Forgot to attach the patch.

Mike

Michael Droettboom wrote:
Thanks.  Behind that, however, it runs into this compiler shortcoming:

cc: build/src.solaris-2.8-sun4u-2.5/numpy/core/src/npymath/npy_math.c
"numpy/core/src/npymath/npy_math_private.h", line 229: invalid type for bit-field: manh "numpy/core/src/npymath/npy_math_private.h", line 230: invalid type for bit-field: manl

It seems that Sun compilers (before Sun Studio 12, C compiler 5.9), don't support bit fields larger than 32-bits. Welcome to my world :)

You can see a discussion of this here:

http://www.mail-archive.com/tools-disc...@opensolaris.org/msg02634.html

and the release notes for Sun C compiler 5.9 here:

http://docs.sun.com/source/820-4155/c.html

The best solution I've been able to dream up is to use a macro to get at the manh bitfield on these older compilers. This fix does seem to pass the "test_umath.py" unit tests. It's not as clean as the bit-field method, but it should be more portable. You can see what I'm getting at in the attached (rough) patch.

Can you think of a better solution? If this is *the* solution, we may want to add getters/setters for all the members (sign, exp, manl) and fix nextafterl in terms of those, just for consistency.

Cheers,
Mike

David Cournapeau wrote:
On Wed, Nov 11, 2009 at 6:18 AM, Michael Droettboom <md...@stsci.edu> wrote:
I don't know if your 'long double' detection code is complete yet, but I
thought I'd share the current build output on one of our Solaris
machines.  It looks like it may just be a typo difference between
'IEEE_QUAD_BE' in long_double_representation() and 'IEEE_QUAD_16B_BE' in
setup.py, but I wanted to confirm.

Yes, you're right - I don't have any machine with a 128 bits long
double type, so I let the typo slipped.

Could you try last revision (r7726) ?

David
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Index: numpy/core/src/npymath/npy_math_private.h
===================================================================
--- numpy/core/src/npymath/npy_math_private.h   (revision 7726)
+++ numpy/core/src/npymath/npy_math_private.h   (working copy)
@@ -174,6 +174,9 @@
 /*
  * Long double support
  */
+#define LDBL_GET_MANH(x) ((x).bits.manh)
+#define LDBL_SET_MANH(x, v) ((x).bits.manh = (v))
+
 #if defined(HAVE_LDOUBLE_INTEL_EXTENDED_12_BYTES_LE)
     /* 80 bits Intel format aligned on 12 bytes */
     union IEEEl2bits {
@@ -221,15 +224,32 @@
     #define mask_nbit_l(u)  ((void)0)
 #elif defined(HAVE_LDOUBLE_IEEE_QUAD_BE)
     /* Quad precision IEEE format */
-    union IEEEl2bits {
-        npy_longdouble  e;
-        struct {
-            npy_uint32  sign    :1;
-            npy_uint32  exp     :15;
-            npy_uint64  manh    :48;
-            npy_uint64  manl    :64;
-        } bits;
-    };
+    #if defined(__SUNPRO_C) && (__SUNPRO_C < 0x590)
+        union IEEEl2bits {
+           npy_longdouble e;
+           struct {
+               npy_uint32  sign    :1;
+               npy_uint32  exp     :15;
+                /* implicit padding */
+                npy_uint64  manl;
+           } bits;
+        };
+        #undef LDBL_GET_MANH
+        #define LDBL_GET_MANH(x) ((*(npy_uint64 *)&((x).e)) & 
0x0000ffffffffffffL)
+        #undef LDBL_SET_MANH
+        #define LDBL_SET_MANH(x, v) ((*(npy_uint64 *)&((x).e)) |= ((v) & 
0x0000ffffffffffffL))
+    #else
+        union IEEEl2bits {
+           npy_longdouble  e;
+           struct {
+               npy_uint32  sign    :1;
+               npy_uint32  exp     :15;
+               npy_uint64  manh    :48;
+               npy_uint64  manl    :64;
+           } bits;
+       };
+    #endif
+    #define LDBL_NBIT   0
     #define mask_nbit_l(u)  ((void)0)
 #elif defined(HAVE_LDOUBLE_IEEE_DOUBLE_LE)
     union IEEEl2bits {
Index: numpy/core/src/npymath/ieee754.c.src
===================================================================
--- numpy/core/src/npymath/ieee754.c.src        (revision 7726)
+++ numpy/core/src/npymath/ieee754.c.src        (working copy)
@@ -165,16 +165,16 @@
     uy.e = y;
 
     if ((ux.bits.exp == 0x7fff &&
-         ((ux.bits.manh & ~LDBL_NBIT) | ux.bits.manl) != 0) ||
+         ((LDBL_GET_MANH(ux) & ~LDBL_NBIT) | ux.bits.manl) != 0) ||
         (uy.bits.exp == 0x7fff &&
-         ((uy.bits.manh & ~LDBL_NBIT) | uy.bits.manl) != 0)) {
+         ((LDBL_GET_MANH(uy) & ~LDBL_NBIT) | uy.bits.manl) != 0)) {
         return x + y;           /* x or y is nan */
     }
     if (x == y) {
         return y;               /* x=y, return y */
     }
     if (x == 0.0) {
-        ux.bits.manh = 0;       /* return +-minsubnormal */
+        LDBL_SET_MANH(ux, 0);       /* return +-minsubnormal */
         ux.bits.manl = 1;
         ux.bits.sign = uy.bits.sign;
         t = ux.e * ux.e;
@@ -186,17 +186,17 @@
     }
     if (x > 0.0 ^ x < y) {      /* x -= ulp */
         if (ux.bits.manl == 0) {
-            if ((ux.bits.manh & ~LDBL_NBIT) == 0) {
+            if ((LDBL_GET_MANH(ux) & ~LDBL_NBIT) == 0) {
                 ux.bits.exp -= 1;
             }
-            ux.bits.manh = (ux.bits.manh - 1) | (ux.bits.manh & LDBL_NBIT);
+            LDBL_SET_MANH(ux, (LDBL_GET_MANH(ux) - 1) | (LDBL_GET_MANH(ux) & 
LDBL_NBIT));
         }
         ux.bits.manl -= 1;
     } else {                    /* x += ulp */
         ux.bits.manl += 1;
         if (ux.bits.manl == 0) {
-            ux.bits.manh = (ux.bits.manh + 1) | (ux.bits.manh & LDBL_NBIT);
-            if ((ux.bits.manh & ~LDBL_NBIT) == 0) {
+            LDBL_SET_MANH(ux, (LDBL_GET_MANH(ux) + 1) | (LDBL_GET_MANH(ux) & 
LDBL_NBIT));
+            if ((LDBL_GET_MANH(ux) & ~LDBL_NBIT) == 0) {
                 ux.bits.exp += 1;
             }
         }
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to