Asm question...

Everything else that doesn't fall into one of the other PB categories.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Asm question...

Post by srod »

Hi,

I was just checking the commented FASM output for one of my PB routines and noticed that (heavily edited) in response to:

Code: Select all

a.f=1.4 
b.f=2.5 
x.f=a+b
PB produces

Code: Select all

; x.f=a+b
  FLD    dword [v_a]
  FADD   dword [v_b]
  FADD   dword [F1]
  FSTP   dword [v_x]
It's the FADD dword [f1] which puzzles me as this memory location holds zero.

I must admit that my knowledge of the FPU commands are quite sketchy, but I can't figure out the purpose of what appears to be a superfluous command?

Anyone know the answer?

I can post the entire commented output if required.

Thanks.
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

My guess, and it is only a guess, is that it has something to do with pipelining, strange as it may seem, sometimes adding extra instructions can push others into the other pipe where they can operate quicker.

Everyone feel free to shoot me down in flames if I'm wrong (which is more than likely).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

An interesting theory. You might well be right there Derek. Although, why not simply use the FWAIT command in this case?

Uhm, I figure either you're right or it's something to do with resetting some of the status flags.
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

srod wrote:why not simply use the FWAIT command in this case?
It did cross my mind that an FADD was probably not the instruction to use, I also considered that it may have something to do with a 'carry' or 'overflow' which would tie in with your theory about flags.

I think we need someone else to figure it out for sure!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Derek wrote:I think we need someone else to figure it out for sure!
:)

Where's batman when you need him?
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It's not needed, but PB adds it everywhere. I think it's the rests from a trick to allow negative numbers without introducing additional complexity into the compiler.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

So, presumably, if you took them all out and if your code was complex enough so that they actually made a difference then you would end up with a faster, leaner exe.

Of course, I don't for one minute think that removing a few FADD's is going to make a speed difference with the sort of programs that PB is used in making, simply because as soon as you require user input all speed issues are gone.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Thanks Trond. I was kind of hoping that was the case. :)
I may look like a mule, but I'm not a complete ass.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That'll take a while to read! :)

Good link, thanks.
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Makes for some interesting reading.

Here's a quote from the 'What's Right With Assembly Language?' section
Saving space saves money. Pure and simple. If a program requires 1.5 megabytes, it will not fit on a 1.44 Mbyte floppy. Likewise, if an application requires 2 megabytes RAM, the user will have to install an extra megabyte if there is only one available in the machine. Even on big machines with 32 or more megabytes, writing gigantic applications isn't excusable. Most users put more than eight megabytes in their machines so they can run multiple programs from memory at one time.
Anyone got a big machine with 32 megabytes or more.. :lol:
minirop
User
User
Posts: 24
Joined: Tue Nov 28, 2006 12:21 am

Post by minirop »

F1: dd 0
and ?
Fred could reply
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

minirop wrote:
F1: dd 0
and ?
Fred could reply
What do you mean? It's 0.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Hum, it looks like a compiler issue than anything else. I will take a closer look.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Thanks Fred.
I may look like a mule, but I'm not a complete ass.
Post Reply