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


|