Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: help spot t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 9 Topic 4580 of 4724
Post > Topic >>

Re: help spot the error in this floating point code

by Bin Xin <spamtrap@[EMAIL PROTECTED] > Apr 18, 2008 at 01:47 PM

On Apr 17, 9:25 pm, Jentje Goslinga  <spamt...@[EMAIL PROTECTED]
> wrote:
> Bin Xin wrote:
> > On Mar 19, 9:02 am, Terje Mathisen  <spamt...@[EMAIL PROTECTED]
> wrote:
> >> Tim Roberts wrote:
> >>> I admit that I lost track part way through, but it looks to me like
you
> >>> aren't cleaning up thefloatingpointstack when you are done.  If you
> >>> leave stuff on the stack, sooner or later the stack will overflow
(there
> >>> are only 8 entries, after all), which
triggersfloatingpointexceptions.
> >> The easy way to check this is to call your my_pow() function in a
loop,
> >> preferably while inside the debugger, and watch the x87 stack
contents.
>
> > Thanks for replying.
>
> > So I try to follow the stack state after each call to my_pow,  it
> > looks ok for a few calls (9), then I see a weird thing: when "fld1" is
> > executed at somepoint, it loads a "nan" instead of "1" into st0:
>
> As Terje says, check for FPU stack overflow.
>
> If you are using normal calling conventions (as enforced by
> compilers), your FPU stack should be empty upon entering any
> function, and upon exit should be either empty (I) or contain
> a single entry (II), in the case where the function returns
> afloatingpointnumber:
>
> void myfunc(...)    (I)
>
> double myfunc(...)  (II)
>
> To find out how many entries out off the available eight of the
> FPU stack are used, inspect the FPU TAGS word with your debugger.
> (NB: The TAGS word; NOT the FPU CONTROL OR STATUS word).
> The TAGS word should read FFFF upon entry to the function (just
> prior to the hardware call instruction) and upon exit should read
> FFFF in case (I) and 3FFF in case (II), if I am not mistaken.
> This is because the coding is from left to right and is 11 for an
> empty register and 00 for a used register, so 3FFF means
> 0011 1111 1111 1111
> which means that the first FPU register "st0" is in use and
> st1...st7 are empty. Note that some debuggers display garbage even
> in empty registers, so do not rely on the debugger FPU stack display.
>
> This is as much as I know; I am not sure whether the used registers
> should be contiguous, or what happens upon stack rotation, I haven't
> investigated that.

Thanks, Jen.  This is informative.  Is there an existing tool that can
check a piece of assembly code,  for registers not cleaned up?

bin
 




 9 Posts in Topic:
help spot the error in this floating point code
Bin Xin <spamtrap@[EM  2008-03-18 15:26:40 
Re: help spot the error in this floating point code
Tim Roberts <spamtrap  2008-03-19 05:13:52 
Re: help spot the error in this floating point code
Terje Mathisen <spamt  2008-03-19 14:02:16 
Re: help spot the error in this floating point code
nbaker2328 <spamtrap@[  2008-03-18 23:08:55 
Re: help spot the error in this floating point code
Bin Xin <spamtrap@[EM  2008-04-16 15:23:00 
Re: help spot the error in this floating point code
"Wolfgang Kern"  2008-04-17 13:28:18 
Re: help spot the error in this floating point code
Jentje Goslinga <spam  2008-04-17 18:25:15 
Re: help spot the error in this floating point code
Bin Xin <spamtrap@[EM  2008-04-18 13:47:00 
Re: help spot the error in this floating point code
Jentje Goslinga <spam  2008-04-18 19:08:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 20 17:23:01 CDT 2008.