PureBasic Forum
https://www.purebasic.fr/english/

Why does CQO instruction not recognized by PB
https://www.purebasic.fr/english/viewtopic.php?f=35&t=72198
Page 1 of 1

Author:  Jeff88 [ Sat Feb 02, 2019 12:26 am ]
Post subject:  Why does CQO instruction not recognized by PB

I wanted to see the timing difference between IDIV and DIV. So I wrote a simple program, looked at the assembly code and cut and pasted the portion for c=a/b into the timing loop. I changed IDIV to DIV. The compiler gave a syntax error for CQO line. I put a ! in front of the CQO to send directly to FASM and it worked fine. Any comments? Truly amazing how fast cpu's are today.

Code:
ntimes=1e6

a=999999999999999999
b=567890123456789

atime=ElapsedMilliseconds()
For i=1 To ntimes
Next
btime=ElapsedMilliseconds()
For i=1 To ntimes
  c=a/b
Next
c=0
ctime=ElapsedMilliseconds()
For i=1 To ntimes
  ;c=a/b
  EnableASM
  MOV    r15,qword [v_a]
  PUSH   qword [v_b]
  MOV    rax,r15
  POP    rcx
  !CQO                            ;trouble spot
  DIV   rcx
  MOV    r15,rax
  MOV    qword [v_c],r15
  DisableASM
  Next
dtime=ElapsedMilliseconds()

OpenConsole()
PrintN("nsec/loop")
PrintN(Str(btime-atime)+" "+Str(ctime-btime)+"  "+Str(dtime-ctime))
PrintN(Str(a/b)+ "  "+Str(c))

Input()
End

Author:  luis [ Sat Feb 02, 2019 12:47 am ]
Post subject:  Re: Why does CQO instruction not recognized by PB

I'm just guessing here.
I think PB EnableASM supports only the opcodes up to 80486, and CQO was introduced with x64.
You have compiled your PB program on x64 so you found that instruction in the generated code.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/