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