Page 1 of 2
Asm question...
Posted: Wed Mar 07, 2007 11:54 pm
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:
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.
Posted: Thu Mar 08, 2007 10:46 am
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).
Posted: Thu Mar 08, 2007 10:58 am
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.
Posted: Thu Mar 08, 2007 11:07 am
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!
Posted: Thu Mar 08, 2007 11:12 am
by srod
Derek wrote:I think we need someone else to figure it out for sure!
Where's batman when you need him?
Posted: Thu Mar 08, 2007 12:25 pm
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.
Posted: Thu Mar 08, 2007 1:03 pm
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.
Posted: Thu Mar 08, 2007 8:22 pm
by srod
Thanks Trond. I was kind of hoping that was the case.

Posted: Thu Mar 08, 2007 11:50 pm
by dell_jockey
Posted: Fri Mar 09, 2007 12:01 am
by srod
That'll take a while to read!
Good link, thanks.
Posted: Fri Mar 09, 2007 10:20 am
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..

Posted: Tue Mar 13, 2007 11:56 pm
by minirop
F1: dd 0
and ?
Fred could reply
Posted: Wed Mar 14, 2007 12:47 pm
by Trond
minirop wrote:F1: dd 0
and ?
Fred could reply
What do you mean? It's 0.
Posted: Thu Mar 15, 2007 12:01 am
by Fred
Hum, it looks like a compiler issue than anything else. I will take a closer look.
Posted: Thu Mar 15, 2007 12:56 am
by srod
Thanks Fred.