|
|
29e444 |
From c00f26c0eaba5a9680aac0f98de4b6e385a8cb82 Mon Sep 17 00:00:00 2001
|
|
|
29e444 |
From: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
|
|
|
29e444 |
Date: Fri, 8 Mar 2013 11:07:15 -0300
|
|
|
29e444 |
Subject: [PATCH 18/42] PowerPC: unify math_ldbl.h implementations
|
|
|
29e444 |
|
|
|
29e444 |
This patch removes redudant definition from PowerPC specific
|
|
|
29e444 |
math_ldbl, using the definitions from ieee754 math_ldbl.h.
|
|
|
29e444 |
(backported from commit edf66e57fc2bac083ecc9756a5fe47f9041ed3bb)
|
|
|
29e444 |
---
|
|
|
29e444 |
sysdeps/ieee754/ldbl-128ibm/math_ldbl.h | 10 +-
|
|
|
29e444 |
sysdeps/powerpc/Implies | 1 +
|
|
|
29e444 |
sysdeps/powerpc/fpu/math_ldbl.h | 171 ++------------------------------
|
|
|
29e444 |
sysdeps/unix/sysv/linux/powerpc/Implies | 4 -
|
|
|
29e444 |
5 files changed, 34 insertions(+), 168 deletions(-)
|
|
|
29e444 |
delete mode 100644 sysdeps/unix/sysv/linux/powerpc/Implies
|
|
|
29e444 |
|
|
|
12745e |
diff --git glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/math_ldbl.h glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/math_ldbl.h
|
|
|
29e444 |
index be9ac71..1cce1fc 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/math_ldbl.h
|
|
|
12745e |
+++ glibc-2.17-c758a686/sysdeps/ieee754/ldbl-128ibm/math_ldbl.h
|
|
|
29e444 |
@@ -125,7 +125,7 @@ ldbl_insert_mantissa (int sign, int exp, int64_t hi64, u_int64_t lo64)
|
|
|
29e444 |
/* Handy utility functions to pack/unpack/cononicalize and find the nearbyint
|
|
|
29e444 |
of long double implemented as double double. */
|
|
|
29e444 |
static inline long double
|
|
|
29e444 |
-ldbl_pack (double a, double aa)
|
|
|
29e444 |
+default_ldbl_pack (double a, double aa)
|
|
|
29e444 |
{
|
|
|
29e444 |
union ibm_extended_long_double u;
|
|
|
29e444 |
u.dd[0] = a;
|
|
|
29e444 |
@@ -134,7 +134,7 @@ ldbl_pack (double a, double aa)
|
|
|
29e444 |
}
|
|
|
29e444 |
|
|
|
29e444 |
static inline void
|
|
|
29e444 |
-ldbl_unpack (long double l, double *a, double *aa)
|
|
|
29e444 |
+default_ldbl_unpack (long double l, double *a, double *aa)
|
|
|
29e444 |
{
|
|
|
29e444 |
union ibm_extended_long_double u;
|
|
|
29e444 |
u.d = l;
|
|
|
29e444 |
@@ -142,6 +142,12 @@ ldbl_unpack (long double l, double *a, double *aa)
|
|
|
29e444 |
*aa = u.dd[1];
|
|
|
29e444 |
}
|
|
|
29e444 |
|
|
|
29e444 |
+#ifndef ldbl_pack
|
|
|
29e444 |
+# define ldbl_pack default_ldbl_pack
|
|
|
29e444 |
+#endif
|
|
|
29e444 |
+#ifndef ldbl_unpack
|
|
|
29e444 |
+# define ldbl_unpack default_ldbl_unpack
|
|
|
29e444 |
+#endif
|
|
|
29e444 |
|
|
|
29e444 |
/* Convert a finite long double to canonical form.
|
|
|
29e444 |
Does not handle +/-Inf properly. */
|
|
|
12745e |
diff --git glibc-2.17-c758a686/sysdeps/powerpc/Implies glibc-2.17-c758a686/sysdeps/powerpc/Implies
|
|
|
29e444 |
index 7ccf9a7..78dba95 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/sysdeps/powerpc/Implies
|
|
|
12745e |
+++ glibc-2.17-c758a686/sysdeps/powerpc/Implies
|
|
|
29e444 |
@@ -1,4 +1,5 @@
|
|
|
29e444 |
# On PowerPC we use the IBM extended long double format.
|
|
|
29e444 |
ieee754/ldbl-128ibm
|
|
|
29e444 |
+ieee754/ldbl-opt
|
|
|
29e444 |
ieee754/dbl-64
|
|
|
29e444 |
ieee754/flt-32
|
|
|
12745e |
diff --git glibc-2.17-c758a686/sysdeps/powerpc/fpu/math_ldbl.h glibc-2.17-c758a686/sysdeps/powerpc/fpu/math_ldbl.h
|
|
|
29e444 |
index 6cd6d0b..36378c0 100644
|
|
|
12745e |
--- glibc-2.17-c758a686/sysdeps/powerpc/fpu/math_ldbl.h
|
|
|
12745e |
+++ glibc-2.17-c758a686/sysdeps/powerpc/fpu/math_ldbl.h
|
|
|
29e444 |
@@ -2,132 +2,12 @@
|
|
|
29e444 |
#error "Never use <math_ldbl.h> directly; include <math_private.h> instead."
|
|
|
29e444 |
#endif
|
|
|
29e444 |
|
|
|
29e444 |
-#include <sysdeps/ieee754/ldbl-128/math_ldbl.h>
|
|
|
29e444 |
-#include <ieee754.h>
|
|
|
29e444 |
-
|
|
|
29e444 |
-static inline void
|
|
|
29e444 |
-ldbl_extract_mantissa (int64_t *hi64, u_int64_t *lo64, int *exp, long double x)
|
|
|
29e444 |
-{
|
|
|
29e444 |
- /* We have 105 bits of mantissa plus one implicit digit. Since
|
|
|
29e444 |
- 106 bits are representable we use the first implicit digit for
|
|
|
29e444 |
- the number before the decimal point and the second implicit bit
|
|
|
29e444 |
- as bit 53 of the mantissa. */
|
|
|
29e444 |
- unsigned long long hi, lo;
|
|
|
29e444 |
- int ediff;
|
|
|
29e444 |
- union ibm_extended_long_double eldbl;
|
|
|
29e444 |
- eldbl.d = x;
|
|
|
29e444 |
- *exp = eldbl.ieee.exponent - IBM_EXTENDED_LONG_DOUBLE_BIAS;
|
|
|
29e444 |
-
|
|
|
29e444 |
- lo = ((long long)eldbl.ieee.mantissa2 << 32) | eldbl.ieee.mantissa3;
|
|
|
29e444 |
- hi = ((long long)eldbl.ieee.mantissa0 << 32) | eldbl.ieee.mantissa1;
|
|
|
29e444 |
- /* If the lower double is not a denomal or zero then set the hidden
|
|
|
29e444 |
- 53rd bit. */
|
|
|
29e444 |
- if (eldbl.ieee.exponent2 > 0x001)
|
|
|
29e444 |
- {
|
|
|
29e444 |
- lo |= (1ULL << 52);
|
|
|
29e444 |
- lo = lo << 7; /* pre-shift lo to match ieee854. */
|
|
|
29e444 |
- /* The lower double is normalized separately from the upper. We
|
|
|
29e444 |
- may need to adjust the lower manitissa to reflect this. */
|
|
|
29e444 |
- ediff = eldbl.ieee.exponent - eldbl.ieee.exponent2;
|
|
|
29e444 |
- if (ediff > 53)
|
|
|
29e444 |
- lo = lo >> (ediff-53);
|
|
|
29e444 |
- }
|
|
|
29e444 |
- hi |= (1ULL << 52);
|
|
|
29e444 |
-
|
|
|
29e444 |
- if ((eldbl.ieee.negative != eldbl.ieee.negative2)
|
|
|
29e444 |
- && ((eldbl.ieee.exponent2 != 0) && (lo != 0LL)))
|
|
|
29e444 |
- {
|
|
|
29e444 |
- hi--;
|
|
|
29e444 |
- lo = (1ULL << 60) - lo;
|
|
|
29e444 |
- if (hi < (1ULL << 52))
|
|
|
29e444 |
- {
|
|
|
29e444 |
- /* we have a borrow from the hidden bit, so shift left 1. */
|
|
|
29e444 |
- hi = (hi << 1) | (lo >> 59);
|
|
|
29e444 |
- lo = 0xfffffffffffffffLL & (lo << 1);
|
|
|
29e444 |
- *exp = *exp - 1;
|
|
|
29e444 |
- }
|
|
|
29e444 |
- }
|
|
|
29e444 |
- *lo64 = (hi << 60) | lo;
|
|
|
29e444 |
- *hi64 = hi >> 4;
|
|
|
29e444 |
-}
|
|
|
29e444 |
-
|
|
|
29e444 |
-static inline long double
|
|
|
29e444 |
-ldbl_insert_mantissa (int sign, int exp, int64_t hi64, u_int64_t lo64)
|
|
|
29e444 |
-{
|
|
|
29e444 |
- union ibm_extended_long_double u;
|
|
|
29e444 |
- unsigned long hidden2, lzcount;
|
|
|
29e444 |
- unsigned long long hi, lo;
|
|
|
29e444 |
-
|
|
|
29e444 |
- u.ieee.negative = sign;
|
|
|
29e444 |
- u.ieee.negative2 = sign;
|
|
|
29e444 |
- u.ieee.exponent = exp + IBM_EXTENDED_LONG_DOUBLE_BIAS;
|
|
|
29e444 |
- u.ieee.exponent2 = exp-53 + IBM_EXTENDED_LONG_DOUBLE_BIAS;
|
|
|
29e444 |
- /* Expect 113 bits (112 bits + hidden) right justified in two longs.
|
|
|
29e444 |
- The low order 53 bits (52 + hidden) go into the lower double */
|
|
|
29e444 |
- lo = (lo64 >> 7)& ((1ULL << 53) - 1);
|
|
|
29e444 |
- hidden2 = (lo64 >> 59) & 1ULL;
|
|
|
29e444 |
- /* The high order 53 bits (52 + hidden) go into the upper double */
|
|
|
29e444 |
- hi = (lo64 >> 60) & ((1ULL << 11) - 1);
|
|
|
29e444 |
- hi |= (hi64 << 4);
|
|
|
29e444 |
-
|
|
|
29e444 |
- if (lo != 0LL)
|
|
|
29e444 |
- {
|
|
|
29e444 |
- /* hidden2 bit of low double controls rounding of the high double.
|
|
|
29e444 |
- If hidden2 is '1' then round up hi and adjust lo (2nd mantissa)
|
|
|
29e444 |
- plus change the sign of the low double to compensate. */
|
|
|
29e444 |
- if (hidden2)
|
|
|
29e444 |
- {
|
|
|
29e444 |
- hi++;
|
|
|
29e444 |
- u.ieee.negative2 = !sign;
|
|
|
29e444 |
- lo = (1ULL << 53) - lo;
|
|
|
29e444 |
- }
|
|
|
29e444 |
- /* The hidden bit of the lo mantissa is zero so we need to
|
|
|
29e444 |
- normalize the it for the low double. Shift it left until the
|
|
|
29e444 |
- hidden bit is '1' then adjust the 2nd exponent accordingly. */
|
|
|
29e444 |
-
|
|
|
29e444 |
- if (sizeof (lo) == sizeof (long))
|
|
|
29e444 |
- lzcount = __builtin_clzl (lo);
|
|
|
29e444 |
- else if ((lo >> 32) != 0)
|
|
|
29e444 |
- lzcount = __builtin_clzl ((long) (lo >> 32));
|
|
|
29e444 |
- else
|
|
|
29e444 |
- lzcount = __builtin_clzl ((long) lo) + 32;
|
|
|
29e444 |
- lzcount = lzcount - 11;
|
|
|
29e444 |
- if (lzcount > 0)
|
|
|
29e444 |
- {
|
|
|
29e444 |
- int expnt2 = u.ieee.exponent2 - lzcount;
|
|
|
29e444 |
- if (expnt2 >= 1)
|
|
|
29e444 |
- {
|
|
|
29e444 |
- /* Not denormal. Normalize and set low exponent. */
|
|
|
29e444 |
- lo = lo << lzcount;
|
|
|
29e444 |
- u.ieee.exponent2 = expnt2;
|
|
|
29e444 |
- }
|
|
|
29e444 |
- else
|
|
|
29e444 |
- {
|
|
|
29e444 |
- /* Is denormal. */
|
|
|
29e444 |
- lo = lo << (lzcount + expnt2);
|
|
|
29e444 |
- u.ieee.exponent2 = 0;
|
|
|
29e444 |
- }
|
|
|
29e444 |
- }
|
|
|
29e444 |
- }
|
|
|
29e444 |
- else
|
|
|
29e444 |
- {
|
|
|
29e444 |
- u.ieee.negative2 = 0;
|
|
|
29e444 |
- u.ieee.exponent2 = 0;
|
|
|
29e444 |
- }
|
|
|
29e444 |
-
|
|
|
29e444 |
- u.ieee.mantissa3 = lo & ((1ULL << 32) - 1);
|
|
|
29e444 |
- u.ieee.mantissa2 = (lo >> 32) & ((1ULL << 20) - 1);
|
|
|
29e444 |
- u.ieee.mantissa1 = hi & ((1ULL << 32) - 1);
|
|
|
29e444 |
- u.ieee.mantissa0 = (hi >> 32) & ((1ULL << 20) - 1);
|
|
|
29e444 |
- return u.d;
|
|
|
29e444 |
-}
|
|
|
29e444 |
-
|
|
|
29e444 |
-/* gcc generates disgusting code to pack and unpack long doubles.
|
|
|
29e444 |
- This tells gcc that pack/unpack is really a nop. We use fr1/fr2
|
|
|
29e444 |
- because those are the regs used to pass/return a single
|
|
|
29e444 |
- long double arg. */
|
|
|
29e444 |
+/* GCC does not optimize the default ldbl_pack code to not spill register
|
|
|
29e444 |
+ in the stack. The following optimization tells gcc that pack/unpack
|
|
|
29e444 |
+ is really a nop. We use fr1/fr2 because those are the regs used to
|
|
|
29e444 |
+ pass/return a single long double arg. */
|
|
|
29e444 |
static inline long double
|
|
|
29e444 |
-ldbl_pack (double a, double aa)
|
|
|
29e444 |
+ldbl_pack_ppc (double a, double aa)
|
|
|
29e444 |
{
|
|
|
29e444 |
register long double x __asm__ ("fr1");
|
|
|
29e444 |
register double xh __asm__ ("fr1");
|
|
|
29e444 |
@@ -139,7 +19,7 @@ ldbl_pack (double a, double aa)
|
|
|
29e444 |
}
|
|
|
29e444 |
|
|
|
29e444 |
static inline void
|
|
|
29e444 |
-ldbl_unpack (long double l, double *a, double *aa)
|
|
|
29e444 |
+ldbl_unpack_ppc (long double l, double *a, double *aa)
|
|
|
29e444 |
{
|
|
|
29e444 |
register long double x __asm__ ("fr1");
|
|
|
29e444 |
register double xh __asm__ ("fr1");
|
|
|
29e444 |
@@ -150,40 +30,7 @@ ldbl_unpack (long double l, double *a, double *aa)
|
|
|
29e444 |
*aa = xl;
|
|
|
29e444 |
}
|
|
|
29e444 |
|
|
|
29e444 |
+#define ldbl_pack ldbl_pack_ppc
|
|
|
29e444 |
+#define ldbl_unpack ldbl_unpack_ppc
|
|
|
29e444 |
|
|
|
29e444 |
-/* Convert a finite long double to canonical form.
|
|
|
29e444 |
- Does not handle +/-Inf properly. */
|
|
|
29e444 |
-static inline void
|
|
|
29e444 |
-ldbl_canonicalize (double *a, double *aa)
|
|
|
29e444 |
-{
|
|
|
29e444 |
- double xh, xl;
|
|
|
29e444 |
-
|
|
|
29e444 |
- xh = *a + *aa;
|
|
|
29e444 |
- xl = (*a - xh) + *aa;
|
|
|
29e444 |
- *a = xh;
|
|
|
29e444 |
- *aa = xl;
|
|
|
29e444 |
-}
|
|
|
29e444 |
-
|
|
|
29e444 |
-/* Simple inline nearbyint (double) function .
|
|
|
29e444 |
- Only works in the default rounding mode
|
|
|
29e444 |
- but is useful in long double rounding functions. */
|
|
|
29e444 |
-static inline double
|
|
|
29e444 |
-ldbl_nearbyint (double a)
|
|
|
29e444 |
-{
|
|
|
29e444 |
- double two52 = 0x10000000000000LL;
|
|
|
29e444 |
-
|
|
|
29e444 |
- if (__builtin_expect ((__builtin_fabs (a) < two52), 1))
|
|
|
29e444 |
- {
|
|
|
29e444 |
- if (__builtin_expect ((a > 0.0), 1))
|
|
|
29e444 |
- {
|
|
|
29e444 |
- a += two52;
|
|
|
29e444 |
- a -= two52;
|
|
|
29e444 |
- }
|
|
|
29e444 |
- else if (__builtin_expect ((a < 0.0), 1))
|
|
|
29e444 |
- {
|
|
|
29e444 |
- a = two52 - a;
|
|
|
29e444 |
- a = -(a - two52);
|
|
|
29e444 |
- }
|
|
|
29e444 |
- }
|
|
|
29e444 |
- return a;
|
|
|
29e444 |
-}
|
|
|
29e444 |
+#include <sysdeps/ieee754/ldbl-128ibm/math_ldbl.h>
|
|
|
12745e |
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Implies glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Implies
|
|
|
29e444 |
deleted file mode 100644
|
|
|
29e444 |
index ff27cdb..0000000
|
|
|
12745e |
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Implies
|
|
|
29e444 |
+++ /dev/null
|
|
|
29e444 |
@@ -1,4 +0,0 @@
|
|
|
29e444 |
-# Make sure these routines come before ldbl-opt.
|
|
|
29e444 |
-ieee754/ldbl-128ibm
|
|
|
29e444 |
-# These supply the ABI compatibility for when long double was double.
|
|
|
29e444 |
-ieee754/ldbl-opt
|
|
|
29e444 |
--
|
|
|
29e444 |
1.7.11.7
|
|
|
29e444 |
|