Page 1 of 1
Convert PB code to asm
Posted: Thu Jul 24, 2014 8:42 pm
by spacebuddy
Can anyone convert this code to PureBasic so I can benchmark to see the difference.
Dim x As Double
Dim y As Double
Dim i As Long
Dim t As Single
x = 1
y = 1.000001
t = Timer
For i = 1 To 100000000
x = x * y
Next
t = Timer - t
Print " X= "; x
Print " Temps d'execution :", Round(t, 2) & " Sec"
Re: Convert PB code to asm
Posted: Thu Jul 24, 2014 8:54 pm
by wilbert
I'm not sure what you are asking.
Converting the code to PB would be something like this
Code: Select all
x.d = 1
y.d = 1.000001
t.l = ElapsedMilliseconds()
For i.l = 1 To 100000000
x * y
Next
t = ElapsedMilliseconds() - t
Msg.s = "X= " + StrD(x) + #CRLF$
Msg + "Temps d'execution :" + StrD(t / 1000, 2) + " Sec"
MessageRequester("", Msg)
but you are asking a question in the ASM forum.
Do you want the multiplication loop to be ASM ?
Re: Convert PB code to asm
Posted: Thu Jul 24, 2014 9:26 pm
by spacebuddy
Wilbert, yes would like it to be asm

Re: Convert PB code to asm
Posted: Thu Jul 24, 2014 9:58 pm
by skywalk
You can also look at PB's asm output?
Code: Select all
fn$ = "c:\your-proj\yourfilename.pb"
Compiler = RunProgram(#PB_Compiler_Home + "compilers\pbcompiler", fn$ + " /commented", #NULL$, #PB_Program_Read | #PB_Program_Open)
Re: Convert PB code to asm
Posted: Fri Jul 25, 2014 6:09 am
by wilbert
This is using x87.
Code: Select all
x.d = 1
y.d = 1.000001
t.l = ElapsedMilliseconds()
!fld qword [v_y]
!fld qword [v_x]
!mov ecx, 100000000
!mulx_loop:
!fmul st0, st1
!dec ecx
!jnz mulx_loop
!fstp qword [v_x]
!fstp st0
t = ElapsedMilliseconds() - t
Msg.s = "X= " + StrD(x) + #CRLF$
Msg + "Temps d'execution :" + StrD(t / 1000, 2) + " Sec"
MessageRequester("", Msg)
It's also possible using the SSE2 instruction MULSD.
Code: Select all
x.d = 1
y.d = 1.000001
t.l = ElapsedMilliseconds()
!movsd xmm0, [v_x]
!movsd xmm1, [v_y]
!mov ecx, 100000000
!mulx_loop:
!mulsd xmm0, xmm1
!dec ecx
!jnz mulx_loop
!movsd [v_x], xmm0
t = ElapsedMilliseconds() - t
Msg.s = "X= " + StrD(x) + #CRLF$
Msg + "Temps d'execution :" + StrD(t / 1000, 2) + " Sec"
MessageRequester("", Msg)
The results are slightly different because the FPU uses 80 bits internally while SSE2 uses 64 bits.
Re: Convert PB code to asm
Posted: Fri Jul 25, 2014 7:40 am
by davido
@
wilbert, Thank you for the instructive demos.

Re: Convert PB code to asm
Posted: Fri Jul 25, 2014 8:48 am
by deesko
It's possible to get purebasic's assembler output if you compile using command line compiler with the /commented option.
Re: Convert PB code to asm
Posted: Fri Jul 25, 2014 4:29 pm
by spacebuddy
Thank you Wilbert
