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 5 of 9 Topic 4580 of 4710
Post > Topic >>

Re: help spot the error in this floating point code

by Bin Xin <spamtrap@[EMAIL PROTECTED] > Apr 16, 2008 at 03:23 PM

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 some point, it loads a "nan" instead of "1" into st0:

(gdb) ni
0x08048397      270
8: $st7 = 15
7: $st6 = 14
6: $st5 = 13
5: $st4 = 12
4: $st3 = 2
3: $st2 = 0
2: $st1 = 2
1: $st0 = 0
(gdb) ni
0x08048399      270
8: $st7 = 14
7: $st6 = 13
6: $st5 = 12
5: $st4 = 2
4: $st3 = 0
3: $st2 = 2
2: $st1 = 0
1: $st0 = -nan(0xc000000000000000)

So what am I missing here?  I have attached the disassembled code at
the end for my_pow.

Thanks,
-Bin




my_pow:
804838a:       dd 44 24 04             fldl   0x4(%esp)
 804838e:       dd 44 24 0c             fldl   0xc(%esp)
 8048392:       d9 e4                   ftst
 8048394:       9b df e0                fstsw  %ax
 8048397:       d9 e8                   fld1
 8048399:       9e                      sahf
 804839a:       74 3f                   je     80483db <my_pow+0x51>
 804839c:       d8 d9                   fcomp  %st(1)
 804839e:       9b df e0                fstsw  %ax
 80483a1:       d9 c9                   fxch   %st(1)
 80483a3:       9e                      sahf
 80483a4:       74 35                   je     80483db <my_pow+0x51>
 80483a6:       d9 e4                   ftst
 80483a8:       9b df e0                fstsw  %ax
 80483ab:       9e                      sahf
 80483ac:       74 2d                   je     80483db <my_pow+0x51>
 80483ae:       73 2c                   jae    80483dc <my_pow+0x52>
 80483b0:       d9 c9                   fxch   %st(1)
 80483b2:       d9 c0                   fld    %st(0)
 80483b4:       d9 fc                   frndint
 80483b6:       d8 d9                   fcomp  %st(1)
 80483b8:       9b df e0                fstsw  %ax
 80483bb:       d9 c9                   fxch   %st(1)
 80483bd:       9e                      sahf
 80483be:       75 1c                   jne    80483dc <my_pow+0x52>
 80483c0:       d9 e8                   fld1
 80483c2:       d8 c0                   fadd   %st(0),%st
 80483c4:       d8 fa                   fdivr  %st(2),%st
 80483c6:       d9 fc                   frndint
 80483c8:       d8 c0                   fadd   %st(0),%st
 80483ca:       d8 da                   fcomp  %st(2)
 80483cc:       9b df e0                fstsw  %ax
 80483cf:       d9 e0                   fchs
 80483d1:       9e                      sahf
 80483d2:       74 08                   je     80483dc <my_pow+0x52>
 80483d4:       e8 03 00 00 00          call   80483dc <my_pow+0x52>
 80483d9:       d9 e0                   fchs
 80483db:       c3                      ret
 80483dc:       d9 f1                   fyl2x
 80483de:       e9 96 ff ff ff          jmp    8048379 <__finexp>


08048379 <__finexp>:
 8048379:       dd d1                   fst    %st(1)
 804837b:       d9 fc                   frndint
 804837d:       dd d2                   fst    %st(2)
 804837f:       de e9                   fsubrp %st,%st(1)
 8048381:       d9 f0                   f2xm1
 8048383:       d9 e8                   fld1
 8048385:       de c1                   faddp  %st,%st(1)
 8048387:       d9 fd                   fscale
 8048389:       c3                      ret
 




 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 6 20:16:29 CDT 2008.