Skip to content

Commit 4065510

Browse files
authored
[libc][math] inline functions in shared math headers (#150703)
Part of #147386
1 parent eed9b4e commit 4065510

23 files changed

+41
-37
lines changed

libc/src/__support/math/acos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace LIBC_NAMESPACE_DECL {
2424

2525
namespace math {
2626

27-
static constexpr double acos(double x) {
27+
LIBC_INLINE static constexpr double acos(double x) {
2828
using DoubleDouble = fputil::DoubleDouble;
2929
using namespace asin_internal;
3030
using FPBits = fputil::FPBits<double>;

libc/src/__support/math/acosf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static constexpr fputil::ExceptValues<float, N_EXCEPTS> ACOSF_EXCEPTS = {{
4545

4646
} // namespace acosf_internal
4747

48-
static constexpr float acosf(float x) {
48+
LIBC_INLINE static constexpr float acosf(float x) {
4949
using namespace acosf_internal;
5050
using namespace inv_trigf_utils_internal;
5151
using FPBits = typename fputil::FPBits<float>;

libc/src/__support/math/acosf16.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace LIBC_NAMESPACE_DECL {
2626

2727
namespace math {
2828

29-
static constexpr float16 acosf16(float16 x) {
29+
LIBC_INLINE static constexpr float16 acosf16(float16 x) {
3030

3131
// Generated by Sollya using the following command:
3232
// > round(pi/2, SG, RN);

libc/src/__support/math/acoshf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace LIBC_NAMESPACE_DECL {
2121

2222
namespace math {
2323

24-
static constexpr float acoshf(float x) {
24+
LIBC_INLINE static constexpr float acoshf(float x) {
2525
using namespace acoshf_internal;
2626
using FPBits_t = typename fputil::FPBits<float>;
2727
FPBits_t xbits(x);

libc/src/__support/math/acoshf16.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LIBC_NAMESPACE_DECL {
2828

2929
namespace math {
3030

31-
static constexpr float16 acoshf16(float16 x) {
31+
LIBC_INLINE static constexpr float16 acoshf16(float16 x) {
3232

3333
using namespace acoshf_internal;
3434
constexpr size_t N_EXCEPTS = 2;

libc/src/__support/math/acospif16.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
2525

2626
namespace math {
2727

28-
static constexpr float16 acospif16(float16 x) {
28+
LIBC_INLINE static constexpr float16 acospif16(float16 x) {
2929
using FPBits = fputil::FPBits<float16>;
3030
FPBits xbits(x);
3131

libc/src/__support/math/asin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
2525

2626
namespace math {
2727

28-
static constexpr double asin(double x) {
28+
LIBC_INLINE static constexpr double asin(double x) {
2929
using namespace asin_internal;
3030
using FPBits = fputil::FPBits<double>;
3131

libc/src/__support/math/erff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace LIBC_NAMESPACE_DECL {
1919

2020
namespace math {
2121

22-
static constexpr float erff(float x) {
22+
LIBC_INLINE static constexpr float erff(float x) {
2323

2424
// Polynomials approximating erf(x)/x on ( k/8, (k + 1)/8 ) generated by
2525
// Sollya with: > P = fpminimax(erf(x)/x, [|0, 2, 4, 6, 8, 10, 12, 14|],

libc/src/__support/math/exp.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace {
6767
// Return expm1(dx) / x ~ 1 + dx / 2 + dx^2 / 6 + dx^3 / 24.
6868
// For |dx| < 2^-13 + 2^-30:
6969
// | output - expm1(dx) / dx | < 2^-51.
70-
static double poly_approx_d(double dx) {
70+
LIBC_INLINE static double poly_approx_d(double dx) {
7171
// dx^2
7272
double dx2 = dx * dx;
7373
// c0 = 1 + dx / 2
@@ -85,7 +85,7 @@ static double poly_approx_d(double dx) {
8585
// Return exp(dx) ~ 1 + dx + dx^2 / 2 + ... + dx^6 / 720
8686
// For |dx| < 2^-13 + 2^-30:
8787
// | output - exp(dx) | < 2^-101
88-
static DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
88+
LIBC_INLINE static DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
8989
// Taylor polynomial.
9090
constexpr DoubleDouble COEFFS[] = {
9191
{0, 0x1p0}, // 1
@@ -106,7 +106,7 @@ static DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
106106
// Return exp(dx) ~ 1 + dx + dx^2 / 2 + ... + dx^7 / 5040
107107
// For |dx| < 2^-13 + 2^-30:
108108
// | output - exp(dx) | < 2^-126.
109-
static Float128 poly_approx_f128(const Float128 &dx) {
109+
LIBC_INLINE static Float128 poly_approx_f128(const Float128 &dx) {
110110
constexpr Float128 COEFFS_128[]{
111111
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
112112
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
@@ -127,7 +127,7 @@ static Float128 poly_approx_f128(const Float128 &dx) {
127127
// Compute exp(x) using 128-bit precision.
128128
// TODO(lntue): investigate triple-double precision implementation for this
129129
// step.
130-
static Float128 exp_f128(double x, double kd, int idx1, int idx2) {
130+
LIBC_INLINE static Float128 exp_f128(double x, double kd, int idx1, int idx2) {
131131
// Recalculate dx:
132132

133133
double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
@@ -160,8 +160,8 @@ static Float128 exp_f128(double x, double kd, int idx1, int idx2) {
160160
}
161161

162162
// Compute exp(x) with double-double precision.
163-
static DoubleDouble exp_double_double(double x, double kd,
164-
const DoubleDouble &exp_mid) {
163+
LIBC_INLINE static DoubleDouble exp_double_double(double x, double kd,
164+
const DoubleDouble &exp_mid) {
165165
// Recalculate dx:
166166
// dx = x - k * 2^-12 * log(2)
167167
double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
@@ -184,7 +184,7 @@ static DoubleDouble exp_double_double(double x, double kd,
184184

185185
// Check for exceptional cases when
186186
// |x| <= 2^-53 or x < log(2^-1075) or x >= 0x1.6232bdd7abcd3p+9
187-
static double set_exceptional(double x) {
187+
LIBC_INLINE static double set_exceptional(double x) {
188188
using FPBits = typename fputil::FPBits<double>;
189189
FPBits xbits(x);
190190

libc/src/__support/math/exp10.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ LIBC_INLINE static double exp10_poly_approx_d(double dx) {
8383
// > P = fpminimax((10^x - 1)/x, 5, [|DD...|], [-2^-14, 2^-14]);
8484
// Error bounds:
8585
// | output - 10^(dx) | < 2^-101
86-
static constexpr DoubleDouble exp10_poly_approx_dd(const DoubleDouble &dx) {
86+
LIBC_INLINE static constexpr DoubleDouble
87+
exp10_poly_approx_dd(const DoubleDouble &dx) {
8788
// Taylor polynomial.
8889
constexpr DoubleDouble COEFFS[] = {
8990
{0, 0x1p0},
@@ -105,7 +106,8 @@ static constexpr DoubleDouble exp10_poly_approx_dd(const DoubleDouble &dx) {
105106
// Return exp(dx) ~ 1 + a0 * dx + a1 * dx^2 + ... + a6 * dx^7
106107
// For |dx| < 2^-14:
107108
// | output - 10^dx | < 1.5 * 2^-124.
108-
static constexpr Float128 exp10_poly_approx_f128(const Float128 &dx) {
109+
LIBC_INLINE static constexpr Float128
110+
exp10_poly_approx_f128(const Float128 &dx) {
109111
constexpr Float128 COEFFS_128[]{
110112
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
111113
{Sign::POS, -126, 0x935d8ddd'aaa8ac16'ea56d62b'82d30a2d_u128},
@@ -126,7 +128,8 @@ static constexpr Float128 exp10_poly_approx_f128(const Float128 &dx) {
126128
// Compute 10^(x) using 128-bit precision.
127129
// TODO(lntue): investigate triple-double precision implementation for this
128130
// step.
129-
static Float128 exp10_f128(double x, double kd, int idx1, int idx2) {
131+
LIBC_INLINE static Float128 exp10_f128(double x, double kd, int idx1,
132+
int idx2) {
130133
double t1 = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_HI, x); // exact
131134
double t2 = kd * MLOG10_2_EXP2_M12_MID_32; // exact
132135
double t3 = kd * MLOG10_2_EXP2_M12_LO; // Error < 2^-144
@@ -157,8 +160,8 @@ static Float128 exp10_f128(double x, double kd, int idx1, int idx2) {
157160
}
158161

159162
// Compute 10^x with double-double precision.
160-
static DoubleDouble exp10_double_double(double x, double kd,
161-
const DoubleDouble &exp_mid) {
163+
LIBC_INLINE static DoubleDouble
164+
exp10_double_double(double x, double kd, const DoubleDouble &exp_mid) {
162165
// Recalculate dx:
163166
// dx = x - k * 2^-12 * log10(2)
164167
double t1 = fputil::multiply_add(kd, MLOG10_2_EXP2_M12_HI, x); // exact
@@ -180,7 +183,7 @@ static DoubleDouble exp10_double_double(double x, double kd,
180183
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
181184

182185
// When output is denormal.
183-
static double exp10_denorm(double x) {
186+
LIBC_INLINE static double exp10_denorm(double x) {
184187
// Range reduction.
185188
double tmp = fputil::multiply_add(x, LOG2_10, 0x1.8000'0000'4p21);
186189
int k = static_cast<int>(cpp::bit_cast<uint64_t>(tmp) >> 19);
@@ -234,7 +237,7 @@ static double exp10_denorm(double x) {
234237
// * x >= log10(2^1024)
235238
// * x <= log10(2^-1022)
236239
// * x is inf or nan
237-
static constexpr double exp10_set_exceptional(double x) {
240+
LIBC_INLINE static constexpr double exp10_set_exceptional(double x) {
238241
using FPBits = typename fputil::FPBits<double>;
239242
FPBits xbits(x);
240243

@@ -285,7 +288,7 @@ static constexpr double exp10_set_exceptional(double x) {
285288

286289
namespace math {
287290

288-
static constexpr double exp10(double x) {
291+
LIBC_INLINE static constexpr double exp10(double x) {
289292
using FPBits = typename fputil::FPBits<double>;
290293
FPBits xbits(x);
291294

0 commit comments

Comments
 (0)