It is currently Wed Jan 20, 2021 4:02 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Convert PB code to asm
PostPosted: Thu Jul 24, 2014 8:42 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Jul 02, 2009 5:42 am
Posts: 327
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"


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert PB code to asm
PostPosted: Thu Jul 24, 2014 8:54 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
I'm not sure what you are asking.

Converting the code to PB would be something like this
Code:
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 ?

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert PB code to asm
PostPosted: Thu Jul 24, 2014 9:26 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Jul 02, 2009 5:42 am
Posts: 327
Wilbert, yes would like it to be asm :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert PB code to asm
PostPosted: Thu Jul 24, 2014 9:58 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3377
Location: Boston, MA
You can also look at PB's asm output?
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert PB code to asm
PostPosted: Fri Jul 25, 2014 6:09 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
This is using x87.
Code:
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:
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.

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert PB code to asm
PostPosted: Fri Jul 25, 2014 7:40 am 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1807
Location: Uttoxeter, UK
@wilbert, Thank you for the instructive demos. :D

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert PB code to asm
PostPosted: Fri Jul 25, 2014 8:48 am 
Offline
User
User

Joined: Fri Sep 21, 2012 11:40 pm
Posts: 39
Location: Portugal
It's possible to get purebasic's assembler output if you compile using command line compiler with the /commented option.


Top
 Profile  
Reply with quote  
 Post subject: Re: Convert PB code to asm
PostPosted: Fri Jul 25, 2014 4:29 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Jul 02, 2009 5:42 am
Posts: 327
Thank you Wilbert :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye