Blame SOURCES/glibc-rh731833-libm-3.patch

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