This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: QNaN and SNaN definitions
- From: Hartvig Ekner <hartvige at mips dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Wed, 20 Mar 2002 22:28:14 +0100 (CET)
- Subject: Re: QNaN and SNaN definitions
H . J . Lu writes:
>
> On Tue, Mar 19, 2002 at 10:34:11PM +0100, Hartvig Ekner wrote:
> > < stuff on NaN>
> >
> > I can send in patches to fix this for MIPS, but I would think this is
> > inappropriate and that some of you glibc people would have to decide how
> > to deal with this. If you can tell me how you want it fixed, I will be
> > happy to deliver the patches, but I need a machine specific #define to
> > look at in these header files. I would like to avoid separate MIPS versions
> > of these header files if possible (maintenance issues).
>
> Just create a new sysdeps/mips/bits/nan.h with the right bits.
>
> >
> > In nan.h, it is clear what has to be done.
> >
> > In ieee754.h it is less clear. One can leave things as they are, but then
> > peoples apps will not work without them knowing the difference. Maybe define
> > machine-dep constants to be used with the quiet_nan field, or more
> > drastically, rename the quiet_nan field to signalling_nan. Is this an
> > option at all?
> >
>
> You can create a new sysdeps/mips/ieee754.h and change quiet_nan to
> signalling_nan. Any codes depending on quiet_nan will fail on mips
I would really like to avoid especially ieee754 branching off into a
separate MIPS file, since it contains a lot of other stuff than the
quiet_nan thing.
How about these two patches to the generic files in sysdeps?
/Hartvig
===================================================================
RCS file: RCS/nan.h,v
retrieving revision 1.1
diff -u -r1.1 nan.h
--- nan.h 2002/03/20 20:43:26 1.1
+++ nan.h 2002/03/20 20:57:56
@@ -22,24 +22,42 @@
#endif
-/* IEEE Not A Number. */
+/* IEEE Not A Number. Note that MIPS has the QNaN and SNaN patterns
+ reversed compared to most other architectures. The IEEE spec left
+ the definition of this open to implementations, and for MIPS the top
+ bit of the mantissa must be SET to indicate a SNaN. */
#ifdef __GNUC__
+# ifdef __mips__
+# define QNAN_PATTERN 0x7fbfffffUL
+# else
+# define QNAN_PATTERN 0x7fc00000UL
+# endif
+
# define NAN \
(__extension__ \
((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) \
- { __l: 0x7fc00000UL }).__d)
+ { __l: QNAN_PATTERN }).__d)
#else
# include <endian.h>
# if __BYTE_ORDER == __BIG_ENDIAN
-# define __nan_bytes { 0x7f, 0xc0, 0, 0 }
+# ifdef __mips__
+# define __nan_bytes { 0x7f, 0xbf, 0xff, 0xff }
+# else
+# define __nan_bytes { 0x7f, 0xc0, 0x00, 0x00 }
+# endif
# endif
+
# if __BYTE_ORDER == __LITTLE_ENDIAN
-# define __nan_bytes { 0, 0, 0xc0, 0x7f }
+# ifdef __mips__
+# define __nan_bytes { 0xff, 0xff, 0xbf, 0x7f }
+# else
+# define __nan_bytes { 0x00, 0x00, 0xc0, 0x7f }
+# endif
# endif
static union { unsigned char __c[4]; float __d; } __nan_union = { __nan_bytes };
===================================================================
RCS file: RCS/ieee754.h,v
retrieving revision 1.1
diff -u -r1.1 ieee754.h
--- ieee754.h 2002/03/20 20:43:26 1.1
+++ ieee754.h 2002/03/20 21:12:01
@@ -25,6 +25,21 @@
__BEGIN_DECLS
+/* Note that MIPS has the QNaN and SNaN patterns reversed compared to
+ most other architectures. See bits/nan.h for more detail.
+
+ The constants below can be used to portably manipulate the "quiet_nan"
+ bitfields in the IEEE754 unions, which for MIPS should actually be named
+ "signalling_nan". */
+
+#ifdef __mips__
+# define IEEE754_QNAN_BIT 0
+# define IEEE754_SNAN_BIT 1
+#else
+# define IEEE754_QNAN_BIT 1
+# define IEEE754_SNAN_BIT 0
+#endif
+
union ieee754_float
{
float f;