News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FPU hickup

Started by Draakie, August 23, 2006, 11:08:54 AM

Previous topic - Next topic

Draakie

Hi all, Hope u'll be able to set me straight. First the very small code snippet that should have been simple and easy- but turned into a nightmare.

........first other stuff that initialize via FPU the VAR's : ex. fstp VAR1 and some other using the
........FPULIB here and there with some other standard FPU calcs thrown in - all 100% tested and
........working. Real standard stuff - nothing strange..........but then

fld VAR1        ; a REAL10 defined in .data?
fld VAR2
.if BooleanFlag == TRUE
     fadd
.else
     fsub
.endif
invoke FpuExam,NULL,SRC1_FPU
.........
.........etc.

Simple right ?! - Well not. You see I've been around the block a couple of times with thousands of lines of assembler written - and this has got me spooked. I use almost exactly the same code earlier on in the app without problems. What happens is : As soon as I have VAR1 and VAR2 equal to each other - aswell as the BooleanFlag == FALSE - the fsub goes bonkers - returning values like
-2.6561e-64. But get this - I stick DumpFPU (from the MASM32 pack) just after the FLD's and strangely it gives correct output and the fsub - does it's work. Firstly I thought well it's probably a FWAIT scenario - but no matter how many FWAIT's/ WAIT / DO NOTHING LOOP you throw at it - still garbage output. So I thought it must be some sort of Exception occuring - but no. Then I thought let's do this the long way just incase and throw a FINIT just before the FLD's - start with a clean slate - Nope - still garbage. Then I went a little NUTS (understandably hopefully  :wink) Indirect addressing / moved VARS to .DATA segment / FNXCEL / FFREE /FPULIB routines for ADD&SUB/ you name it - YIP still garbage. It's as if the FLD's corrupt somehow - but DumpFPU - seems to clear the way. What could it be - please - i'am not beyond begging at this point.

Thanx
Draakie 's hubby
Does this code make me look bloated ? (wink)

Tedd

Could be caused by a rounding error?
-2.6561e-64 is very close to 0.00000000000000000000000 (just depends how many decimal places you print to)
No snowflake in an avalanche feels responsible.

Draakie

hmmmmm, thanx Ted - did'nt think of that !
Kewl idea - Will give it a go - something's gotta work.
Any idea why things are diffirent when DumpFPU is
in the picture ?

Appreciated....
Draakie 's hubby
Does this code make me look bloated ? (wink)

ToutEnMasm

#3
Hello,
If it is the FpuExam that is in masm32 there is a lot of instructions and better is to put the code in a source file and follow it with a debugger.
                                   ToutEnMasm

  Note: added debugger FPU     
follow the link, some changes for a better look
http://www.manoscoder.gr/mbbs/forums/thread-view.asp?tid=22&posts=1&start=1    

raymond

Quotebut DumpFPU - seems to clear the way

I have to assume at this point that the DumpFPU you refer to is the FPUDump written by NaN and included in the vkdebug/dbproc subfolder of MASM32.

That procedure saves the content of the FPU registers as REAL8 and later returns those REAL8 values to the FPU before it returns control to your program. Any minor difference between two REAL10 values such as you reported could get rounded off when converted to REAL8 values.

Although you mentioned that the VAR1 and VAR2 REAL10 variables are supposedly equal, they should be if, AND ONLY IF, all your previous computations and storage of intermediate values were performed in the REAL10 format. Otherwise, minor differences could later show up as you reported.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com