[RISCV][VLOPT] Add vector narrowing integer right shift instructions to isSupportedIn...
[llvm-project.git] / libc / src / math / generic / common_constants.h
blobdc1a90c1cb24a311ec18632052185b159971ea70
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H
10 #define LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H
12 #include "src/__support/FPUtil/triple_double.h"
13 #include "src/__support/macros/config.h"
14 #include "src/__support/number_pair.h"
16 namespace LIBC_NAMESPACE_DECL {
18 // Lookup table for (1/f) where f = 1 + n*2^(-7), n = 0..127.
19 extern const double ONE_OVER_F[128];
21 // Lookup table for log(f) = log(1 + n*2^(-7)) where n = 0..127.
22 extern const double LOG_F[128];
24 // Lookup table for range reduction constants r for logarithms.
25 extern const float R[128];
27 // Lookup table for range reduction constants r for logarithms.
28 extern const double RD[128];
30 // Lookup table for compensated constants for exact range reduction when FMA
31 // instructions are not available.
32 extern const double CD[128];
34 // Lookup table for -log(r)
35 extern const double LOG_R[128];
36 extern const NumberPair<double> LOG_R_DD[128];
38 // Lookup table for -log2(r)
39 extern const double LOG2_R[128];
41 // Minimax polynomial for (log(1 + x) - x)/x^2, generated by sollya with:
42 // > P = fpminimax((log(1 + x) - x)/x^2, 5, [|D...|], [-2^-8, 2^-7]);
43 constexpr double LOG_COEFFS[6] = {-0x1.fffffffffffffp-2, 0x1.5555555554a9bp-2,
44 -0x1.0000000094567p-2, 0x1.99999dcc9823cp-3,
45 -0x1.55550ac2e537ap-3, 0x1.21a02c4e624d7p-3};
47 // Logarithm Range Reduction - Step 2, 3, and 4.
48 extern const int S2[193];
49 extern const int S3[161];
50 extern const int S4[130];
52 extern const double R2[193];
54 // log(2) generated by Sollya with:
55 // > a = 2^-43 * nearestint(2^43*log(2));
56 // LSB = 2^-43 is chosen so that e_x * LOG_2_HI is exact for -1075 < e_x < 1024.
57 constexpr double LOG_2_HI = 0x1.62e42fefa38p-1; // LSB = 2^-43
58 // > b = round(log10(2) - a, D, RN);
59 constexpr double LOG_2_LO = 0x1.ef35793c7673p-45; // LSB = 2^-97
61 // Lookup table for exp(m) with m = -104, ..., 89.
62 // -104 = floor(log(single precision's min denormal))
63 // 89 = ceil(log(single precision's max normal))
64 // Table is generated with Sollya as follow:
65 // > display = hexadecimal;
66 // > for i from -104 to 89 do { D(exp(i)); };
67 extern const double EXP_M1[195];
69 // Lookup table for exp(m * 2^(-7)) with m = 0, ..., 127.
70 // Table is generated with Sollya as follow:
71 // > display = hexadecimal;
72 // > for i from 0 to 127 do { D(exp(i / 128)); };
73 extern const double EXP_M2[128];
75 // Lookup table for 2^(k * 2^-6) with k = 0..63.
76 extern const fputil::TripleDouble EXP2_MID1[64];
78 // Lookup table for 2^(k * 2^-12) with k = 0..63.
79 extern const fputil::TripleDouble EXP2_MID2[64];
81 } // namespace LIBC_NAMESPACE_DECL
83 #endif // LLVM_LIBC_SRC_MATH_GENERIC_COMMON_CONSTANTS_H