1 | //===-- Common constants for math functions ---------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H |
10 | #define LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H |
11 | |
12 | #include "src/__support/FPUtil/triple_double.h" |
13 | #include "src/__support/macros/config.h" |
14 | #include "src/__support/number_pair.h" |
15 | |
16 | namespace LIBC_NAMESPACE_DECL { |
17 | |
18 | // Lookup table for (1/f) where f = 1 + n*2^(-7), n = 0..127, |
19 | // computed and stored as float precision constants. |
20 | extern const float ONE_OVER_F_FLOAT[128]; |
21 | |
22 | // Lookup table for (1/f) where f = 1 + n*2^(-7), n = 0..127. |
23 | extern const double ONE_OVER_F[128]; |
24 | |
25 | // Lookup table for log(f) = log(1 + n*2^(-7)) where n = 0..127, |
26 | // computed and stored as float precision constants. |
27 | extern const float LOG_F_FLOAT[128]; |
28 | |
29 | // Lookup table for log(f) = log(1 + n*2^(-7)) where n = 0..127. |
30 | extern const double LOG_F[128]; |
31 | |
32 | // Lookup table for range reduction constants r for logarithms. |
33 | extern const float R[128]; |
34 | |
35 | // Lookup table for range reduction constants r for logarithms. |
36 | extern const double RD[128]; |
37 | |
38 | // Lookup table for compensated constants for exact range reduction when FMA |
39 | // instructions are not available. |
40 | extern const double CD[128]; |
41 | |
42 | // Lookup table for -log(r) |
43 | extern const double LOG_R[128]; |
44 | extern const NumberPair<double> LOG_R_DD[128]; |
45 | |
46 | // Lookup table for -log2(r) |
47 | extern const double LOG2_R[128]; |
48 | |
49 | // Minimax polynomial for (log(1 + x) - x)/x^2, generated by sollya with: |
50 | // > P = fpminimax((log(1 + x) - x)/x^2, 5, [|D...|], [-2^-8, 2^-7]); |
51 | constexpr double LOG_COEFFS[6] = {-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2, |
52 | -0x1.0000000094567p-2, 0x1.99999dcc9823cp-3, |
53 | -0x1.55550ac2e537ap-3, 0x1.21a02c4e624d7p-3}; |
54 | |
55 | // Logarithm Range Reduction - Step 2, 3, and 4. |
56 | extern const int S2[193]; |
57 | extern const int S3[161]; |
58 | extern const int S4[130]; |
59 | |
60 | extern const double R2[193]; |
61 | |
62 | // log(2) generated by Sollya with: |
63 | // > a = 2^-43 * nearestint(2^43*log(2)); |
64 | // LSB = 2^-43 is chosen so that e_x * LOG_2_HI is exact for -1075 < e_x < 1024. |
65 | constexpr double LOG_2_HI = 0x1.62e42fefa38p-1; // LSB = 2^-43 |
66 | // > b = round(log10(2) - a, D, RN); |
67 | constexpr double LOG_2_LO = 0x1.ef35793c7673p-45; // LSB = 2^-97 |
68 | |
69 | // Lookup table for exp(m) with m = -104, ..., 89. |
70 | // -104 = floor(log(single precision's min denormal)) |
71 | // 89 = ceil(log(single precision's max normal)) |
72 | // Table is generated with Sollya as follow: |
73 | // > display = hexadecimal; |
74 | // > for i from -104 to 89 do { D(exp(i)); }; |
75 | extern const double EXP_M1[195]; |
76 | |
77 | // Lookup table for exp(m * 2^(-7)) with m = 0, ..., 127. |
78 | // Table is generated with Sollya as follow: |
79 | // > display = hexadecimal; |
80 | // > for i from 0 to 127 do { D(exp(i / 128)); }; |
81 | extern const double EXP_M2[128]; |
82 | |
83 | // Lookup table for 2^(k * 2^-6) with k = 0..63. |
84 | extern const fputil::TripleDouble EXP2_MID1[64]; |
85 | |
86 | // Lookup table for 2^(k * 2^-12) with k = 0..63. |
87 | extern const fputil::TripleDouble EXP2_MID2[64]; |
88 | |
89 | } // namespace LIBC_NAMESPACE_DECL |
90 | |
91 | #endif // LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H |
92 | |