xref: /aosp_15_r20/external/arm-optimized-routines/pl/math/math_config.h (revision 412f47f9e737e10ed5cc46ec6a8d7fa2264f8a14)
1*412f47f9SXin Li /*
2*412f47f9SXin Li  * Configuration for math routines.
3*412f47f9SXin Li  *
4*412f47f9SXin Li  * Copyright (c) 2017-2024, 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 #ifndef _MATH_CONFIG_H
9*412f47f9SXin Li #define _MATH_CONFIG_H
10*412f47f9SXin Li 
11*412f47f9SXin Li #include <math.h>
12*412f47f9SXin Li #include <stdint.h>
13*412f47f9SXin Li 
14*412f47f9SXin Li #ifndef WANT_ROUNDING
15*412f47f9SXin Li /* If defined to 1, return correct results for special cases in non-nearest
16*412f47f9SXin Li    rounding modes (logf (1.0f) returns 0.0f with FE_DOWNWARD rather than
17*412f47f9SXin Li    -0.0f). This may be set to 0 if there is no fenv support or if math
18*412f47f9SXin Li    functions only get called in round to nearest mode.  */
19*412f47f9SXin Li # define WANT_ROUNDING 1
20*412f47f9SXin Li #endif
21*412f47f9SXin Li #ifndef WANT_ERRNO
22*412f47f9SXin Li /* If defined to 1, set errno in math functions according to ISO C.  Many math
23*412f47f9SXin Li    libraries do not set errno, so this is 0 by default.  It may need to be
24*412f47f9SXin Li    set to 1 if math.h has (math_errhandling & MATH_ERRNO) != 0.  */
25*412f47f9SXin Li # define WANT_ERRNO 0
26*412f47f9SXin Li #endif
27*412f47f9SXin Li #ifndef WANT_SIMD_EXCEPT
28*412f47f9SXin Li /* If defined to 1, trigger fp exceptions in vector routines, consistently with
29*412f47f9SXin Li    behaviour expected from the corresponding scalar routine.  */
30*412f47f9SXin Li # define WANT_SIMD_EXCEPT 0
31*412f47f9SXin Li #endif
32*412f47f9SXin Li 
33*412f47f9SXin Li /* Compiler can inline round as a single instruction.  */
34*412f47f9SXin Li #ifndef HAVE_FAST_ROUND
35*412f47f9SXin Li # if __aarch64__
36*412f47f9SXin Li #  define HAVE_FAST_ROUND 1
37*412f47f9SXin Li # else
38*412f47f9SXin Li #  define HAVE_FAST_ROUND 0
39*412f47f9SXin Li # endif
40*412f47f9SXin Li #endif
41*412f47f9SXin Li 
42*412f47f9SXin Li /* Compiler can inline lround, but not (long)round(x).  */
43*412f47f9SXin Li #ifndef HAVE_FAST_LROUND
44*412f47f9SXin Li # if __aarch64__ && (100 * __GNUC__ + __GNUC_MINOR__) >= 408                 \
45*412f47f9SXin Li       && __NO_MATH_ERRNO__
46*412f47f9SXin Li #  define HAVE_FAST_LROUND 1
47*412f47f9SXin Li # else
48*412f47f9SXin Li #  define HAVE_FAST_LROUND 0
49*412f47f9SXin Li # endif
50*412f47f9SXin Li #endif
51*412f47f9SXin Li 
52*412f47f9SXin Li /* Compiler can inline fma as a single instruction.  */
53*412f47f9SXin Li #ifndef HAVE_FAST_FMA
54*412f47f9SXin Li # if defined FP_FAST_FMA || __aarch64__
55*412f47f9SXin Li #  define HAVE_FAST_FMA 1
56*412f47f9SXin Li # else
57*412f47f9SXin Li #  define HAVE_FAST_FMA 0
58*412f47f9SXin Li # endif
59*412f47f9SXin Li #endif
60*412f47f9SXin Li 
61*412f47f9SXin Li /* Provide *_finite symbols and some of the glibc hidden symbols
62*412f47f9SXin Li    so libmathlib can be used with binaries compiled against glibc
63*412f47f9SXin Li    to interpose math functions with both static and dynamic linking.  */
64*412f47f9SXin Li #ifndef USE_GLIBC_ABI
65*412f47f9SXin Li # if __GNUC__
66*412f47f9SXin Li #  define USE_GLIBC_ABI 1
67*412f47f9SXin Li # else
68*412f47f9SXin Li #  define USE_GLIBC_ABI 0
69*412f47f9SXin Li # endif
70*412f47f9SXin Li #endif
71*412f47f9SXin Li 
72*412f47f9SXin Li /* Symbol renames to avoid libc conflicts.  */
73*412f47f9SXin Li #define __exp_data pl_math_exp_data
74*412f47f9SXin Li 
75*412f47f9SXin Li /* Optionally used extensions.  */
76*412f47f9SXin Li #ifdef __GNUC__
77*412f47f9SXin Li # define HIDDEN __attribute__ ((__visibility__ ("hidden")))
78*412f47f9SXin Li # define NOINLINE __attribute__ ((noinline))
79*412f47f9SXin Li # define UNUSED __attribute__ ((unused))
80*412f47f9SXin Li # define likely(x) __builtin_expect (!!(x), 1)
81*412f47f9SXin Li # define unlikely(x) __builtin_expect (x, 0)
82*412f47f9SXin Li # if __GNUC__ >= 9
83*412f47f9SXin Li #  define attribute_copy(f) __attribute__ ((copy (f)))
84*412f47f9SXin Li # else
85*412f47f9SXin Li #  define attribute_copy(f)
86*412f47f9SXin Li # endif
87*412f47f9SXin Li # define strong_alias(f, a)                                                   \
88*412f47f9SXin Li     extern __typeof (f) a __attribute__ ((alias (#f))) attribute_copy (f);
89*412f47f9SXin Li # define hidden_alias(f, a)                                                   \
90*412f47f9SXin Li     extern __typeof (f) a __attribute__ ((alias (#f), visibility ("hidden"))) \
91*412f47f9SXin Li 	attribute_copy (f);
92*412f47f9SXin Li #else
93*412f47f9SXin Li # define HIDDEN
94*412f47f9SXin Li # define NOINLINE
95*412f47f9SXin Li # define UNUSED
96*412f47f9SXin Li # define likely(x) (x)
97*412f47f9SXin Li # define unlikely(x) (x)
98*412f47f9SXin Li #endif
99*412f47f9SXin Li 
100*412f47f9SXin Li /* Return ptr but hide its value from the compiler so accesses through it
101*412f47f9SXin Li    cannot be optimized based on the contents.  */
102*412f47f9SXin Li #define ptr_barrier(ptr)                                                      \
103*412f47f9SXin Li   ({                                                                          \
104*412f47f9SXin Li     __typeof (ptr) __ptr = (ptr);                                             \
105*412f47f9SXin Li     __asm("" : "+r"(__ptr));                                                  \
106*412f47f9SXin Li     __ptr;                                                                    \
107*412f47f9SXin Li   })
108*412f47f9SXin Li 
109*412f47f9SXin Li /* Symbol renames to avoid libc conflicts.  */
110*412f47f9SXin Li #define __math_oflowf arm_math_oflowf
111*412f47f9SXin Li #define __math_uflowf arm_math_uflowf
112*412f47f9SXin Li #define __math_may_uflowf arm_math_may_uflowf
113*412f47f9SXin Li #define __math_divzerof arm_math_divzerof
114*412f47f9SXin Li #define __math_oflow arm_math_oflow
115*412f47f9SXin Li #define __math_uflow arm_math_uflow
116*412f47f9SXin Li #define __math_may_uflow arm_math_may_uflow
117*412f47f9SXin Li #define __math_divzero arm_math_divzero
118*412f47f9SXin Li #define __math_invalidf arm_math_invalidf
119*412f47f9SXin Li #define __math_invalid arm_math_invalid
120*412f47f9SXin Li #define __math_check_oflow arm_math_check_oflow
121*412f47f9SXin Li #define __math_check_uflow arm_math_check_uflow
122*412f47f9SXin Li #define __math_check_oflowf arm_math_check_oflowf
123*412f47f9SXin Li #define __math_check_uflowf arm_math_check_uflowf
124*412f47f9SXin Li 
125*412f47f9SXin Li #if HAVE_FAST_ROUND
126*412f47f9SXin Li /* When set, the roundtoint and converttoint functions are provided with
127*412f47f9SXin Li    the semantics documented below.  */
128*412f47f9SXin Li # define TOINT_INTRINSICS 1
129*412f47f9SXin Li 
130*412f47f9SXin Li /* Round x to nearest int in all rounding modes, ties have to be rounded
131*412f47f9SXin Li    consistently with converttoint so the results match.  If the result
132*412f47f9SXin Li    would be outside of [-2^31, 2^31-1] then the semantics is unspecified.  */
133*412f47f9SXin Li static inline double_t
roundtoint(double_t x)134*412f47f9SXin Li roundtoint (double_t x)
135*412f47f9SXin Li {
136*412f47f9SXin Li   return round (x);
137*412f47f9SXin Li }
138*412f47f9SXin Li 
139*412f47f9SXin Li /* Convert x to nearest int in all rounding modes, ties have to be rounded
140*412f47f9SXin Li    consistently with roundtoint.  If the result is not representible in an
141*412f47f9SXin Li    int32_t then the semantics is unspecified.  */
142*412f47f9SXin Li static inline int32_t
converttoint(double_t x)143*412f47f9SXin Li converttoint (double_t x)
144*412f47f9SXin Li {
145*412f47f9SXin Li # if HAVE_FAST_LROUND
146*412f47f9SXin Li   return lround (x);
147*412f47f9SXin Li # else
148*412f47f9SXin Li   return (long) round (x);
149*412f47f9SXin Li # endif
150*412f47f9SXin Li }
151*412f47f9SXin Li #endif
152*412f47f9SXin Li 
153*412f47f9SXin Li static inline uint32_t
asuint(float f)154*412f47f9SXin Li asuint (float f)
155*412f47f9SXin Li {
156*412f47f9SXin Li   union
157*412f47f9SXin Li   {
158*412f47f9SXin Li     float f;
159*412f47f9SXin Li     uint32_t i;
160*412f47f9SXin Li   } u = { f };
161*412f47f9SXin Li   return u.i;
162*412f47f9SXin Li }
163*412f47f9SXin Li 
164*412f47f9SXin Li static inline float
asfloat(uint32_t i)165*412f47f9SXin Li asfloat (uint32_t i)
166*412f47f9SXin Li {
167*412f47f9SXin Li   union
168*412f47f9SXin Li   {
169*412f47f9SXin Li     uint32_t i;
170*412f47f9SXin Li     float f;
171*412f47f9SXin Li   } u = { i };
172*412f47f9SXin Li   return u.f;
173*412f47f9SXin Li }
174*412f47f9SXin Li 
175*412f47f9SXin Li static inline uint64_t
asuint64(double f)176*412f47f9SXin Li asuint64 (double f)
177*412f47f9SXin Li {
178*412f47f9SXin Li   union
179*412f47f9SXin Li   {
180*412f47f9SXin Li     double f;
181*412f47f9SXin Li     uint64_t i;
182*412f47f9SXin Li   } u = { f };
183*412f47f9SXin Li   return u.i;
184*412f47f9SXin Li }
185*412f47f9SXin Li 
186*412f47f9SXin Li static inline double
asdouble(uint64_t i)187*412f47f9SXin Li asdouble (uint64_t i)
188*412f47f9SXin Li {
189*412f47f9SXin Li   union
190*412f47f9SXin Li   {
191*412f47f9SXin Li     uint64_t i;
192*412f47f9SXin Li     double f;
193*412f47f9SXin Li   } u = { i };
194*412f47f9SXin Li   return u.f;
195*412f47f9SXin Li }
196*412f47f9SXin Li 
197*412f47f9SXin Li #ifndef IEEE_754_2008_SNAN
198*412f47f9SXin Li # define IEEE_754_2008_SNAN 1
199*412f47f9SXin Li #endif
200*412f47f9SXin Li static inline int
issignalingf_inline(float x)201*412f47f9SXin Li issignalingf_inline (float x)
202*412f47f9SXin Li {
203*412f47f9SXin Li   uint32_t ix = asuint (x);
204*412f47f9SXin Li   if (!IEEE_754_2008_SNAN)
205*412f47f9SXin Li     return (ix & 0x7fc00000) == 0x7fc00000;
206*412f47f9SXin Li   return 2 * (ix ^ 0x00400000) > 2u * 0x7fc00000;
207*412f47f9SXin Li }
208*412f47f9SXin Li 
209*412f47f9SXin Li static inline int
issignaling_inline(double x)210*412f47f9SXin Li issignaling_inline (double x)
211*412f47f9SXin Li {
212*412f47f9SXin Li   uint64_t ix = asuint64 (x);
213*412f47f9SXin Li   if (!IEEE_754_2008_SNAN)
214*412f47f9SXin Li     return (ix & 0x7ff8000000000000) == 0x7ff8000000000000;
215*412f47f9SXin Li   return 2 * (ix ^ 0x0008000000000000) > 2 * 0x7ff8000000000000ULL;
216*412f47f9SXin Li }
217*412f47f9SXin Li 
218*412f47f9SXin Li #if __aarch64__ && __GNUC__
219*412f47f9SXin Li /* Prevent the optimization of a floating-point expression.  */
220*412f47f9SXin Li static inline float
opt_barrier_float(float x)221*412f47f9SXin Li opt_barrier_float (float x)
222*412f47f9SXin Li {
223*412f47f9SXin Li   __asm__ __volatile__ ("" : "+w" (x));
224*412f47f9SXin Li   return x;
225*412f47f9SXin Li }
226*412f47f9SXin Li static inline double
opt_barrier_double(double x)227*412f47f9SXin Li opt_barrier_double (double x)
228*412f47f9SXin Li {
229*412f47f9SXin Li   __asm__ __volatile__ ("" : "+w" (x));
230*412f47f9SXin Li   return x;
231*412f47f9SXin Li }
232*412f47f9SXin Li /* Force the evaluation of a floating-point expression for its side-effect.  */
233*412f47f9SXin Li static inline void
force_eval_float(float x)234*412f47f9SXin Li force_eval_float (float x)
235*412f47f9SXin Li {
236*412f47f9SXin Li   __asm__ __volatile__ ("" : "+w" (x));
237*412f47f9SXin Li }
238*412f47f9SXin Li static inline void
force_eval_double(double x)239*412f47f9SXin Li force_eval_double (double x)
240*412f47f9SXin Li {
241*412f47f9SXin Li   __asm__ __volatile__ ("" : "+w" (x));
242*412f47f9SXin Li }
243*412f47f9SXin Li #else
244*412f47f9SXin Li static inline float
opt_barrier_float(float x)245*412f47f9SXin Li opt_barrier_float (float x)
246*412f47f9SXin Li {
247*412f47f9SXin Li   volatile float y = x;
248*412f47f9SXin Li   return y;
249*412f47f9SXin Li }
250*412f47f9SXin Li static inline double
opt_barrier_double(double x)251*412f47f9SXin Li opt_barrier_double (double x)
252*412f47f9SXin Li {
253*412f47f9SXin Li   volatile double y = x;
254*412f47f9SXin Li   return y;
255*412f47f9SXin Li }
256*412f47f9SXin Li static inline void
force_eval_float(float x)257*412f47f9SXin Li force_eval_float (float x)
258*412f47f9SXin Li {
259*412f47f9SXin Li   volatile float y UNUSED = x;
260*412f47f9SXin Li }
261*412f47f9SXin Li static inline void
force_eval_double(double x)262*412f47f9SXin Li force_eval_double (double x)
263*412f47f9SXin Li {
264*412f47f9SXin Li   volatile double y UNUSED = x;
265*412f47f9SXin Li }
266*412f47f9SXin Li #endif
267*412f47f9SXin Li 
268*412f47f9SXin Li /* Evaluate an expression as the specified type, normally a type
269*412f47f9SXin Li    cast should be enough, but compilers implement non-standard
270*412f47f9SXin Li    excess-precision handling, so when FLT_EVAL_METHOD != 0 then
271*412f47f9SXin Li    these functions may need to be customized.  */
272*412f47f9SXin Li static inline float
eval_as_float(float x)273*412f47f9SXin Li eval_as_float (float x)
274*412f47f9SXin Li {
275*412f47f9SXin Li   return x;
276*412f47f9SXin Li }
277*412f47f9SXin Li static inline double
eval_as_double(double x)278*412f47f9SXin Li eval_as_double (double x)
279*412f47f9SXin Li {
280*412f47f9SXin Li   return x;
281*412f47f9SXin Li }
282*412f47f9SXin Li 
283*412f47f9SXin Li /* Error handling tail calls for special cases, with a sign argument.
284*412f47f9SXin Li    The sign of the return value is set if the argument is non-zero.  */
285*412f47f9SXin Li 
286*412f47f9SXin Li /* The result overflows.  */
287*412f47f9SXin Li HIDDEN float __math_oflowf (uint32_t);
288*412f47f9SXin Li /* The result underflows to 0 in nearest rounding mode.  */
289*412f47f9SXin Li HIDDEN float __math_uflowf (uint32_t);
290*412f47f9SXin Li /* The result underflows to 0 in some directed rounding mode only.  */
291*412f47f9SXin Li HIDDEN float __math_may_uflowf (uint32_t);
292*412f47f9SXin Li /* Division by zero.  */
293*412f47f9SXin Li HIDDEN float __math_divzerof (uint32_t);
294*412f47f9SXin Li /* The result overflows.  */
295*412f47f9SXin Li HIDDEN double __math_oflow (uint32_t);
296*412f47f9SXin Li /* The result underflows to 0 in nearest rounding mode.  */
297*412f47f9SXin Li HIDDEN double __math_uflow (uint32_t);
298*412f47f9SXin Li /* The result underflows to 0 in some directed rounding mode only.  */
299*412f47f9SXin Li HIDDEN double __math_may_uflow (uint32_t);
300*412f47f9SXin Li /* Division by zero.  */
301*412f47f9SXin Li HIDDEN double __math_divzero (uint32_t);
302*412f47f9SXin Li 
303*412f47f9SXin Li /* Error handling using input checking.  */
304*412f47f9SXin Li 
305*412f47f9SXin Li /* Invalid input unless it is a quiet NaN.  */
306*412f47f9SXin Li HIDDEN float __math_invalidf (float);
307*412f47f9SXin Li /* Invalid input unless it is a quiet NaN.  */
308*412f47f9SXin Li HIDDEN double __math_invalid (double);
309*412f47f9SXin Li 
310*412f47f9SXin Li /* Error handling using output checking, only for errno setting.  */
311*412f47f9SXin Li 
312*412f47f9SXin Li /* Check if the result overflowed to infinity.  */
313*412f47f9SXin Li HIDDEN double __math_check_oflow (double);
314*412f47f9SXin Li /* Check if the result underflowed to 0.  */
315*412f47f9SXin Li HIDDEN double __math_check_uflow (double);
316*412f47f9SXin Li 
317*412f47f9SXin Li /* Check if the result overflowed to infinity.  */
318*412f47f9SXin Li static inline double
check_oflow(double x)319*412f47f9SXin Li check_oflow (double x)
320*412f47f9SXin Li {
321*412f47f9SXin Li   return WANT_ERRNO ? __math_check_oflow (x) : x;
322*412f47f9SXin Li }
323*412f47f9SXin Li 
324*412f47f9SXin Li /* Check if the result underflowed to 0.  */
325*412f47f9SXin Li static inline double
check_uflow(double x)326*412f47f9SXin Li check_uflow (double x)
327*412f47f9SXin Li {
328*412f47f9SXin Li   return WANT_ERRNO ? __math_check_uflow (x) : x;
329*412f47f9SXin Li }
330*412f47f9SXin Li 
331*412f47f9SXin Li /* Check if the result overflowed to infinity.  */
332*412f47f9SXin Li HIDDEN float __math_check_oflowf (float);
333*412f47f9SXin Li /* Check if the result underflowed to 0.  */
334*412f47f9SXin Li HIDDEN float __math_check_uflowf (float);
335*412f47f9SXin Li 
336*412f47f9SXin Li /* Check if the result overflowed to infinity.  */
337*412f47f9SXin Li static inline float
check_oflowf(float x)338*412f47f9SXin Li check_oflowf (float x)
339*412f47f9SXin Li {
340*412f47f9SXin Li   return WANT_ERRNO ? __math_check_oflowf (x) : x;
341*412f47f9SXin Li }
342*412f47f9SXin Li 
343*412f47f9SXin Li /* Check if the result underflowed to 0.  */
344*412f47f9SXin Li static inline float
check_uflowf(float x)345*412f47f9SXin Li check_uflowf (float x)
346*412f47f9SXin Li {
347*412f47f9SXin Li   return WANT_ERRNO ? __math_check_uflowf (x) : x;
348*412f47f9SXin Li }
349*412f47f9SXin Li 
350*412f47f9SXin Li extern const struct erff_data
351*412f47f9SXin Li {
352*412f47f9SXin Li   struct
353*412f47f9SXin Li   {
354*412f47f9SXin Li     float erf, scale;
355*412f47f9SXin Li   } tab[513];
356*412f47f9SXin Li } __erff_data HIDDEN;
357*412f47f9SXin Li 
358*412f47f9SXin Li extern const struct sv_erff_data
359*412f47f9SXin Li {
360*412f47f9SXin Li   float erf[513];
361*412f47f9SXin Li   float scale[513];
362*412f47f9SXin Li } __sv_erff_data HIDDEN;
363*412f47f9SXin Li 
364*412f47f9SXin Li extern const struct erfcf_data
365*412f47f9SXin Li {
366*412f47f9SXin Li   struct
367*412f47f9SXin Li   {
368*412f47f9SXin Li     float erfc, scale;
369*412f47f9SXin Li   } tab[645];
370*412f47f9SXin Li } __erfcf_data HIDDEN;
371*412f47f9SXin Li 
372*412f47f9SXin Li /* Data for logf and log10f.  */
373*412f47f9SXin Li #define LOGF_TABLE_BITS 4
374*412f47f9SXin Li #define LOGF_POLY_ORDER 4
375*412f47f9SXin Li extern const struct logf_data
376*412f47f9SXin Li {
377*412f47f9SXin Li   struct
378*412f47f9SXin Li   {
379*412f47f9SXin Li     double invc, logc;
380*412f47f9SXin Li   } tab[1 << LOGF_TABLE_BITS];
381*412f47f9SXin Li   double ln2;
382*412f47f9SXin Li   double invln10;
383*412f47f9SXin Li   double poly[LOGF_POLY_ORDER - 1]; /* First order coefficient is 1.  */
384*412f47f9SXin Li } __logf_data HIDDEN;
385*412f47f9SXin Li 
386*412f47f9SXin Li /* Data for low accuracy log10 (with 1/ln(10) included in coefficients).  */
387*412f47f9SXin Li #define LOG10_TABLE_BITS 7
388*412f47f9SXin Li #define LOG10_POLY_ORDER 6
389*412f47f9SXin Li #define LOG10_POLY1_ORDER 12
390*412f47f9SXin Li extern const struct log10_data
391*412f47f9SXin Li {
392*412f47f9SXin Li   double ln2hi;
393*412f47f9SXin Li   double ln2lo;
394*412f47f9SXin Li   double invln10;
395*412f47f9SXin Li   double poly[LOG10_POLY_ORDER - 1]; /* First coefficient is 1/log(10).  */
396*412f47f9SXin Li   double poly1[LOG10_POLY1_ORDER - 1];
397*412f47f9SXin Li   struct
398*412f47f9SXin Li   {
399*412f47f9SXin Li     double invc, logc;
400*412f47f9SXin Li   } tab[1 << LOG10_TABLE_BITS];
401*412f47f9SXin Li #if !HAVE_FAST_FMA
402*412f47f9SXin Li   struct
403*412f47f9SXin Li   {
404*412f47f9SXin Li     double chi, clo;
405*412f47f9SXin Li   } tab2[1 << LOG10_TABLE_BITS];
406*412f47f9SXin Li #endif
407*412f47f9SXin Li } __log10_data HIDDEN;
408*412f47f9SXin Li 
409*412f47f9SXin Li #define EXP_TABLE_BITS 7
410*412f47f9SXin Li #define EXP_POLY_ORDER 5
411*412f47f9SXin Li /* Use polynomial that is optimized for a wider input range.  This may be
412*412f47f9SXin Li    needed for good precision in non-nearest rounding and !TOINT_INTRINSICS.  */
413*412f47f9SXin Li #define EXP_POLY_WIDE 0
414*412f47f9SXin Li /* Use close to nearest rounding toint when !TOINT_INTRINSICS.  This may be
415*412f47f9SXin Li    needed for good precision in non-nearest rouning and !EXP_POLY_WIDE.  */
416*412f47f9SXin Li #define EXP_USE_TOINT_NARROW 0
417*412f47f9SXin Li #define EXP2_POLY_ORDER 5
418*412f47f9SXin Li #define EXP2_POLY_WIDE 0
419*412f47f9SXin Li extern const struct exp_data
420*412f47f9SXin Li {
421*412f47f9SXin Li   double invln2N;
422*412f47f9SXin Li   double shift;
423*412f47f9SXin Li   double negln2hiN;
424*412f47f9SXin Li   double negln2loN;
425*412f47f9SXin Li   double poly[4]; /* Last four coefficients.  */
426*412f47f9SXin Li   double exp2_shift;
427*412f47f9SXin Li   double exp2_poly[EXP2_POLY_ORDER];
428*412f47f9SXin Li   uint64_t tab[2 * (1 << EXP_TABLE_BITS)];
429*412f47f9SXin Li } __exp_data HIDDEN;
430*412f47f9SXin Li 
431*412f47f9SXin Li /* Copied from math/v_exp.h for use in vector exp_tail.  */
432*412f47f9SXin Li #define V_EXP_TAIL_TABLE_BITS 8
433*412f47f9SXin Li extern const uint64_t __v_exp_tail_data[1 << V_EXP_TAIL_TABLE_BITS] HIDDEN;
434*412f47f9SXin Li 
435*412f47f9SXin Li /* Copied from math/v_exp.h for use in vector exp2.  */
436*412f47f9SXin Li #define V_EXP_TABLE_BITS 7
437*412f47f9SXin Li extern const uint64_t __v_exp_data[1 << V_EXP_TABLE_BITS] HIDDEN;
438*412f47f9SXin Li 
439*412f47f9SXin Li extern const struct erf_data
440*412f47f9SXin Li {
441*412f47f9SXin Li   struct
442*412f47f9SXin Li   {
443*412f47f9SXin Li     double erf, scale;
444*412f47f9SXin Li   } tab[769];
445*412f47f9SXin Li } __erf_data HIDDEN;
446*412f47f9SXin Li 
447*412f47f9SXin Li extern const struct sv_erf_data
448*412f47f9SXin Li {
449*412f47f9SXin Li   double erf[769];
450*412f47f9SXin Li   double scale[769];
451*412f47f9SXin Li } __sv_erf_data HIDDEN;
452*412f47f9SXin Li 
453*412f47f9SXin Li extern const struct erfc_data
454*412f47f9SXin Li {
455*412f47f9SXin Li   struct
456*412f47f9SXin Li   {
457*412f47f9SXin Li     double erfc, scale;
458*412f47f9SXin Li   } tab[3488];
459*412f47f9SXin Li } __erfc_data HIDDEN;
460*412f47f9SXin Li 
461*412f47f9SXin Li #define ATAN_POLY_NCOEFFS 20
462*412f47f9SXin Li extern const struct atan_poly_data
463*412f47f9SXin Li {
464*412f47f9SXin Li   double poly[ATAN_POLY_NCOEFFS];
465*412f47f9SXin Li } __atan_poly_data HIDDEN;
466*412f47f9SXin Li 
467*412f47f9SXin Li #define ATANF_POLY_NCOEFFS 8
468*412f47f9SXin Li extern const struct atanf_poly_data
469*412f47f9SXin Li {
470*412f47f9SXin Li   float poly[ATANF_POLY_NCOEFFS];
471*412f47f9SXin Li } __atanf_poly_data HIDDEN;
472*412f47f9SXin Li 
473*412f47f9SXin Li #define ASINHF_NCOEFFS 8
474*412f47f9SXin Li extern const struct asinhf_data
475*412f47f9SXin Li {
476*412f47f9SXin Li   float coeffs[ASINHF_NCOEFFS];
477*412f47f9SXin Li } __asinhf_data HIDDEN;
478*412f47f9SXin Li 
479*412f47f9SXin Li #define LOG_TABLE_BITS 7
480*412f47f9SXin Li #define LOG_POLY_ORDER 6
481*412f47f9SXin Li #define LOG_POLY1_ORDER 12
482*412f47f9SXin Li extern const struct log_data
483*412f47f9SXin Li {
484*412f47f9SXin Li   double ln2hi;
485*412f47f9SXin Li   double ln2lo;
486*412f47f9SXin Li   double poly[LOG_POLY_ORDER - 1]; /* First coefficient is 1.  */
487*412f47f9SXin Li   double poly1[LOG_POLY1_ORDER - 1];
488*412f47f9SXin Li   struct
489*412f47f9SXin Li   {
490*412f47f9SXin Li     double invc, logc;
491*412f47f9SXin Li   } tab[1 << LOG_TABLE_BITS];
492*412f47f9SXin Li #if !HAVE_FAST_FMA
493*412f47f9SXin Li   struct
494*412f47f9SXin Li   {
495*412f47f9SXin Li     double chi, clo;
496*412f47f9SXin Li   } tab2[1 << LOG_TABLE_BITS];
497*412f47f9SXin Li #endif
498*412f47f9SXin Li } __log_data HIDDEN;
499*412f47f9SXin Li 
500*412f47f9SXin Li #define ASINH_NCOEFFS 18
501*412f47f9SXin Li extern const struct asinh_data
502*412f47f9SXin Li {
503*412f47f9SXin Li   double poly[ASINH_NCOEFFS];
504*412f47f9SXin Li } __asinh_data HIDDEN;
505*412f47f9SXin Li 
506*412f47f9SXin Li #define LOG1P_NCOEFFS 19
507*412f47f9SXin Li extern const struct log1p_data
508*412f47f9SXin Li {
509*412f47f9SXin Li   double coeffs[LOG1P_NCOEFFS];
510*412f47f9SXin Li } __log1p_data HIDDEN;
511*412f47f9SXin Li 
512*412f47f9SXin Li #define LOG1PF_2U5
513*412f47f9SXin Li #define LOG1PF_NCOEFFS 9
514*412f47f9SXin Li extern const struct log1pf_data
515*412f47f9SXin Li {
516*412f47f9SXin Li   float coeffs[LOG1PF_NCOEFFS];
517*412f47f9SXin Li } __log1pf_data HIDDEN;
518*412f47f9SXin Li 
519*412f47f9SXin Li #define TANF_P_POLY_NCOEFFS 6
520*412f47f9SXin Li /* cotan approach needs order 3 on [0, pi/4] to reach <3.5ulps.  */
521*412f47f9SXin Li #define TANF_Q_POLY_NCOEFFS 4
522*412f47f9SXin Li extern const struct tanf_poly_data
523*412f47f9SXin Li {
524*412f47f9SXin Li   float poly_tan[TANF_P_POLY_NCOEFFS];
525*412f47f9SXin Li   float poly_cotan[TANF_Q_POLY_NCOEFFS];
526*412f47f9SXin Li } __tanf_poly_data HIDDEN;
527*412f47f9SXin Li 
528*412f47f9SXin Li #define V_LOG2_TABLE_BITS 7
529*412f47f9SXin Li extern const struct v_log2_data
530*412f47f9SXin Li {
531*412f47f9SXin Li   double poly[5];
532*412f47f9SXin Li   double invln2;
533*412f47f9SXin Li   struct
534*412f47f9SXin Li   {
535*412f47f9SXin Li     double invc, log2c;
536*412f47f9SXin Li   } table[1 << V_LOG2_TABLE_BITS];
537*412f47f9SXin Li } __v_log2_data HIDDEN;
538*412f47f9SXin Li 
539*412f47f9SXin Li #define V_LOG10_TABLE_BITS 7
540*412f47f9SXin Li extern const struct v_log10_data
541*412f47f9SXin Li {
542*412f47f9SXin Li   double poly[5];
543*412f47f9SXin Li   double invln10, log10_2;
544*412f47f9SXin Li   struct
545*412f47f9SXin Li   {
546*412f47f9SXin Li     double invc, log10c;
547*412f47f9SXin Li   } table[1 << V_LOG10_TABLE_BITS];
548*412f47f9SXin Li } __v_log10_data HIDDEN;
549*412f47f9SXin Li 
550*412f47f9SXin Li /* Some data for SVE powf's internal exp and log.  */
551*412f47f9SXin Li #define V_POWF_EXP2_TABLE_BITS 5
552*412f47f9SXin Li #define V_POWF_EXP2_N (1 << V_POWF_EXP2_TABLE_BITS)
553*412f47f9SXin Li #define V_POWF_LOG2_TABLE_BITS 5
554*412f47f9SXin Li #define V_POWF_LOG2_N (1 << V_POWF_LOG2_TABLE_BITS)
555*412f47f9SXin Li extern const struct v_powf_data
556*412f47f9SXin Li {
557*412f47f9SXin Li   double invc[V_POWF_LOG2_N];
558*412f47f9SXin Li   double logc[V_POWF_LOG2_N];
559*412f47f9SXin Li   uint64_t scale[V_POWF_EXP2_N];
560*412f47f9SXin Li } __v_powf_data HIDDEN;
561*412f47f9SXin Li 
562*412f47f9SXin Li #define V_LOG_POLY_ORDER 6
563*412f47f9SXin Li #define V_LOG_TABLE_BITS 7
564*412f47f9SXin Li extern const struct v_log_data
565*412f47f9SXin Li {
566*412f47f9SXin Li   /* Shared data for vector log and log-derived routines (e.g. asinh).  */
567*412f47f9SXin Li   double poly[V_LOG_POLY_ORDER - 1];
568*412f47f9SXin Li   double ln2;
569*412f47f9SXin Li   struct
570*412f47f9SXin Li   {
571*412f47f9SXin Li     double invc, logc;
572*412f47f9SXin Li   } table[1 << V_LOG_TABLE_BITS];
573*412f47f9SXin Li } __v_log_data HIDDEN;
574*412f47f9SXin Li 
575*412f47f9SXin Li #define EXPM1F_POLY_ORDER 5
576*412f47f9SXin Li extern const float __expm1f_poly[EXPM1F_POLY_ORDER] HIDDEN;
577*412f47f9SXin Li 
578*412f47f9SXin Li #define EXPF_TABLE_BITS 5
579*412f47f9SXin Li #define EXPF_POLY_ORDER 3
580*412f47f9SXin Li extern const struct expf_data
581*412f47f9SXin Li {
582*412f47f9SXin Li   uint64_t tab[1 << EXPF_TABLE_BITS];
583*412f47f9SXin Li   double invln2_scaled;
584*412f47f9SXin Li   double poly_scaled[EXPF_POLY_ORDER];
585*412f47f9SXin Li } __expf_data HIDDEN;
586*412f47f9SXin Li 
587*412f47f9SXin Li #define EXPM1_POLY_ORDER 11
588*412f47f9SXin Li extern const double __expm1_poly[EXPM1_POLY_ORDER] HIDDEN;
589*412f47f9SXin Li 
590*412f47f9SXin Li extern const struct cbrtf_data
591*412f47f9SXin Li {
592*412f47f9SXin Li   float poly[4];
593*412f47f9SXin Li   float table[5];
594*412f47f9SXin Li } __cbrtf_data HIDDEN;
595*412f47f9SXin Li 
596*412f47f9SXin Li extern const struct cbrt_data
597*412f47f9SXin Li {
598*412f47f9SXin Li   double poly[4];
599*412f47f9SXin Li   double table[5];
600*412f47f9SXin Li } __cbrt_data HIDDEN;
601*412f47f9SXin Li 
602*412f47f9SXin Li #define ASINF_POLY_ORDER 4
603*412f47f9SXin Li extern const float __asinf_poly[ASINF_POLY_ORDER + 1] HIDDEN;
604*412f47f9SXin Li 
605*412f47f9SXin Li #define ASIN_POLY_ORDER 11
606*412f47f9SXin Li extern const double __asin_poly[ASIN_POLY_ORDER + 1] HIDDEN;
607*412f47f9SXin Li 
608*412f47f9SXin Li /* Some data for AdvSIMD and SVE pow's internal exp and log.  */
609*412f47f9SXin Li #define V_POW_EXP_TABLE_BITS 8
610*412f47f9SXin Li extern const struct v_pow_exp_data
611*412f47f9SXin Li {
612*412f47f9SXin Li   double poly[3];
613*412f47f9SXin Li   double n_over_ln2, ln2_over_n_hi, ln2_over_n_lo, shift;
614*412f47f9SXin Li   uint64_t sbits[1 << V_POW_EXP_TABLE_BITS];
615*412f47f9SXin Li } __v_pow_exp_data HIDDEN;
616*412f47f9SXin Li 
617*412f47f9SXin Li #define V_POW_LOG_TABLE_BITS 7
618*412f47f9SXin Li extern const struct v_pow_log_data
619*412f47f9SXin Li {
620*412f47f9SXin Li   double poly[7]; /* First coefficient is 1.  */
621*412f47f9SXin Li   double ln2_hi, ln2_lo;
622*412f47f9SXin Li   double invc[1 << V_POW_LOG_TABLE_BITS];
623*412f47f9SXin Li   double logc[1 << V_POW_LOG_TABLE_BITS];
624*412f47f9SXin Li   double logctail[1 << V_POW_LOG_TABLE_BITS];
625*412f47f9SXin Li } __v_pow_log_data HIDDEN;
626*412f47f9SXin Li 
627*412f47f9SXin Li #endif
628