xref: /freebsd/contrib/arm-optimized-routines/math/aarch64/advsimd/finite_pow.h (revision f3087bef11543b42e0d69b708f367097a4118d24)
1*f3087befSAndrew Turner /*
2*f3087befSAndrew Turner  * Double-precision x^y function.
3*f3087befSAndrew Turner  *
4*f3087befSAndrew Turner  * Copyright (c) 2018-2024, Arm Limited.
5*f3087befSAndrew Turner  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6*f3087befSAndrew Turner  */
7*f3087befSAndrew Turner 
8*f3087befSAndrew Turner #include "math_config.h"
9*f3087befSAndrew Turner 
10*f3087befSAndrew Turner /* Scalar version of pow used for fallbacks in vector implementations.  */
11*f3087befSAndrew Turner 
12*f3087befSAndrew Turner /* Data is defined in v_pow_log_data.c.  */
13*f3087befSAndrew Turner #define N_LOG (1 << V_POW_LOG_TABLE_BITS)
14*f3087befSAndrew Turner #define Off 0x3fe6955500000000
15*f3087befSAndrew Turner #define As __v_pow_log_data.poly
16*f3087befSAndrew Turner 
17*f3087befSAndrew Turner /* Data is defined in v_pow_exp_data.c.  */
18*f3087befSAndrew Turner #define N_EXP (1 << V_POW_EXP_TABLE_BITS)
19*f3087befSAndrew Turner #define SignBias (0x800 << V_POW_EXP_TABLE_BITS)
20*f3087befSAndrew Turner #define SmallExp 0x3c9 /* top12(0x1p-54).  */
21*f3087befSAndrew Turner #define BigExp 0x408   /* top12(512.0).  */
22*f3087befSAndrew Turner #define ThresExp 0x03f /* BigExp - SmallExp.  */
23*f3087befSAndrew Turner #define InvLn2N __v_pow_exp_data.n_over_ln2
24*f3087befSAndrew Turner #define Ln2HiN __v_pow_exp_data.ln2_over_n_hi
25*f3087befSAndrew Turner #define Ln2LoN __v_pow_exp_data.ln2_over_n_lo
26*f3087befSAndrew Turner #define SBits __v_pow_exp_data.sbits
27*f3087befSAndrew Turner #define Cs __v_pow_exp_data.poly
28*f3087befSAndrew Turner 
29*f3087befSAndrew Turner /* Constants associated with pow.  */
30*f3087befSAndrew Turner #define SmallPowX 0x001 /* top12(0x1p-126).  */
31*f3087befSAndrew Turner #define BigPowX 0x7ff	/* top12(INFINITY).  */
32*f3087befSAndrew Turner #define ThresPowX 0x7fe /* BigPowX - SmallPowX.  */
33*f3087befSAndrew Turner #define SmallPowY 0x3be /* top12(0x1.e7b6p-65).  */
34*f3087befSAndrew Turner #define BigPowY 0x43e	/* top12(0x1.749p62).  */
35*f3087befSAndrew Turner #define ThresPowY 0x080 /* BigPowY - SmallPowY.  */
36*f3087befSAndrew Turner 
37*f3087befSAndrew Turner /* Top 12 bits of a double (sign and exponent bits).  */
38*f3087befSAndrew Turner static inline uint32_t
top12(double x)39*f3087befSAndrew Turner top12 (double x)
40*f3087befSAndrew Turner {
41*f3087befSAndrew Turner   return asuint64 (x) >> 52;
42*f3087befSAndrew Turner }
43*f3087befSAndrew Turner 
44*f3087befSAndrew Turner /* Compute y+TAIL = log(x) where the rounded result is y and TAIL has about
45*f3087befSAndrew Turner    additional 15 bits precision.  IX is the bit representation of x, but
46*f3087befSAndrew Turner    normalized in the subnormal range using the sign bit for the exponent.  */
47*f3087befSAndrew Turner static inline double
log_inline(uint64_t ix,double * tail)48*f3087befSAndrew Turner log_inline (uint64_t ix, double *tail)
49*f3087befSAndrew Turner {
50*f3087befSAndrew Turner   /* x = 2^k z; where z is in range [Off,2*Off) and exact.
51*f3087befSAndrew Turner      The range is split into N subintervals.
52*f3087befSAndrew Turner      The ith subinterval contains z and c is near its center.  */
53*f3087befSAndrew Turner   uint64_t tmp = ix - Off;
54*f3087befSAndrew Turner   int i = (tmp >> (52 - V_POW_LOG_TABLE_BITS)) & (N_LOG - 1);
55*f3087befSAndrew Turner   int k = (int64_t) tmp >> 52; /* arithmetic shift.  */
56*f3087befSAndrew Turner   uint64_t iz = ix - (tmp & 0xfffULL << 52);
57*f3087befSAndrew Turner   double z = asdouble (iz);
58*f3087befSAndrew Turner   double kd = (double) k;
59*f3087befSAndrew Turner 
60*f3087befSAndrew Turner   /* log(x) = k*Ln2 + log(c) + log1p(z/c-1).  */
61*f3087befSAndrew Turner   double invc = __v_pow_log_data.invc[i];
62*f3087befSAndrew Turner   double logc = __v_pow_log_data.logc[i];
63*f3087befSAndrew Turner   double logctail = __v_pow_log_data.logctail[i];
64*f3087befSAndrew Turner 
65*f3087befSAndrew Turner   /* Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and
66*f3087befSAndrew Turner      |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.  */
67*f3087befSAndrew Turner   double r = fma (z, invc, -1.0);
68*f3087befSAndrew Turner 
69*f3087befSAndrew Turner   /* k*Ln2 + log(c) + r.  */
70*f3087befSAndrew Turner   double t1 = kd * __v_pow_log_data.ln2_hi + logc;
71*f3087befSAndrew Turner   double t2 = t1 + r;
72*f3087befSAndrew Turner   double lo1 = kd * __v_pow_log_data.ln2_lo + logctail;
73*f3087befSAndrew Turner   double lo2 = t1 - t2 + r;
74*f3087befSAndrew Turner 
75*f3087befSAndrew Turner   /* Evaluation is optimized assuming superscalar pipelined execution.  */
76*f3087befSAndrew Turner   double ar = As[0] * r;
77*f3087befSAndrew Turner   double ar2 = r * ar;
78*f3087befSAndrew Turner   double ar3 = r * ar2;
79*f3087befSAndrew Turner   /* k*Ln2 + log(c) + r + A[0]*r*r.  */
80*f3087befSAndrew Turner   double hi = t2 + ar2;
81*f3087befSAndrew Turner   double lo3 = fma (ar, r, -ar2);
82*f3087befSAndrew Turner   double lo4 = t2 - hi + ar2;
83*f3087befSAndrew Turner   /* p = log1p(r) - r - A[0]*r*r.  */
84*f3087befSAndrew Turner   double p = (ar3
85*f3087befSAndrew Turner 	      * (As[1] + r * As[2]
86*f3087befSAndrew Turner 		 + ar2 * (As[3] + r * As[4] + ar2 * (As[5] + r * As[6]))));
87*f3087befSAndrew Turner   double lo = lo1 + lo2 + lo3 + lo4 + p;
88*f3087befSAndrew Turner   double y = hi + lo;
89*f3087befSAndrew Turner   *tail = hi - y + lo;
90*f3087befSAndrew Turner   return y;
91*f3087befSAndrew Turner }
92*f3087befSAndrew Turner 
93*f3087befSAndrew Turner /* Handle cases that may overflow or underflow when computing the result that
94*f3087befSAndrew Turner    is scale*(1+TMP) without intermediate rounding.  The bit representation of
95*f3087befSAndrew Turner    scale is in SBITS, however it has a computed exponent that may have
96*f3087befSAndrew Turner    overflown into the sign bit so that needs to be adjusted before using it as
97*f3087befSAndrew Turner    a double.  (int32_t)KI is the k used in the argument reduction and exponent
98*f3087befSAndrew Turner    adjustment of scale, positive k here means the result may overflow and
99*f3087befSAndrew Turner    negative k means the result may underflow.  */
100*f3087befSAndrew Turner static inline double
special_case(double tmp,uint64_t sbits,uint64_t ki)101*f3087befSAndrew Turner special_case (double tmp, uint64_t sbits, uint64_t ki)
102*f3087befSAndrew Turner {
103*f3087befSAndrew Turner   double scale, y;
104*f3087befSAndrew Turner 
105*f3087befSAndrew Turner   if ((ki & 0x80000000) == 0)
106*f3087befSAndrew Turner     {
107*f3087befSAndrew Turner       /* k > 0, the exponent of scale might have overflowed by <= 460.  */
108*f3087befSAndrew Turner       sbits -= 1009ull << 52;
109*f3087befSAndrew Turner       scale = asdouble (sbits);
110*f3087befSAndrew Turner       y = 0x1p1009 * (scale + scale * tmp);
111*f3087befSAndrew Turner       return y;
112*f3087befSAndrew Turner     }
113*f3087befSAndrew Turner   /* k < 0, need special care in the subnormal range.  */
114*f3087befSAndrew Turner   sbits += 1022ull << 52;
115*f3087befSAndrew Turner   /* Note: sbits is signed scale.  */
116*f3087befSAndrew Turner   scale = asdouble (sbits);
117*f3087befSAndrew Turner   y = scale + scale * tmp;
118*f3087befSAndrew Turner #if WANT_SIMD_EXCEPT
119*f3087befSAndrew Turner   if (fabs (y) < 1.0)
120*f3087befSAndrew Turner     {
121*f3087befSAndrew Turner       /* Round y to the right precision before scaling it into the subnormal
122*f3087befSAndrew Turner 	 range to avoid double rounding that can cause 0.5+E/2 ulp error where
123*f3087befSAndrew Turner 	 E is the worst-case ulp error outside the subnormal range.  So this
124*f3087befSAndrew Turner 	 is only useful if the goal is better than 1 ulp worst-case error.  */
125*f3087befSAndrew Turner       double hi, lo, one = 1.0;
126*f3087befSAndrew Turner       if (y < 0.0)
127*f3087befSAndrew Turner 	one = -1.0;
128*f3087befSAndrew Turner       lo = scale - y + scale * tmp;
129*f3087befSAndrew Turner       hi = one + y;
130*f3087befSAndrew Turner       lo = one - hi + y + lo;
131*f3087befSAndrew Turner       y = (hi + lo) - one;
132*f3087befSAndrew Turner       /* Fix the sign of 0.  */
133*f3087befSAndrew Turner       if (y == 0.0)
134*f3087befSAndrew Turner 	y = asdouble (sbits & 0x8000000000000000);
135*f3087befSAndrew Turner       /* The underflow exception needs to be signaled explicitly.  */
136*f3087befSAndrew Turner       force_eval_double (opt_barrier_double (0x1p-1022) * 0x1p-1022);
137*f3087befSAndrew Turner     }
138*f3087befSAndrew Turner #endif
139*f3087befSAndrew Turner   y = 0x1p-1022 * y;
140*f3087befSAndrew Turner   return y;
141*f3087befSAndrew Turner }
142*f3087befSAndrew Turner 
143*f3087befSAndrew Turner /* Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.
144*f3087befSAndrew Turner    The sign_bias argument is SignBias or 0 and sets the sign to -1 or 1.  */
145*f3087befSAndrew Turner static inline double
exp_inline(double x,double xtail,uint32_t sign_bias)146*f3087befSAndrew Turner exp_inline (double x, double xtail, uint32_t sign_bias)
147*f3087befSAndrew Turner {
148*f3087befSAndrew Turner   uint32_t abstop = top12 (x) & 0x7ff;
149*f3087befSAndrew Turner   if (unlikely (abstop - SmallExp >= ThresExp))
150*f3087befSAndrew Turner     {
151*f3087befSAndrew Turner       if (abstop - SmallExp >= 0x80000000)
152*f3087befSAndrew Turner 	{
153*f3087befSAndrew Turner 	  /* Avoid spurious underflow for tiny x.  */
154*f3087befSAndrew Turner 	  /* Note: 0 is common input.  */
155*f3087befSAndrew Turner 	  return sign_bias ? -1.0 : 1.0;
156*f3087befSAndrew Turner 	}
157*f3087befSAndrew Turner       if (abstop >= top12 (1024.0))
158*f3087befSAndrew Turner 	{
159*f3087befSAndrew Turner 	  /* Note: inf and nan are already handled.  */
160*f3087befSAndrew Turner 	  /* Skip errno handling.  */
161*f3087befSAndrew Turner #if WANT_SIMD_EXCEPT
162*f3087befSAndrew Turner 	  return asuint64 (x) >> 63 ? __math_uflow (sign_bias)
163*f3087befSAndrew Turner 				    : __math_oflow (sign_bias);
164*f3087befSAndrew Turner #else
165*f3087befSAndrew Turner 	  double res_uoflow = asuint64 (x) >> 63 ? 0.0 : INFINITY;
166*f3087befSAndrew Turner 	  return sign_bias ? -res_uoflow : res_uoflow;
167*f3087befSAndrew Turner #endif
168*f3087befSAndrew Turner 	}
169*f3087befSAndrew Turner       /* Large x is special cased below.  */
170*f3087befSAndrew Turner       abstop = 0;
171*f3087befSAndrew Turner     }
172*f3087befSAndrew Turner 
173*f3087befSAndrew Turner   /* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].  */
174*f3087befSAndrew Turner   /* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].  */
175*f3087befSAndrew Turner   double z = InvLn2N * x;
176*f3087befSAndrew Turner   double kd = round (z);
177*f3087befSAndrew Turner   uint64_t ki = lround (z);
178*f3087befSAndrew Turner   double r = x - kd * Ln2HiN - kd * Ln2LoN;
179*f3087befSAndrew Turner   /* The code assumes 2^-200 < |xtail| < 2^-8/N.  */
180*f3087befSAndrew Turner   r += xtail;
181*f3087befSAndrew Turner   /* 2^(k/N) ~= scale.  */
182*f3087befSAndrew Turner   uint64_t idx = ki & (N_EXP - 1);
183*f3087befSAndrew Turner   uint64_t top = (ki + sign_bias) << (52 - V_POW_EXP_TABLE_BITS);
184*f3087befSAndrew Turner   /* This is only a valid scale when -1023*N < k < 1024*N.  */
185*f3087befSAndrew Turner   uint64_t sbits = SBits[idx] + top;
186*f3087befSAndrew Turner   /* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (exp(r) - 1).  */
187*f3087befSAndrew Turner   /* Evaluation is optimized assuming superscalar pipelined execution.  */
188*f3087befSAndrew Turner   double r2 = r * r;
189*f3087befSAndrew Turner   double tmp = r + r2 * Cs[0] + r * r2 * (Cs[1] + r * Cs[2]);
190*f3087befSAndrew Turner   if (unlikely (abstop == 0))
191*f3087befSAndrew Turner     return special_case (tmp, sbits, ki);
192*f3087befSAndrew Turner   double scale = asdouble (sbits);
193*f3087befSAndrew Turner   /* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
194*f3087befSAndrew Turner      is no spurious underflow here even without fma.  */
195*f3087befSAndrew Turner   return scale + scale * tmp;
196*f3087befSAndrew Turner }
197*f3087befSAndrew Turner 
198*f3087befSAndrew Turner /* Computes exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.
199*f3087befSAndrew Turner    A version of exp_inline that is not inlined and for which sign_bias is
200*f3087befSAndrew Turner    equal to 0.  */
201*f3087befSAndrew Turner static double NOINLINE
exp_nosignbias(double x,double xtail)202*f3087befSAndrew Turner exp_nosignbias (double x, double xtail)
203*f3087befSAndrew Turner {
204*f3087befSAndrew Turner   uint32_t abstop = top12 (x) & 0x7ff;
205*f3087befSAndrew Turner   if (unlikely (abstop - SmallExp >= ThresExp))
206*f3087befSAndrew Turner     {
207*f3087befSAndrew Turner       /* Avoid spurious underflow for tiny x.  */
208*f3087befSAndrew Turner       if (abstop - SmallExp >= 0x80000000)
209*f3087befSAndrew Turner 	return 1.0;
210*f3087befSAndrew Turner       /* Note: inf and nan are already handled.  */
211*f3087befSAndrew Turner       if (abstop >= top12 (1024.0))
212*f3087befSAndrew Turner #if WANT_SIMD_EXCEPT
213*f3087befSAndrew Turner 	return asuint64 (x) >> 63 ? __math_uflow (0) : __math_oflow (0);
214*f3087befSAndrew Turner #else
215*f3087befSAndrew Turner 	return asuint64 (x) >> 63 ? 0.0 : INFINITY;
216*f3087befSAndrew Turner #endif
217*f3087befSAndrew Turner       /* Large x is special cased below.  */
218*f3087befSAndrew Turner       abstop = 0;
219*f3087befSAndrew Turner     }
220*f3087befSAndrew Turner 
221*f3087befSAndrew Turner   /* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].  */
222*f3087befSAndrew Turner   /* x = ln2/N*k + r, with k integer and r in [-ln2/2N, ln2/2N].  */
223*f3087befSAndrew Turner   double z = InvLn2N * x;
224*f3087befSAndrew Turner   double kd = round (z);
225*f3087befSAndrew Turner   uint64_t ki = lround (z);
226*f3087befSAndrew Turner   double r = x - kd * Ln2HiN - kd * Ln2LoN;
227*f3087befSAndrew Turner   /* The code assumes 2^-200 < |xtail| < 2^-8/N.  */
228*f3087befSAndrew Turner   r += xtail;
229*f3087befSAndrew Turner   /* 2^(k/N) ~= scale.  */
230*f3087befSAndrew Turner   uint64_t idx = ki & (N_EXP - 1);
231*f3087befSAndrew Turner   uint64_t top = ki << (52 - V_POW_EXP_TABLE_BITS);
232*f3087befSAndrew Turner   /* This is only a valid scale when -1023*N < k < 1024*N.  */
233*f3087befSAndrew Turner   uint64_t sbits = SBits[idx] + top;
234*f3087befSAndrew Turner   /* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).  */
235*f3087befSAndrew Turner   double r2 = r * r;
236*f3087befSAndrew Turner   double tmp = r + r2 * Cs[0] + r * r2 * (Cs[1] + r * Cs[2]);
237*f3087befSAndrew Turner   if (unlikely (abstop == 0))
238*f3087befSAndrew Turner     return special_case (tmp, sbits, ki);
239*f3087befSAndrew Turner   double scale = asdouble (sbits);
240*f3087befSAndrew Turner   /* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
241*f3087befSAndrew Turner      is no spurious underflow here even without fma.  */
242*f3087befSAndrew Turner   return scale + scale * tmp;
243*f3087befSAndrew Turner }
244*f3087befSAndrew Turner 
245*f3087befSAndrew Turner /* Returns 0 if not int, 1 if odd int, 2 if even int.  The argument is
246*f3087befSAndrew Turner    the bit representation of a non-zero finite floating-point value.  */
247*f3087befSAndrew Turner static inline int
checkint(uint64_t iy)248*f3087befSAndrew Turner checkint (uint64_t iy)
249*f3087befSAndrew Turner {
250*f3087befSAndrew Turner   int e = iy >> 52 & 0x7ff;
251*f3087befSAndrew Turner   if (e < 0x3ff)
252*f3087befSAndrew Turner     return 0;
253*f3087befSAndrew Turner   if (e > 0x3ff + 52)
254*f3087befSAndrew Turner     return 2;
255*f3087befSAndrew Turner   if (iy & ((1ULL << (0x3ff + 52 - e)) - 1))
256*f3087befSAndrew Turner     return 0;
257*f3087befSAndrew Turner   if (iy & (1ULL << (0x3ff + 52 - e)))
258*f3087befSAndrew Turner     return 1;
259*f3087befSAndrew Turner   return 2;
260*f3087befSAndrew Turner }
261*f3087befSAndrew Turner 
262*f3087befSAndrew Turner /* Returns 1 if input is the bit representation of 0, infinity or nan.  */
263*f3087befSAndrew Turner static inline int
zeroinfnan(uint64_t i)264*f3087befSAndrew Turner zeroinfnan (uint64_t i)
265*f3087befSAndrew Turner {
266*f3087befSAndrew Turner   return 2 * i - 1 >= 2 * asuint64 (INFINITY) - 1;
267*f3087befSAndrew Turner }
268*f3087befSAndrew Turner 
269*f3087befSAndrew Turner static double NOINLINE
pow_scalar_special_case(double x,double y)270*f3087befSAndrew Turner pow_scalar_special_case (double x, double y)
271*f3087befSAndrew Turner {
272*f3087befSAndrew Turner   uint32_t sign_bias = 0;
273*f3087befSAndrew Turner   uint64_t ix, iy;
274*f3087befSAndrew Turner   uint32_t topx, topy;
275*f3087befSAndrew Turner 
276*f3087befSAndrew Turner   ix = asuint64 (x);
277*f3087befSAndrew Turner   iy = asuint64 (y);
278*f3087befSAndrew Turner   topx = top12 (x);
279*f3087befSAndrew Turner   topy = top12 (y);
280*f3087befSAndrew Turner   if (unlikely (topx - SmallPowX >= ThresPowX
281*f3087befSAndrew Turner 		|| (topy & 0x7ff) - SmallPowY >= ThresPowY))
282*f3087befSAndrew Turner     {
283*f3087befSAndrew Turner       /* Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0
284*f3087befSAndrew Turner 	 and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.  */
285*f3087befSAndrew Turner       /* Special cases: (x < 0x1p-126 or inf or nan) or
286*f3087befSAndrew Turner 	 (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).  */
287*f3087befSAndrew Turner       if (unlikely (zeroinfnan (iy)))
288*f3087befSAndrew Turner 	{
289*f3087befSAndrew Turner 	  if (2 * iy == 0)
290*f3087befSAndrew Turner 	    return issignaling_inline (x) ? x + y : 1.0;
291*f3087befSAndrew Turner 	  if (ix == asuint64 (1.0))
292*f3087befSAndrew Turner 	    return issignaling_inline (y) ? x + y : 1.0;
293*f3087befSAndrew Turner 	  if (2 * ix > 2 * asuint64 (INFINITY)
294*f3087befSAndrew Turner 	      || 2 * iy > 2 * asuint64 (INFINITY))
295*f3087befSAndrew Turner 	    return x + y;
296*f3087befSAndrew Turner 	  if (2 * ix == 2 * asuint64 (1.0))
297*f3087befSAndrew Turner 	    return 1.0;
298*f3087befSAndrew Turner 	  if ((2 * ix < 2 * asuint64 (1.0)) == !(iy >> 63))
299*f3087befSAndrew Turner 	    return 0.0; /* |x|<1 && y==inf or |x|>1 && y==-inf.  */
300*f3087befSAndrew Turner 	  return y * y;
301*f3087befSAndrew Turner 	}
302*f3087befSAndrew Turner       if (unlikely (zeroinfnan (ix)))
303*f3087befSAndrew Turner 	{
304*f3087befSAndrew Turner 	  double x2 = x * x;
305*f3087befSAndrew Turner 	  if (ix >> 63 && checkint (iy) == 1)
306*f3087befSAndrew Turner 	    {
307*f3087befSAndrew Turner 	      x2 = -x2;
308*f3087befSAndrew Turner 	      sign_bias = 1;
309*f3087befSAndrew Turner 	    }
310*f3087befSAndrew Turner #if WANT_SIMD_EXCEPT
311*f3087befSAndrew Turner 	  if (2 * ix == 0 && iy >> 63)
312*f3087befSAndrew Turner 	    return __math_divzero (sign_bias);
313*f3087befSAndrew Turner #endif
314*f3087befSAndrew Turner 	  return iy >> 63 ? 1 / x2 : x2;
315*f3087befSAndrew Turner 	}
316*f3087befSAndrew Turner       /* Here x and y are non-zero finite.  */
317*f3087befSAndrew Turner       if (ix >> 63)
318*f3087befSAndrew Turner 	{
319*f3087befSAndrew Turner 	  /* Finite x < 0.  */
320*f3087befSAndrew Turner 	  int yint = checkint (iy);
321*f3087befSAndrew Turner 	  if (yint == 0)
322*f3087befSAndrew Turner #if WANT_SIMD_EXCEPT
323*f3087befSAndrew Turner 	    return __math_invalid (x);
324*f3087befSAndrew Turner #else
325*f3087befSAndrew Turner 	    return __builtin_nan ("");
326*f3087befSAndrew Turner #endif
327*f3087befSAndrew Turner 	  if (yint == 1)
328*f3087befSAndrew Turner 	    sign_bias = SignBias;
329*f3087befSAndrew Turner 	  ix &= 0x7fffffffffffffff;
330*f3087befSAndrew Turner 	  topx &= 0x7ff;
331*f3087befSAndrew Turner 	}
332*f3087befSAndrew Turner       if ((topy & 0x7ff) - SmallPowY >= ThresPowY)
333*f3087befSAndrew Turner 	{
334*f3087befSAndrew Turner 	  /* Note: sign_bias == 0 here because y is not odd.  */
335*f3087befSAndrew Turner 	  if (ix == asuint64 (1.0))
336*f3087befSAndrew Turner 	    return 1.0;
337*f3087befSAndrew Turner 	  /* |y| < 2^-65, x^y ~= 1 + y*log(x).  */
338*f3087befSAndrew Turner 	  if ((topy & 0x7ff) < SmallPowY)
339*f3087befSAndrew Turner 	    return 1.0;
340*f3087befSAndrew Turner #if WANT_SIMD_EXCEPT
341*f3087befSAndrew Turner 	  return (ix > asuint64 (1.0)) == (topy < 0x800) ? __math_oflow (0)
342*f3087befSAndrew Turner 							 : __math_uflow (0);
343*f3087befSAndrew Turner #else
344*f3087befSAndrew Turner 	  return (ix > asuint64 (1.0)) == (topy < 0x800) ? INFINITY : 0;
345*f3087befSAndrew Turner #endif
346*f3087befSAndrew Turner 	}
347*f3087befSAndrew Turner       if (topx == 0)
348*f3087befSAndrew Turner 	{
349*f3087befSAndrew Turner 	  /* Normalize subnormal x so exponent becomes negative.  */
350*f3087befSAndrew Turner 	  ix = asuint64 (x * 0x1p52);
351*f3087befSAndrew Turner 	  ix &= 0x7fffffffffffffff;
352*f3087befSAndrew Turner 	  ix -= 52ULL << 52;
353*f3087befSAndrew Turner 	}
354*f3087befSAndrew Turner     }
355*f3087befSAndrew Turner 
356*f3087befSAndrew Turner   double lo;
357*f3087befSAndrew Turner   double hi = log_inline (ix, &lo);
358*f3087befSAndrew Turner   double ehi = y * hi;
359*f3087befSAndrew Turner   double elo = y * lo + fma (y, hi, -ehi);
360*f3087befSAndrew Turner   return exp_inline (ehi, elo, sign_bias);
361*f3087befSAndrew Turner }
362