# PureBasic Forum

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

 All times are UTC + 1 hour

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Convert PB code to asmPosted: Thu Jul 24, 2014 8:42 pm
 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.

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

 Post subject: Re: Convert PB code to asmPosted: Thu Jul 24, 2014 8:54 pm
 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

 Post subject: Re: Convert PB code to asmPosted: Thu Jul 24, 2014 9:26 pm
 Enthusiast

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

Top

 Post subject: Re: Convert PB code to asmPosted: Thu Jul 24, 2014 9:58 pm

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

 Post subject: Re: Convert PB code to asmPosted: Fri Jul 25, 2014 6:09 am
 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

 Post subject: Re: Convert PB code to asmPosted: Fri Jul 25, 2014 7:40 am

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

_________________
DE AA EB

Top

 Post subject: Re: Convert PB code to asmPosted: Fri Jul 25, 2014 8:48 am
 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

 Post subject: Re: Convert PB code to asmPosted: Fri Jul 25, 2014 4:29 pm
 Enthusiast

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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite