summaryrefslogtreecommitdiff
path: root/packages/glibc/2.17/0020-glibc-rh731833-libm-3.patch
blob: 15e6010ab243e1ea00f99f003254997446eb2db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
From c00f26c0eaba5a9680aac0f98de4b6e385a8cb82 Mon Sep 17 00:00:00 2001
From: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date: Fri, 8 Mar 2013 11:07:15 -0300
Subject: [PATCH 18/42] PowerPC: unify math_ldbl.h implementations

This patch removes redudant definition from PowerPC specific
math_ldbl, using the definitions from ieee754 math_ldbl.h.
(backported from commit edf66e57fc2bac083ecc9756a5fe47f9041ed3bb)
---
 sysdeps/ieee754/ldbl-128ibm/math_ldbl.h |   10 +
 sysdeps/powerpc/Implies                 |    1 
 sysdeps/powerpc/fpu/math_ldbl.h         |  171 +-------------------------------
 sysdeps/unix/sysv/linux/powerpc/Implies |    4 
 4 files changed, 18 insertions(+), 168 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/Implies

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