From: Dominic Sweetman <dom@mips.com>
To: "Maciej W. Rozycki" <macro@linux-mips.org>
Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>,
linux-mips@linux-mips.org, ralf@linux-mips.org
Subject: Re: ieee754[sd]p_neg workaround
Date: Wed, 20 Apr 2005 13:57:41 +0100 [thread overview]
Message-ID: <16998.20933.14301.397793@arsenal.mips.com> (raw)
In-Reply-To: <Pine.LNX.4.61L.0504201312520.7109@blysk.ds.pg.gda.pl>
Maciej W. Rozycki (macro@linux-mips.org) writes:
> > I have a long standing patch for FPU emulator to fix a segmentation
> > fault in pow() library function.
> >
> > Here is a test program to reproduce it.
> >
> > main()
> > {
> > union {
> > double d;
> > struct {
> > #ifdef __MIPSEB
> > unsigned int high, low;
> > #else
> > unsigned int low, high;
> > #endif
> > } i;
> > } x, y, z;
> > x.i.low = 0x00000000;
> > x.i.high = 0xfff00001;
> > y.i.low = 0x80000000;
> > y.i.high = 0xcff00000;
> > z.d = pow(x.d, y.d);
> > printf("%x %x\n", z.i.high, z.i.low);
> > return 0;
> > }
> >
> >
> > If you run this program, you will get segmentation fault (unless your
> > FPU does not raise Unimplemented exception for NaN operands). The
> > segmentation fault is caused by endless recursion in __ieee754_pow().
> >
> > It looks glibc's pow() assume unary '-' operation for any number
> > (including NaN) always invert its sign bit.
>
> AFAICS, the IEEE 754 standard explicitly leaves interpretation of the
> sign bit for NaNs as unspecified. Therefore our implementation is correct
> and its glibc that should be fixed instead. Please file a bug report
> against glibc.
You are both right, in a sense.
"Annex A Recommended Functions and Predicates" of IEEE754 (the
annexe is not part of the formal spec) includes a recommendation:
"x is x copied with its sign reversed, not 0x; the distinction is
germane when x is ±0 or NaN."
And in fact that's how the MIPS neg.d operation works: it never
generates an exception, just blindly flips the sign bit.
In the body of IEEE754 it says:
"This standard does not interpret the sign of an NaN."
So there you are. According to the book, the library function should
not depend on the sign of a NaN, but it would also be better if the
compiler/emulator/whatever ensures that "-x" is always and only
implemented by reversing the sign bit.
So file a bug against glibc, but we should fix the emulator so it
correctly imitates the MIPS instruction set...
--
Dominic Sweetman
MIPS Technologies.
next prev parent reply other threads:[~2005-04-20 13:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-20 8:40 ieee754[sd]p_neg workaround Atsushi Nemoto
2005-04-20 12:23 ` Maciej W. Rozycki
2005-04-20 12:57 ` Dominic Sweetman [this message]
2005-04-20 13:13 ` Ralf Baechle
2005-04-21 7:19 ` Atsushi Nemoto
2006-01-02 12:59 ` Atsushi Nemoto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16998.20933.14301.397793@arsenal.mips.com \
--to=dom@mips.com \
--cc=anemo@mba.ocn.ne.jp \
--cc=linux-mips@linux-mips.org \
--cc=macro@linux-mips.org \
--cc=ralf@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox