Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 1 | /* |
Szabolcs Nagy | 1b94597 | 2018-05-14 14:46:40 +0100 | [diff] [blame] | 2 | * Configuration for math routines. |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 3 | * |
Szabolcs Nagy | 11253b0 | 2018-11-12 11:10:57 +0000 | [diff] [blame] | 4 | * Copyright (c) 2017-2018, Arm Limited. |
| 5 | * SPDX-License-Identifier: MIT |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _MATH_CONFIG_H |
| 9 | #define _MATH_CONFIG_H |
| 10 | |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 11 | #include <math.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | #ifndef WANT_ROUNDING |
Wilco Dijkstra | 6f41cff | 2020-02-27 16:25:40 +0000 | [diff] [blame] | 15 | /* If defined to 1, return correct results for special cases in non-nearest |
| 16 | rounding modes (logf (1.0f) returns 0.0f with FE_DOWNWARD rather than -0.0f). |
| 17 | This may be set to 0 if there is no fenv support or if math functions only |
| 18 | get called in round to nearest mode. */ |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 19 | # define WANT_ROUNDING 1 |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 20 | #endif |
| 21 | #ifndef WANT_ERRNO |
Wilco Dijkstra | 6f41cff | 2020-02-27 16:25:40 +0000 | [diff] [blame] | 22 | /* If defined to 1, set errno in math functions according to ISO C. Many math |
| 23 | libraries do not set errno, so this is 0 by default. It may need to be |
| 24 | set to 1 if math.h has (math_errhandling & MATH_ERRNO) != 0. */ |
| 25 | # define WANT_ERRNO 0 |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 26 | #endif |
| 27 | #ifndef WANT_ERRNO_UFLOW |
| 28 | /* Set errno to ERANGE if result underflows to 0 (in all rounding modes). */ |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 29 | # define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO) |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 30 | #endif |
| 31 | |
Szabolcs Nagy | 39b0191 | 2018-05-10 15:35:06 +0100 | [diff] [blame] | 32 | /* Compiler can inline round as a single instruction. */ |
| 33 | #ifndef HAVE_FAST_ROUND |
| 34 | # if __aarch64__ |
| 35 | # define HAVE_FAST_ROUND 1 |
| 36 | # else |
| 37 | # define HAVE_FAST_ROUND 0 |
| 38 | # endif |
| 39 | #endif |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 40 | |
Szabolcs Nagy | 39b0191 | 2018-05-10 15:35:06 +0100 | [diff] [blame] | 41 | /* Compiler can inline lround, but not (long)round(x). */ |
| 42 | #ifndef HAVE_FAST_LROUND |
| 43 | # if __aarch64__ && (100*__GNUC__ + __GNUC_MINOR__) >= 408 && __NO_MATH_ERRNO__ |
| 44 | # define HAVE_FAST_LROUND 1 |
| 45 | # else |
| 46 | # define HAVE_FAST_LROUND 0 |
| 47 | # endif |
| 48 | #endif |
| 49 | |
Szabolcs Nagy | 56091b7 | 2018-05-31 18:13:20 +0100 | [diff] [blame] | 50 | /* Compiler can inline fma as a single instruction. */ |
| 51 | #ifndef HAVE_FAST_FMA |
Wilco Dijkstra | 5175759 | 2018-08-17 16:51:32 +0100 | [diff] [blame] | 52 | # if defined FP_FAST_FMA || __aarch64__ |
Szabolcs Nagy | 56091b7 | 2018-05-31 18:13:20 +0100 | [diff] [blame] | 53 | # define HAVE_FAST_FMA 1 |
| 54 | # else |
| 55 | # define HAVE_FAST_FMA 0 |
| 56 | # endif |
| 57 | #endif |
| 58 | |
Szabolcs Nagy | 9e6e14e | 2019-11-06 18:01:15 +0000 | [diff] [blame] | 59 | /* Provide *_finite symbols and some of the glibc hidden symbols |
| 60 | so libmathlib can be used with binaries compiled against glibc |
| 61 | to interpose math functions with both static and dynamic linking. */ |
| 62 | #ifndef USE_GLIBC_ABI |
| 63 | # if __GNUC__ |
| 64 | # define USE_GLIBC_ABI 1 |
| 65 | # else |
| 66 | # define USE_GLIBC_ABI 0 |
| 67 | # endif |
| 68 | #endif |
| 69 | |
| 70 | /* Optionally used extensions. */ |
| 71 | #ifdef __GNUC__ |
| 72 | # define HIDDEN __attribute__ ((__visibility__ ("hidden"))) |
| 73 | # define NOINLINE __attribute__ ((noinline)) |
Szabolcs Nagy | 17cd8af | 2019-11-06 18:10:17 +0000 | [diff] [blame] | 74 | # define UNUSED __attribute__ ((unused)) |
Szabolcs Nagy | 9e6e14e | 2019-11-06 18:01:15 +0000 | [diff] [blame] | 75 | # define likely(x) __builtin_expect (!!(x), 1) |
| 76 | # define unlikely(x) __builtin_expect (x, 0) |
Szabolcs Nagy | 2c6c240 | 2019-11-06 18:14:23 +0000 | [diff] [blame] | 77 | # if __GNUC__ >= 9 |
| 78 | # define attribute_copy(f) __attribute__ ((copy (f))) |
| 79 | # else |
| 80 | # define attribute_copy(f) |
| 81 | # endif |
Szabolcs Nagy | 9e6e14e | 2019-11-06 18:01:15 +0000 | [diff] [blame] | 82 | # define strong_alias(f, a) \ |
Szabolcs Nagy | 2c6c240 | 2019-11-06 18:14:23 +0000 | [diff] [blame] | 83 | extern __typeof (f) a __attribute__ ((alias (#f))) attribute_copy (f); |
Szabolcs Nagy | 9e6e14e | 2019-11-06 18:01:15 +0000 | [diff] [blame] | 84 | # define hidden_alias(f, a) \ |
Szabolcs Nagy | 2c6c240 | 2019-11-06 18:14:23 +0000 | [diff] [blame] | 85 | extern __typeof (f) a __attribute__ ((alias (#f), visibility ("hidden"))) \ |
| 86 | attribute_copy (f); |
Szabolcs Nagy | 9e6e14e | 2019-11-06 18:01:15 +0000 | [diff] [blame] | 87 | #else |
| 88 | # define HIDDEN |
| 89 | # define NOINLINE |
Szabolcs Nagy | 17cd8af | 2019-11-06 18:10:17 +0000 | [diff] [blame] | 90 | # define UNUSED |
Szabolcs Nagy | 9e6e14e | 2019-11-06 18:01:15 +0000 | [diff] [blame] | 91 | # define likely(x) (x) |
| 92 | # define unlikely(x) (x) |
| 93 | #endif |
| 94 | |
Szabolcs Nagy | 39b0191 | 2018-05-10 15:35:06 +0100 | [diff] [blame] | 95 | #if HAVE_FAST_ROUND |
Szabolcs Nagy | dd178df | 2018-07-04 09:54:29 +0100 | [diff] [blame] | 96 | /* When set, the roundtoint and converttoint functions are provided with |
| 97 | the semantics documented below. */ |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 98 | # define TOINT_INTRINSICS 1 |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 99 | |
Szabolcs Nagy | dd178df | 2018-07-04 09:54:29 +0100 | [diff] [blame] | 100 | /* Round x to nearest int in all rounding modes, ties have to be rounded |
| 101 | consistently with converttoint so the results match. If the result |
| 102 | would be outside of [-2^31, 2^31-1] then the semantics is unspecified. */ |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 103 | static inline double_t |
| 104 | roundtoint (double_t x) |
| 105 | { |
Szabolcs Nagy | 39b0191 | 2018-05-10 15:35:06 +0100 | [diff] [blame] | 106 | return round (x); |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Szabolcs Nagy | dd178df | 2018-07-04 09:54:29 +0100 | [diff] [blame] | 109 | /* Convert x to nearest int in all rounding modes, ties have to be rounded |
| 110 | consistently with roundtoint. If the result is not representible in an |
| 111 | int32_t then the semantics is unspecified. */ |
| 112 | static inline int32_t |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 113 | converttoint (double_t x) |
| 114 | { |
Szabolcs Nagy | 39b0191 | 2018-05-10 15:35:06 +0100 | [diff] [blame] | 115 | # if HAVE_FAST_LROUND |
| 116 | return lround (x); |
| 117 | # else |
| 118 | return (long) round (x); |
| 119 | # endif |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 120 | } |
| 121 | #endif |
| 122 | |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 123 | static inline uint32_t |
| 124 | asuint (float f) |
| 125 | { |
| 126 | union |
| 127 | { |
| 128 | float f; |
| 129 | uint32_t i; |
| 130 | } u = {f}; |
| 131 | return u.i; |
| 132 | } |
| 133 | |
| 134 | static inline float |
| 135 | asfloat (uint32_t i) |
| 136 | { |
| 137 | union |
| 138 | { |
| 139 | uint32_t i; |
| 140 | float f; |
| 141 | } u = {i}; |
| 142 | return u.f; |
| 143 | } |
| 144 | |
| 145 | static inline uint64_t |
| 146 | asuint64 (double f) |
| 147 | { |
| 148 | union |
| 149 | { |
| 150 | double f; |
| 151 | uint64_t i; |
| 152 | } u = {f}; |
| 153 | return u.i; |
| 154 | } |
| 155 | |
| 156 | static inline double |
| 157 | asdouble (uint64_t i) |
| 158 | { |
| 159 | union |
| 160 | { |
| 161 | uint64_t i; |
| 162 | double f; |
| 163 | } u = {i}; |
| 164 | return u.f; |
| 165 | } |
| 166 | |
Szabolcs Nagy | 6f846e1 | 2017-09-28 15:45:41 +0100 | [diff] [blame] | 167 | #ifndef IEEE_754_2008_SNAN |
| 168 | # define IEEE_754_2008_SNAN 1 |
| 169 | #endif |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 170 | static inline int |
Szabolcs Nagy | 6f846e1 | 2017-09-28 15:45:41 +0100 | [diff] [blame] | 171 | issignalingf_inline (float x) |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 172 | { |
| 173 | uint32_t ix = asuint (x); |
Szabolcs Nagy | 6f846e1 | 2017-09-28 15:45:41 +0100 | [diff] [blame] | 174 | if (!IEEE_754_2008_SNAN) |
| 175 | return (ix & 0x7fc00000) == 0x7fc00000; |
| 176 | return 2 * (ix ^ 0x00400000) > 2u * 0x7fc00000; |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Szabolcs Nagy | ed0ecff | 2018-06-06 18:17:16 +0100 | [diff] [blame] | 179 | static inline int |
| 180 | issignaling_inline (double x) |
| 181 | { |
| 182 | uint64_t ix = asuint64 (x); |
| 183 | if (!IEEE_754_2008_SNAN) |
| 184 | return (ix & 0x7ff8000000000000) == 0x7ff8000000000000; |
| 185 | return 2 * (ix ^ 0x0008000000000000) > 2 * 0x7ff8000000000000ULL; |
| 186 | } |
| 187 | |
Szabolcs Nagy | 5eb9d19 | 2018-05-11 13:20:04 +0100 | [diff] [blame] | 188 | #if __aarch64__ && __GNUC__ |
Szabolcs Nagy | 5fa69e1 | 2018-06-12 17:18:24 +0100 | [diff] [blame] | 189 | /* Prevent the optimization of a floating-point expression. */ |
| 190 | static inline float |
| 191 | opt_barrier_float (float x) |
| 192 | { |
| 193 | __asm__ __volatile__ ("" : "+w" (x)); |
| 194 | return x; |
| 195 | } |
| 196 | static inline double |
| 197 | opt_barrier_double (double x) |
| 198 | { |
| 199 | __asm__ __volatile__ ("" : "+w" (x)); |
| 200 | return x; |
| 201 | } |
| 202 | /* Force the evaluation of a floating-point expression for its side-effect. */ |
Szabolcs Nagy | 5eb9d19 | 2018-05-11 13:20:04 +0100 | [diff] [blame] | 203 | static inline void |
| 204 | force_eval_float (float x) |
| 205 | { |
| 206 | __asm__ __volatile__ ("" : "+w" (x)); |
| 207 | } |
| 208 | static inline void |
| 209 | force_eval_double (double x) |
| 210 | { |
| 211 | __asm__ __volatile__ ("" : "+w" (x)); |
| 212 | } |
| 213 | #else |
Szabolcs Nagy | f671740 | 2018-06-14 17:22:11 +0100 | [diff] [blame] | 214 | static inline float |
Szabolcs Nagy | 5fa69e1 | 2018-06-12 17:18:24 +0100 | [diff] [blame] | 215 | opt_barrier_float (float x) |
| 216 | { |
| 217 | volatile float y = x; |
| 218 | return y; |
| 219 | } |
Szabolcs Nagy | f671740 | 2018-06-14 17:22:11 +0100 | [diff] [blame] | 220 | static inline double |
Szabolcs Nagy | 5fa69e1 | 2018-06-12 17:18:24 +0100 | [diff] [blame] | 221 | opt_barrier_double (double x) |
| 222 | { |
| 223 | volatile double y = x; |
| 224 | return y; |
| 225 | } |
| 226 | static inline void |
Szabolcs Nagy | 5eb9d19 | 2018-05-11 13:20:04 +0100 | [diff] [blame] | 227 | force_eval_float (float x) |
| 228 | { |
Szabolcs Nagy | 17cd8af | 2019-11-06 18:10:17 +0000 | [diff] [blame] | 229 | volatile float y UNUSED = x; |
Szabolcs Nagy | 5eb9d19 | 2018-05-11 13:20:04 +0100 | [diff] [blame] | 230 | } |
| 231 | static inline void |
| 232 | force_eval_double (double x) |
| 233 | { |
Szabolcs Nagy | 17cd8af | 2019-11-06 18:10:17 +0000 | [diff] [blame] | 234 | volatile double y UNUSED = x; |
Szabolcs Nagy | 5eb9d19 | 2018-05-11 13:20:04 +0100 | [diff] [blame] | 235 | } |
| 236 | #endif |
| 237 | |
| 238 | /* Evaluate an expression as the specified type, normally a type |
| 239 | cast should be enough, but compilers implement non-standard |
| 240 | excess-precision handling, so when FLT_EVAL_METHOD != 0 then |
| 241 | these functions may need to be customized. */ |
| 242 | static inline float |
| 243 | eval_as_float (float x) |
| 244 | { |
| 245 | return x; |
| 246 | } |
| 247 | static inline double |
| 248 | eval_as_double (double x) |
| 249 | { |
| 250 | return x; |
| 251 | } |
| 252 | |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 253 | /* Error handling tail calls for special cases, with a sign argument. |
| 254 | The sign of the return value is set if the argument is non-zero. */ |
| 255 | |
| 256 | /* The result overflows. */ |
Szabolcs Nagy | c65db17 | 2018-05-10 17:53:31 +0100 | [diff] [blame] | 257 | HIDDEN float __math_oflowf (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 258 | /* The result underflows to 0 in nearest rounding mode. */ |
Szabolcs Nagy | c65db17 | 2018-05-10 17:53:31 +0100 | [diff] [blame] | 259 | HIDDEN float __math_uflowf (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 260 | /* The result underflows to 0 in some directed rounding mode only. */ |
Szabolcs Nagy | c65db17 | 2018-05-10 17:53:31 +0100 | [diff] [blame] | 261 | HIDDEN float __math_may_uflowf (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 262 | /* Division by zero. */ |
Szabolcs Nagy | c65db17 | 2018-05-10 17:53:31 +0100 | [diff] [blame] | 263 | HIDDEN float __math_divzerof (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 264 | /* The result overflows. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 265 | HIDDEN double __math_oflow (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 266 | /* The result underflows to 0 in nearest rounding mode. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 267 | HIDDEN double __math_uflow (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 268 | /* The result underflows to 0 in some directed rounding mode only. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 269 | HIDDEN double __math_may_uflow (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 270 | /* Division by zero. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 271 | HIDDEN double __math_divzero (uint32_t); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 272 | |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 273 | /* Error handling using input checking. */ |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 274 | |
| 275 | /* Invalid input unless it is a quiet NaN. */ |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 276 | HIDDEN float __math_invalidf (float); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 277 | /* Invalid input unless it is a quiet NaN. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 278 | HIDDEN double __math_invalid (double); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 279 | |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 280 | /* Error handling using output checking, only for errno setting. */ |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 281 | |
| 282 | /* Check if the result overflowed to infinity. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 283 | HIDDEN double __math_check_oflow (double); |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 284 | /* Check if the result underflowed to 0. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 285 | HIDDEN double __math_check_uflow (double); |
| 286 | |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 287 | /* Check if the result overflowed to infinity. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 288 | static inline double |
| 289 | check_oflow (double x) |
| 290 | { |
| 291 | return WANT_ERRNO ? __math_check_oflow (x) : x; |
| 292 | } |
| 293 | |
Szabolcs Nagy | 58ce45c | 2018-06-29 11:06:13 +0100 | [diff] [blame] | 294 | /* Check if the result underflowed to 0. */ |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 295 | static inline double |
| 296 | check_uflow (double x) |
| 297 | { |
| 298 | return WANT_ERRNO ? __math_check_uflow (x) : x; |
| 299 | } |
| 300 | |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 301 | |
| 302 | /* Shared between expf, exp2f and powf. */ |
| 303 | #define EXP2F_TABLE_BITS 5 |
| 304 | #define EXP2F_POLY_ORDER 3 |
| 305 | extern const struct exp2f_data |
| 306 | { |
| 307 | uint64_t tab[1 << EXP2F_TABLE_BITS]; |
| 308 | double shift_scaled; |
| 309 | double poly[EXP2F_POLY_ORDER]; |
| 310 | double shift; |
| 311 | double invln2_scaled; |
| 312 | double poly_scaled[EXP2F_POLY_ORDER]; |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 313 | } __exp2f_data HIDDEN; |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 314 | |
| 315 | #define LOGF_TABLE_BITS 4 |
| 316 | #define LOGF_POLY_ORDER 4 |
| 317 | extern const struct logf_data |
| 318 | { |
| 319 | struct |
| 320 | { |
| 321 | double invc, logc; |
| 322 | } tab[1 << LOGF_TABLE_BITS]; |
| 323 | double ln2; |
Szabolcs Nagy | e353e49 | 2017-09-28 16:12:20 +0100 | [diff] [blame] | 324 | double poly[LOGF_POLY_ORDER - 1]; /* First order coefficient is 1. */ |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 325 | } __logf_data HIDDEN; |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 326 | |
| 327 | #define LOG2F_TABLE_BITS 4 |
| 328 | #define LOG2F_POLY_ORDER 4 |
| 329 | extern const struct log2f_data |
| 330 | { |
| 331 | struct |
| 332 | { |
| 333 | double invc, logc; |
| 334 | } tab[1 << LOG2F_TABLE_BITS]; |
| 335 | double poly[LOG2F_POLY_ORDER]; |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 336 | } __log2f_data HIDDEN; |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 337 | |
| 338 | #define POWF_LOG2_TABLE_BITS 4 |
| 339 | #define POWF_LOG2_POLY_ORDER 5 |
| 340 | #if TOINT_INTRINSICS |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 341 | # define POWF_SCALE_BITS EXP2F_TABLE_BITS |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 342 | #else |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 343 | # define POWF_SCALE_BITS 0 |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 344 | #endif |
| 345 | #define POWF_SCALE ((double) (1 << POWF_SCALE_BITS)) |
| 346 | extern const struct powf_log2_data |
| 347 | { |
| 348 | struct |
| 349 | { |
| 350 | double invc, logc; |
| 351 | } tab[1 << POWF_LOG2_TABLE_BITS]; |
| 352 | double poly[POWF_LOG2_POLY_ORDER]; |
Szabolcs Nagy | 97599cd | 2017-09-28 15:41:06 +0100 | [diff] [blame] | 353 | } __powf_log2_data HIDDEN; |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 354 | |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 355 | |
| 356 | #define EXP_TABLE_BITS 7 |
| 357 | #define EXP_POLY_ORDER 5 |
| 358 | /* Use polynomial that is optimized for a wider input range. This may be |
| 359 | needed for good precision in non-nearest rounding and !TOINT_INTRINSICS. */ |
| 360 | #define EXP_POLY_WIDE 0 |
| 361 | /* Use close to nearest rounding toint when !TOINT_INTRINSICS. This may be |
| 362 | needed for good precision in non-nearest rouning and !EXP_POLY_WIDE. */ |
| 363 | #define EXP_USE_TOINT_NARROW 0 |
| 364 | #define EXP2_POLY_ORDER 5 |
| 365 | #define EXP2_POLY_WIDE 0 |
Szabolcs Nagy | 5e83891 | 2018-06-29 09:56:54 +0100 | [diff] [blame] | 366 | extern const struct exp_data |
| 367 | { |
Szabolcs Nagy | 872aa77 | 2018-04-27 16:17:24 +0100 | [diff] [blame] | 368 | double invln2N; |
| 369 | double shift; |
| 370 | double negln2hiN; |
| 371 | double negln2loN; |
| 372 | double poly[4]; /* Last four coefficients. */ |
| 373 | double exp2_shift; |
| 374 | double exp2_poly[EXP2_POLY_ORDER]; |
| 375 | uint64_t tab[2*(1 << EXP_TABLE_BITS)]; |
| 376 | } __exp_data HIDDEN; |
| 377 | |
Szabolcs Nagy | 56091b7 | 2018-05-31 18:13:20 +0100 | [diff] [blame] | 378 | #define LOG_TABLE_BITS 7 |
| 379 | #define LOG_POLY_ORDER 6 |
| 380 | #define LOG_POLY1_ORDER 12 |
Szabolcs Nagy | 5e83891 | 2018-06-29 09:56:54 +0100 | [diff] [blame] | 381 | extern const struct log_data |
| 382 | { |
Szabolcs Nagy | 56091b7 | 2018-05-31 18:13:20 +0100 | [diff] [blame] | 383 | double ln2hi; |
| 384 | double ln2lo; |
| 385 | double poly[LOG_POLY_ORDER - 1]; /* First coefficient is 1. */ |
| 386 | double poly1[LOG_POLY1_ORDER - 1]; |
| 387 | struct {double invc, logc;} tab[1 << LOG_TABLE_BITS]; |
| 388 | #if !HAVE_FAST_FMA |
| 389 | struct {double chi, clo;} tab2[1 << LOG_TABLE_BITS]; |
| 390 | #endif |
| 391 | } __log_data HIDDEN; |
| 392 | |
Szabolcs Nagy | d69e504 | 2018-06-05 16:15:27 +0100 | [diff] [blame] | 393 | #define LOG2_TABLE_BITS 6 |
| 394 | #define LOG2_POLY_ORDER 7 |
| 395 | #define LOG2_POLY1_ORDER 11 |
Szabolcs Nagy | 5e83891 | 2018-06-29 09:56:54 +0100 | [diff] [blame] | 396 | extern const struct log2_data |
| 397 | { |
Szabolcs Nagy | d69e504 | 2018-06-05 16:15:27 +0100 | [diff] [blame] | 398 | double invln2hi; |
| 399 | double invln2lo; |
| 400 | double poly[LOG2_POLY_ORDER - 1]; |
| 401 | double poly1[LOG2_POLY1_ORDER - 1]; |
| 402 | struct {double invc, logc;} tab[1 << LOG2_TABLE_BITS]; |
| 403 | #if !HAVE_FAST_FMA |
| 404 | struct {double chi, clo;} tab2[1 << LOG2_TABLE_BITS]; |
| 405 | #endif |
| 406 | } __log2_data HIDDEN; |
| 407 | |
Szabolcs Nagy | a623032 | 2018-06-21 17:53:15 +0100 | [diff] [blame] | 408 | #define POW_LOG_TABLE_BITS 7 |
| 409 | #define POW_LOG_POLY_ORDER 8 |
Szabolcs Nagy | 5e83891 | 2018-06-29 09:56:54 +0100 | [diff] [blame] | 410 | extern const struct pow_log_data |
| 411 | { |
Szabolcs Nagy | ed0ecff | 2018-06-06 18:17:16 +0100 | [diff] [blame] | 412 | double ln2hi; |
| 413 | double ln2lo; |
| 414 | double poly[POW_LOG_POLY_ORDER - 1]; /* First coefficient is 1. */ |
Szabolcs Nagy | a623032 | 2018-06-21 17:53:15 +0100 | [diff] [blame] | 415 | /* Note: the pad field is unused, but allows slightly faster indexing. */ |
| 416 | struct {double invc, pad, logc, logctail;} tab[1 << POW_LOG_TABLE_BITS]; |
Szabolcs Nagy | ed0ecff | 2018-06-06 18:17:16 +0100 | [diff] [blame] | 417 | } __pow_log_data HIDDEN; |
| 418 | |
Szabolcs Nagy | 86067a7 | 2017-08-11 15:35:12 +0100 | [diff] [blame] | 419 | #endif |