Convert PB code to asm

Bare metal programming in PureBasic, for experienced users
spacebuddy
Enthusiast
Enthusiast
Posts: 346
Joined: Thu Jul 02, 2009 5:42 am

Convert PB code to asm

Post by spacebuddy »

Can anyone convert this code to PureBasic so I can benchmark to see the difference. :D :D

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"
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Convert PB code to asm

Post 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 ?
Windows (x64)
Raspberry Pi OS (Arm64)
spacebuddy
Enthusiast
Enthusiast
Posts: 346
Joined: Thu Jul 02, 2009 5:42 am

Re: Convert PB code to asm

Post by spacebuddy »

Wilbert, yes would like it to be asm :D
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Convert PB code to asm

Post 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)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Convert PB code to asm

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Convert PB code to asm

Post by davido »

@wilbert, Thank you for the instructive demos. :D
DE AA EB
deesko
User
User
Posts: 39
Joined: Fri Sep 21, 2012 11:40 pm
Location: Portugal

Re: Convert PB code to asm

Post by deesko »

It's possible to get purebasic's assembler output if you compile using command line compiler with the /commented option.
spacebuddy
Enthusiast
Enthusiast
Posts: 346
Joined: Thu Jul 02, 2009 5:42 am

Re: Convert PB code to asm

Post by spacebuddy »

Thank you Wilbert :)
Post Reply