math: remove *_WORD64 macros from libm.h
authorSzabolcs Nagy <nsz@port70.net>
Wed, 4 Sep 2013 16:39:41 +0000 (16:39 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Thu, 5 Sep 2013 11:30:08 +0000 (11:30 +0000)
only fma used these macros and the explicit union is clearer

src/internal/libm.h
src/math/fma.c

index d7562d107a52473eeeb0f619cfabb30caafd73e3..99448a08a5509169c95c4b612bf0ff3d20f49bf7 100644 (file)
@@ -80,14 +80,6 @@ do {                                                            \
   (lo) = (uint32_t)__u.bits;                                    \
 } while (0)
 
-/* Get a 64 bit int from a double.  */
-#define EXTRACT_WORD64(i,d)                                     \
-do {                                                            \
-  union dshape __u;                                             \
-  __u.value = (d);                                              \
-  (i) = __u.bits;                                               \
-} while (0)
-
 /* Get the more significant 32 bit int from a double.  */
 #define GET_HIGH_WORD(i,d)                                      \
 do {                                                            \
@@ -112,14 +104,6 @@ do {                                                            \
   (d) = __u.value;                                              \
 } while (0)
 
-/* Set a double from a 64 bit int.  */
-#define INSERT_WORD64(d,i)                                      \
-do {                                                            \
-  union dshape __u;                                             \
-  __u.bits = (i);                                               \
-  (d) = __u.value;                                              \
-} while (0)
-
 /* Set the more significant 32 bits of a double from an int.  */
 #define SET_HIGH_WORD(d,hi)                                     \
 do {                                                            \
index 1b1c13217698767125dd6814ea307b240dbb7af6..84868be5d354144bcd56833bc12994a44b70fea9 100644 (file)
@@ -232,16 +232,16 @@ static inline struct dd dd_add(double a, double b)
 static inline double add_adjusted(double a, double b)
 {
        struct dd sum;
-       uint64_t hibits, lobits;
+       union {double f; uint64_t i;} uhi, ulo;
 
        sum = dd_add(a, b);
        if (sum.lo != 0) {
-               EXTRACT_WORD64(hibits, sum.hi);
-               if ((hibits & 1) == 0) {
+               uhi.f = sum.hi;
+               if ((uhi.i & 1) == 0) {
                        /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */
-                       EXTRACT_WORD64(lobits, sum.lo);
-                       hibits += 1 - ((hibits ^ lobits) >> 62);
-                       INSERT_WORD64(sum.hi, hibits);
+                       ulo.f = sum.lo;
+                       uhi.i += 1 - ((uhi.i ^ ulo.i) >> 62);
+                       sum.hi = uhi.f;
                }
        }
        return (sum.hi);
@@ -255,7 +255,7 @@ static inline double add_adjusted(double a, double b)
 static inline double add_and_denormalize(double a, double b, int scale)
 {
        struct dd sum;
-       uint64_t hibits, lobits;
+       union {double f; uint64_t i;} uhi, ulo;
        int bits_lost;
 
        sum = dd_add(a, b);
@@ -271,13 +271,13 @@ static inline double add_and_denormalize(double a, double b, int scale)
         * break the ties manually.
         */
        if (sum.lo != 0) {
-               EXTRACT_WORD64(hibits, sum.hi);
-               bits_lost = -((int)(hibits >> 52) & 0x7ff) - scale + 1;
-               if (bits_lost != 1 ^ (int)(hibits & 1)) {
+               uhi.f = sum.hi;
+               bits_lost = -((int)(uhi.i >> 52) & 0x7ff) - scale + 1;
+               if (bits_lost != 1 ^ (int)(uhi.i & 1)) {
                        /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */
-                       EXTRACT_WORD64(lobits, sum.lo);
-                       hibits += 1 - (((hibits ^ lobits) >> 62) & 2);
-                       INSERT_WORD64(sum.hi, hibits);
+                       ulo.f = sum.lo;
+                       uhi.i += 1 - (((uhi.i ^ ulo.i) >> 62) & 2);
+                       sum.hi = uhi.f;
                }
        }
        return scalbn(sum.hi, scale);