xref: /aosp_15_r20/external/arm-optimized-routines/math/pow.c (revision 412f47f9e737e10ed5cc46ec6a8d7fa2264f8a14)
1*412f47f9SXin Li /*
2*412f47f9SXin Li  * Double-precision x^y function.
3*412f47f9SXin Li  *
4*412f47f9SXin Li  * Copyright (c) 2018-2020, Arm Limited.
5*412f47f9SXin Li  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6*412f47f9SXin Li  */
7*412f47f9SXin Li 
8*412f47f9SXin Li #include <float.h>
9*412f47f9SXin Li #include <math.h>
10*412f47f9SXin Li #include <stdint.h>
11*412f47f9SXin Li #include "math_config.h"
12*412f47f9SXin Li 
13*412f47f9SXin Li /*
14*412f47f9SXin Li Worst-case error: 0.54 ULP (~= ulperr_exp + 1024*Ln2*relerr_log*2^53)
15*412f47f9SXin Li relerr_log: 1.3 * 2^-68 (Relative error of log, 1.5 * 2^-68 without fma)
16*412f47f9SXin Li ulperr_exp: 0.509 ULP (ULP error of exp, 0.511 ULP without fma)
17*412f47f9SXin Li */
18*412f47f9SXin Li 
19*412f47f9SXin Li #define T __pow_log_data.tab
20*412f47f9SXin Li #define A __pow_log_data.poly
21*412f47f9SXin Li #define Ln2hi __pow_log_data.ln2hi
22*412f47f9SXin Li #define Ln2lo __pow_log_data.ln2lo
23*412f47f9SXin Li #define N (1 << POW_LOG_TABLE_BITS)
24*412f47f9SXin Li #define OFF 0x3fe6955500000000
25*412f47f9SXin Li 
26*412f47f9SXin Li /* Top 12 bits of a double (sign and exponent bits).  */
27*412f47f9SXin Li static inline uint32_t
top12(double x)28*412f47f9SXin Li top12 (double x)
29*412f47f9SXin Li {
30*412f47f9SXin Li   return asuint64 (x) >> 52;
31*412f47f9SXin Li }
32*412f47f9SXin Li 
33*412f47f9SXin Li /* Compute y+TAIL = log(x) where the rounded result is y and TAIL has about
34*412f47f9SXin Li    additional 15 bits precision.  IX is the bit representation of x, but
35*412f47f9SXin Li    normalized in the subnormal range using the sign bit for the exponent.  */
36*412f47f9SXin Li static inline double_t
log_inline(uint64_t ix,double_t * tail)37*412f47f9SXin Li log_inline (uint64_t ix, double_t *tail)
38*412f47f9SXin Li {
39*412f47f9SXin Li   /* double_t for better performance on targets with FLT_EVAL_METHOD==2.  */
40*412f47f9SXin Li   double_t z, r, y, invc, logc, logctail, kd, hi, t1, t2, lo, lo1, lo2, p;
41*412f47f9SXin Li   uint64_t iz, tmp;
42*412f47f9SXin Li   int k, i;
43*412f47f9SXin Li 
44*412f47f9SXin Li   /* x = 2^k z; where z is in range [OFF,2*OFF) and exact.
45*412f47f9SXin Li      The range is split into N subintervals.
46*412f47f9SXin Li      The ith subinterval contains z and c is near its center.  */
47*412f47f9SXin Li   tmp = ix - OFF;
48*412f47f9SXin Li   i = (tmp >> (52 - POW_LOG_TABLE_BITS)) % N;
49*412f47f9SXin Li   k = (int64_t) tmp >> 52; /* arithmetic shift */
50*412f47f9SXin Li   iz = ix - (tmp & 0xfffULL << 52);
51*412f47f9SXin Li   z = asdouble (iz);
52*412f47f9SXin Li   kd = (double_t) k;
53*412f47f9SXin Li 
54*412f47f9SXin Li   /* log(x) = k*Ln2 + log(c) + log1p(z/c-1).  */
55*412f47f9SXin Li   invc = T[i].invc;
56*412f47f9SXin Li   logc = T[i].logc;
57*412f47f9SXin Li   logctail = T[i].logctail;
58*412f47f9SXin Li 
59*412f47f9SXin Li   /* Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and
60*412f47f9SXin Li      |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.  */
61*412f47f9SXin Li #if HAVE_FAST_FMA
62*412f47f9SXin Li   r = fma (z, invc, -1.0);
63*412f47f9SXin Li #else
64*412f47f9SXin Li   /* Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|.  */
65*412f47f9SXin Li   double_t zhi = asdouble ((iz + (1ULL << 31)) & (-1ULL << 32));
66*412f47f9SXin Li   double_t zlo = z - zhi;
67*412f47f9SXin Li   double_t rhi = zhi * invc - 1.0;
68*412f47f9SXin Li   double_t rlo = zlo * invc;
69*412f47f9SXin Li   r = rhi + rlo;
70*412f47f9SXin Li #endif
71*412f47f9SXin Li 
72*412f47f9SXin Li   /* k*Ln2 + log(c) + r.  */
73*412f47f9SXin Li   t1 = kd * Ln2hi + logc;
74*412f47f9SXin Li   t2 = t1 + r;
75*412f47f9SXin Li   lo1 = kd * Ln2lo + logctail;
76*412f47f9SXin Li   lo2 = t1 - t2 + r;
77*412f47f9SXin Li 
78*412f47f9SXin Li   /* Evaluation is optimized assuming superscalar pipelined execution.  */
79*412f47f9SXin Li   double_t ar, ar2, ar3, lo3, lo4;
80*412f47f9SXin Li   ar = A[0] * r; /* A[0] = -0.5.  */
81*412f47f9SXin Li   ar2 = r * ar;
82*412f47f9SXin Li   ar3 = r * ar2;
83*412f47f9SXin Li   /* k*Ln2 + log(c) + r + A[0]*r*r.  */
84*412f47f9SXin Li #if HAVE_FAST_FMA
85*412f47f9SXin Li   hi = t2 + ar2;
86*412f47f9SXin Li   lo3 = fma (ar, r, -ar2);
87*412f47f9SXin Li   lo4 = t2 - hi + ar2;
88*412f47f9SXin Li #else
89*412f47f9SXin Li   double_t arhi = A[0] * rhi;
90*412f47f9SXin Li   double_t arhi2 = rhi * arhi;
91*412f47f9SXin Li   hi = t2 + arhi2;
92*412f47f9SXin Li   lo3 = rlo * (ar + arhi);
93*412f47f9SXin Li   lo4 = t2 - hi + arhi2;
94*412f47f9SXin Li #endif
95*412f47f9SXin Li   /* p = log1p(r) - r - A[0]*r*r.  */
96*412f47f9SXin Li #if POW_LOG_POLY_ORDER == 8
97*412f47f9SXin Li   p = (ar3
98*412f47f9SXin Li        * (A[1] + r * A[2] + ar2 * (A[3] + r * A[4] + ar2 * (A[5] + r * A[6]))));
99*412f47f9SXin Li #endif
100*412f47f9SXin Li   lo = lo1 + lo2 + lo3 + lo4 + p;
101*412f47f9SXin Li   y = hi + lo;
102*412f47f9SXin Li   *tail = hi - y + lo;
103*412f47f9SXin Li   return y;
104*412f47f9SXin Li }
105*412f47f9SXin Li 
106*412f47f9SXin Li #undef N
107*412f47f9SXin Li #undef T
108*412f47f9SXin Li #define N (1 << EXP_TABLE_BITS)
109*412f47f9SXin Li #define InvLn2N __exp_data.invln2N
110*412f47f9SXin Li #define NegLn2hiN __exp_data.negln2hiN
111*412f47f9SXin Li #define NegLn2loN __exp_data.negln2loN
112*412f47f9SXin Li #define Shift __exp_data.shift
113*412f47f9SXin Li #define T __exp_data.tab
114*412f47f9SXin Li #define C2 __exp_data.poly[5 - EXP_POLY_ORDER]
115*412f47f9SXin Li #define C3 __exp_data.poly[6 - EXP_POLY_ORDER]
116*412f47f9SXin Li #define C4 __exp_data.poly[7 - EXP_POLY_ORDER]
117*412f47f9SXin Li #define C5 __exp_data.poly[8 - EXP_POLY_ORDER]
118*412f47f9SXin Li #define C6 __exp_data.poly[9 - EXP_POLY_ORDER]
119*412f47f9SXin Li 
120*412f47f9SXin Li /* Handle cases that may overflow or underflow when computing the result that
121*412f47f9SXin Li    is scale*(1+TMP) without intermediate rounding.  The bit representation of
122*412f47f9SXin Li    scale is in SBITS, however it has a computed exponent that may have
123*412f47f9SXin Li    overflown into the sign bit so that needs to be adjusted before using it as
124*412f47f9SXin Li    a double.  (int32_t)KI is the k used in the argument reduction and exponent
125*412f47f9SXin Li    adjustment of scale, positive k here means the result may overflow and
126*412f47f9SXin Li    negative k means the result may underflow.  */
127*412f47f9SXin Li static inline double
specialcase(double_t tmp,uint64_t sbits,uint64_t ki)128*412f47f9SXin Li specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
129*412f47f9SXin Li {
130*412f47f9SXin Li   double_t scale, y;
131*412f47f9SXin Li 
132*412f47f9SXin Li   if ((ki & 0x80000000) == 0)
133*412f47f9SXin Li     {
134*412f47f9SXin Li       /* k > 0, the exponent of scale might have overflowed by <= 460.  */
135*412f47f9SXin Li       sbits -= 1009ull << 52;
136*412f47f9SXin Li       scale = asdouble (sbits);
137*412f47f9SXin Li       y = 0x1p1009 * (scale + scale * tmp);
138*412f47f9SXin Li       return check_oflow (eval_as_double (y));
139*412f47f9SXin Li     }
140*412f47f9SXin Li   /* k < 0, need special care in the subnormal range.  */
141*412f47f9SXin Li   sbits += 1022ull << 52;
142*412f47f9SXin Li   /* Note: sbits is signed scale.  */
143*412f47f9SXin Li   scale = asdouble (sbits);
144*412f47f9SXin Li   y = scale + scale * tmp;
145*412f47f9SXin Li   if (fabs (y) < 1.0)
146*412f47f9SXin Li     {
147*412f47f9SXin Li       /* Round y to the right precision before scaling it into the subnormal
148*412f47f9SXin Li 	 range to avoid double rounding that can cause 0.5+E/2 ulp error where
149*412f47f9SXin Li 	 E is the worst-case ulp error outside the subnormal range.  So this
150*412f47f9SXin Li 	 is only useful if the goal is better than 1 ulp worst-case error.  */
151*412f47f9SXin Li       double_t hi, lo, one = 1.0;
152*412f47f9SXin Li       if (y < 0.0)
153*412f47f9SXin Li 	one = -1.0;
154*412f47f9SXin Li       lo = scale - y + scale * tmp;
155*412f47f9SXin Li       hi = one + y;
156*412f47f9SXin Li       lo = one - hi + y + lo;
157*412f47f9SXin Li       y = eval_as_double (hi + lo) - one;
158*412f47f9SXin Li       /* Fix the sign of 0.  */
159*412f47f9SXin Li       if (y == 0.0)
160*412f47f9SXin Li 	y = asdouble (sbits & 0x8000000000000000);
161*412f47f9SXin Li       /* The underflow exception needs to be signaled explicitly.  */
162*412f47f9SXin Li       force_eval_double (opt_barrier_double (0x1p-1022) * 0x1p-1022);
163*412f47f9SXin Li     }
164*412f47f9SXin Li   y = 0x1p-1022 * y;
165*412f47f9SXin Li   return check_uflow (eval_as_double (y));
166*412f47f9SXin Li }
167*412f47f9SXin Li 
168*412f47f9SXin Li #define SIGN_BIAS (0x800 << EXP_TABLE_BITS)
169*412f47f9SXin Li 
170*412f47f9SXin Li /* Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.
171*412f47f9SXin Li    The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1.  */
172*412f47f9SXin Li static inline double
exp_inline(double_t x,double_t xtail,uint32_t sign_bias)173*412f47f9SXin Li exp_inline (double_t x, double_t xtail, uint32_t sign_bias)
174*412f47f9SXin Li {
175*412f47f9SXin Li   uint32_t abstop;
176*412f47f9SXin Li   uint64_t ki, idx, top, sbits;
177*412f47f9SXin Li   /* double_t for better performance on targets with FLT_EVAL_METHOD==2.  */
178*412f47f9SXin Li   double_t kd, z, r, r2, scale, tail, tmp;
179*412f47f9SXin Li 
180*412f47f9SXin Li   abstop = top12 (x) & 0x7ff;
181*412f47f9SXin Li   if (unlikely (abstop - top12 (0x1p-54) >= top12 (512.0) - top12 (0x1p-54)))
182*412f47f9SXin Li     {
183*412f47f9SXin Li       if (abstop - top12 (0x1p-54) >= 0x80000000)
184*412f47f9SXin Li 	{
185*412f47f9SXin Li 	  /* Avoid spurious underflow for tiny x.  */
186*412f47f9SXin Li 	  /* Note: 0 is common input.  */
187*412f47f9SXin Li 	  double_t one = WANT_ROUNDING ? 1.0 + x : 1.0;
188*412f47f9SXin Li 	  return sign_bias ? -one : one;
189*412f47f9SXin Li 	}
190*412f47f9SXin Li       if (abstop >= top12 (1024.0))
191*412f47f9SXin Li 	{
192*412f47f9SXin Li 	  /* Note: inf and nan are already handled.  */
193*412f47f9SXin Li 	  if (asuint64 (x) >> 63)
194*412f47f9SXin Li 	    return __math_uflow (sign_bias);
195*412f47f9SXin Li 	  else
196*412f47f9SXin Li 	    return __math_oflow (sign_bias);
197*412f47f9SXin Li 	}
198*412f47f9SXin Li       /* Large x is special cased below.  */
199*412f47f9SXin Li       abstop = 0;
200*412f47f9SXin Li     }
201*412f47f9SXin Li 
202*412f47f9SXin Li   /* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].  */
203*412f47f9SXin Li   /* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].  */
204*412f47f9SXin Li   z = InvLn2N * x;
205*412f47f9SXin Li #if TOINT_INTRINSICS
206*412f47f9SXin Li   kd = roundtoint (z);
207*412f47f9SXin Li   ki = converttoint (z);
208*412f47f9SXin Li #elif EXP_USE_TOINT_NARROW
209*412f47f9SXin Li   /* z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.  */
210*412f47f9SXin Li   kd = eval_as_double (z + Shift);
211*412f47f9SXin Li   ki = asuint64 (kd) >> 16;
212*412f47f9SXin Li   kd = (double_t) (int32_t) ki;
213*412f47f9SXin Li #else
214*412f47f9SXin Li   /* z - kd is in [-1, 1] in non-nearest rounding modes.  */
215*412f47f9SXin Li   kd = eval_as_double (z + Shift);
216*412f47f9SXin Li   ki = asuint64 (kd);
217*412f47f9SXin Li   kd -= Shift;
218*412f47f9SXin Li #endif
219*412f47f9SXin Li   r = x + kd * NegLn2hiN + kd * NegLn2loN;
220*412f47f9SXin Li   /* The code assumes 2^-200 < |xtail| < 2^-8/N.  */
221*412f47f9SXin Li   r += xtail;
222*412f47f9SXin Li   /* 2^(k/N) ~= scale * (1 + tail).  */
223*412f47f9SXin Li   idx = 2 * (ki % N);
224*412f47f9SXin Li   top = (ki + sign_bias) << (52 - EXP_TABLE_BITS);
225*412f47f9SXin Li   tail = asdouble (T[idx]);
226*412f47f9SXin Li   /* This is only a valid scale when -1023*N < k < 1024*N.  */
227*412f47f9SXin Li   sbits = T[idx + 1] + top;
228*412f47f9SXin Li   /* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).  */
229*412f47f9SXin Li   /* Evaluation is optimized assuming superscalar pipelined execution.  */
230*412f47f9SXin Li   r2 = r * r;
231*412f47f9SXin Li   /* Without fma the worst case error is 0.25/N ulp larger.  */
232*412f47f9SXin Li   /* Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.  */
233*412f47f9SXin Li #if EXP_POLY_ORDER == 4
234*412f47f9SXin Li   tmp = tail + r + r2 * C2 + r * r2 * (C3 + r * C4);
235*412f47f9SXin Li #elif EXP_POLY_ORDER == 5
236*412f47f9SXin Li   tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);
237*412f47f9SXin Li #elif EXP_POLY_ORDER == 6
238*412f47f9SXin Li   tmp = tail + r + r2 * (0.5 + r * C3) + r2 * r2 * (C4 + r * C5 + r2 * C6);
239*412f47f9SXin Li #endif
240*412f47f9SXin Li   if (unlikely (abstop == 0))
241*412f47f9SXin Li     return specialcase (tmp, sbits, ki);
242*412f47f9SXin Li   scale = asdouble (sbits);
243*412f47f9SXin Li   /* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
244*412f47f9SXin Li      is no spurious underflow here even without fma.  */
245*412f47f9SXin Li   return eval_as_double (scale + scale * tmp);
246*412f47f9SXin Li }
247*412f47f9SXin Li 
248*412f47f9SXin Li /* Returns 0 if not int, 1 if odd int, 2 if even int.  The argument is
249*412f47f9SXin Li    the bit representation of a non-zero finite floating-point value.  */
250*412f47f9SXin Li static inline int
checkint(uint64_t iy)251*412f47f9SXin Li checkint (uint64_t iy)
252*412f47f9SXin Li {
253*412f47f9SXin Li   int e = iy >> 52 & 0x7ff;
254*412f47f9SXin Li   if (e < 0x3ff)
255*412f47f9SXin Li     return 0;
256*412f47f9SXin Li   if (e > 0x3ff + 52)
257*412f47f9SXin Li     return 2;
258*412f47f9SXin Li   if (iy & ((1ULL << (0x3ff + 52 - e)) - 1))
259*412f47f9SXin Li     return 0;
260*412f47f9SXin Li   if (iy & (1ULL << (0x3ff + 52 - e)))
261*412f47f9SXin Li     return 1;
262*412f47f9SXin Li   return 2;
263*412f47f9SXin Li }
264*412f47f9SXin Li 
265*412f47f9SXin Li /* Returns 1 if input is the bit representation of 0, infinity or nan.  */
266*412f47f9SXin Li static inline int
zeroinfnan(uint64_t i)267*412f47f9SXin Li zeroinfnan (uint64_t i)
268*412f47f9SXin Li {
269*412f47f9SXin Li   return 2 * i - 1 >= 2 * asuint64 (INFINITY) - 1;
270*412f47f9SXin Li }
271*412f47f9SXin Li 
272*412f47f9SXin Li double
pow(double x,double y)273*412f47f9SXin Li pow (double x, double y)
274*412f47f9SXin Li {
275*412f47f9SXin Li   uint32_t sign_bias = 0;
276*412f47f9SXin Li   uint64_t ix, iy;
277*412f47f9SXin Li   uint32_t topx, topy;
278*412f47f9SXin Li 
279*412f47f9SXin Li   ix = asuint64 (x);
280*412f47f9SXin Li   iy = asuint64 (y);
281*412f47f9SXin Li   topx = top12 (x);
282*412f47f9SXin Li   topy = top12 (y);
283*412f47f9SXin Li   if (unlikely (topx - 0x001 >= 0x7ff - 0x001
284*412f47f9SXin Li 		|| (topy & 0x7ff) - 0x3be >= 0x43e - 0x3be))
285*412f47f9SXin Li     {
286*412f47f9SXin Li       /* Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0
287*412f47f9SXin Li 	 and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.  */
288*412f47f9SXin Li       /* Special cases: (x < 0x1p-126 or inf or nan) or
289*412f47f9SXin Li 	 (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).  */
290*412f47f9SXin Li       if (unlikely (zeroinfnan (iy)))
291*412f47f9SXin Li 	{
292*412f47f9SXin Li 	  if (2 * iy == 0)
293*412f47f9SXin Li 	    return issignaling_inline (x) ? x + y : 1.0;
294*412f47f9SXin Li 	  if (ix == asuint64 (1.0))
295*412f47f9SXin Li 	    return issignaling_inline (y) ? x + y : 1.0;
296*412f47f9SXin Li 	  if (2 * ix > 2 * asuint64 (INFINITY)
297*412f47f9SXin Li 	      || 2 * iy > 2 * asuint64 (INFINITY))
298*412f47f9SXin Li 	    return x + y;
299*412f47f9SXin Li 	  if (2 * ix == 2 * asuint64 (1.0))
300*412f47f9SXin Li 	    return 1.0;
301*412f47f9SXin Li 	  if ((2 * ix < 2 * asuint64 (1.0)) == !(iy >> 63))
302*412f47f9SXin Li 	    return 0.0; /* |x|<1 && y==inf or |x|>1 && y==-inf.  */
303*412f47f9SXin Li 	  return y * y;
304*412f47f9SXin Li 	}
305*412f47f9SXin Li       if (unlikely (zeroinfnan (ix)))
306*412f47f9SXin Li 	{
307*412f47f9SXin Li 	  double_t x2 = x * x;
308*412f47f9SXin Li 	  if (ix >> 63 && checkint (iy) == 1)
309*412f47f9SXin Li 	    {
310*412f47f9SXin Li 	      x2 = -x2;
311*412f47f9SXin Li 	      sign_bias = 1;
312*412f47f9SXin Li 	    }
313*412f47f9SXin Li 	  if (WANT_ERRNO && 2 * ix == 0 && iy >> 63)
314*412f47f9SXin Li 	    return __math_divzero (sign_bias);
315*412f47f9SXin Li 	  /* Without the barrier some versions of clang hoist the 1/x2 and
316*412f47f9SXin Li 	     thus division by zero exception can be signaled spuriously.  */
317*412f47f9SXin Li 	  return iy >> 63 ? opt_barrier_double (1 / x2) : x2;
318*412f47f9SXin Li 	}
319*412f47f9SXin Li       /* Here x and y are non-zero finite.  */
320*412f47f9SXin Li       if (ix >> 63)
321*412f47f9SXin Li 	{
322*412f47f9SXin Li 	  /* Finite x < 0.  */
323*412f47f9SXin Li 	  int yint = checkint (iy);
324*412f47f9SXin Li 	  if (yint == 0)
325*412f47f9SXin Li 	    return __math_invalid (x);
326*412f47f9SXin Li 	  if (yint == 1)
327*412f47f9SXin Li 	    sign_bias = SIGN_BIAS;
328*412f47f9SXin Li 	  ix &= 0x7fffffffffffffff;
329*412f47f9SXin Li 	  topx &= 0x7ff;
330*412f47f9SXin Li 	}
331*412f47f9SXin Li       if ((topy & 0x7ff) - 0x3be >= 0x43e - 0x3be)
332*412f47f9SXin Li 	{
333*412f47f9SXin Li 	  /* Note: sign_bias == 0 here because y is not odd.  */
334*412f47f9SXin Li 	  if (ix == asuint64 (1.0))
335*412f47f9SXin Li 	    return 1.0;
336*412f47f9SXin Li 	  if ((topy & 0x7ff) < 0x3be)
337*412f47f9SXin Li 	    {
338*412f47f9SXin Li 	      /* |y| < 2^-65, x^y ~= 1 + y*log(x).  */
339*412f47f9SXin Li 	      if (WANT_ROUNDING)
340*412f47f9SXin Li 		return ix > asuint64 (1.0) ? 1.0 + y : 1.0 - y;
341*412f47f9SXin Li 	      else
342*412f47f9SXin Li 		return 1.0;
343*412f47f9SXin Li 	    }
344*412f47f9SXin Li 	  return (ix > asuint64 (1.0)) == (topy < 0x800) ? __math_oflow (0)
345*412f47f9SXin Li 							 : __math_uflow (0);
346*412f47f9SXin Li 	}
347*412f47f9SXin Li       if (topx == 0)
348*412f47f9SXin Li 	{
349*412f47f9SXin Li 	  /* Normalize subnormal x so exponent becomes negative.  */
350*412f47f9SXin Li 	  /* Without the barrier some versions of clang evalutate the mul
351*412f47f9SXin Li 	     unconditionally causing spurious overflow exceptions.  */
352*412f47f9SXin Li 	  ix = asuint64 (opt_barrier_double (x) * 0x1p52);
353*412f47f9SXin Li 	  ix &= 0x7fffffffffffffff;
354*412f47f9SXin Li 	  ix -= 52ULL << 52;
355*412f47f9SXin Li 	}
356*412f47f9SXin Li     }
357*412f47f9SXin Li 
358*412f47f9SXin Li   double_t lo;
359*412f47f9SXin Li   double_t hi = log_inline (ix, &lo);
360*412f47f9SXin Li   double_t ehi, elo;
361*412f47f9SXin Li #if HAVE_FAST_FMA
362*412f47f9SXin Li   ehi = y * hi;
363*412f47f9SXin Li   elo = y * lo + fma (y, hi, -ehi);
364*412f47f9SXin Li #else
365*412f47f9SXin Li   double_t yhi = asdouble (iy & -1ULL << 27);
366*412f47f9SXin Li   double_t ylo = y - yhi;
367*412f47f9SXin Li   double_t lhi = asdouble (asuint64 (hi) & -1ULL << 27);
368*412f47f9SXin Li   double_t llo = hi - lhi + lo;
369*412f47f9SXin Li   ehi = yhi * lhi;
370*412f47f9SXin Li   elo = ylo * lhi + y * llo; /* |elo| < |ehi| * 2^-25.  */
371*412f47f9SXin Li #endif
372*412f47f9SXin Li   return exp_inline (ehi, elo, sign_bias);
373*412f47f9SXin Li }
374*412f47f9SXin Li #if USE_GLIBC_ABI
strong_alias(pow,__pow_finite)375*412f47f9SXin Li strong_alias (pow, __pow_finite)
376*412f47f9SXin Li hidden_alias (pow, __ieee754_pow)
377*412f47f9SXin Li # if LDBL_MANT_DIG == 53
378*412f47f9SXin Li long double powl (long double x, long double y) { return pow (x, y); }
379*412f47f9SXin Li # endif
380*412f47f9SXin Li #endif
381