Skip to content

Commit 7f60071

Browse files
committed
make explogxf header only
1 parent b12ff3f commit 7f60071

File tree

20 files changed

+71
-192
lines changed

20 files changed

+71
-192
lines changed

libc/src/__support/math/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ add_header_library(
5656
libc.include.llvm-libc-macros.float16_macros
5757
)
5858

59+
#TODO: Add errno include to the hyperbolic functions.
60+
add_header_library(
61+
explogxf
62+
HDRS
63+
explogxf.h
64+
DEPENDS
65+
libc.src.math.common_constants
66+
libc.src.__support.math.exp_utils
67+
libc.src.__support.math.exp10f_utils
68+
libc.src.__support.macros.properties.cpu_features
69+
libc.src.errno.errno
70+
)
71+
5972
add_header_library(
6073
frexpf128
6174
HDRS

libc/src/math/generic/explogxf.h renamed to libc/src/__support/math/explogxf.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_MATH_GENERIC_EXPLOGXF_H
1010
#define LLVM_LIBC_SRC_MATH_GENERIC_EXPLOGXF_H
1111

12-
#include "common_constants.h"
12+
#include "src/math/generic/common_constants.h"
1313

1414
#include "src/__support/common.h"
1515
#include "src/__support/macros/properties/cpu_features.h"
@@ -21,17 +21,6 @@ namespace LIBC_NAMESPACE_DECL {
2121
constexpr int LOG_P1_BITS = 6;
2222
constexpr int LOG_P1_SIZE = 1 << LOG_P1_BITS;
2323

24-
// N[Table[Log[2, 1 + x], {x, 0/64, 63/64, 1/64}], 40]
25-
extern const double LOG_P1_LOG2[LOG_P1_SIZE];
26-
27-
// N[Table[1/(1 + x), {x, 0/64, 63/64, 1/64}], 40]
28-
extern const double LOG_P1_1_OVER[LOG_P1_SIZE];
29-
30-
// Taylor series expansion for Log[2, 1 + x] splitted to EVEN AND ODD numbers
31-
// K_LOG2_ODD starts from x^3
32-
extern const double K_LOG2_ODD[4];
33-
extern const double K_LOG2_EVEN[4];
34-
3524
// The function correctly calculates sinh(x) and cosh(x) by calculating exp(x)
3625
// and exp(-x) simultaneously.
3726
// To compute e^x, we perform the following range
@@ -131,33 +120,6 @@ template <bool is_sinh> LIBC_INLINE double exp_pm_eval(float x) {
131120
return r;
132121
}
133122

134-
// x should be positive, normal finite value
135-
LIBC_INLINE static double log2_eval(double x) {
136-
using FPB = fputil::FPBits<double>;
137-
FPB bs(x);
138-
139-
double result = 0;
140-
result += bs.get_exponent();
141-
142-
int p1 = (bs.get_mantissa() >> (FPB::FRACTION_LEN - LOG_P1_BITS)) &
143-
(LOG_P1_SIZE - 1);
144-
145-
bs.set_uintval(bs.uintval() & (FPB::FRACTION_MASK >> LOG_P1_BITS));
146-
bs.set_biased_exponent(FPB::EXP_BIAS);
147-
double dx = (bs.get_val() - 1.0) * LOG_P1_1_OVER[p1];
148-
149-
// Taylor series for log(2,1+x)
150-
double c1 = fputil::multiply_add(dx, K_LOG2_ODD[0], K_LOG2_EVEN[0]);
151-
double c2 = fputil::multiply_add(dx, K_LOG2_ODD[1], K_LOG2_EVEN[1]);
152-
double c3 = fputil::multiply_add(dx, K_LOG2_ODD[2], K_LOG2_EVEN[2]);
153-
double c4 = fputil::multiply_add(dx, K_LOG2_ODD[3], K_LOG2_EVEN[3]);
154-
155-
// c0 = dx * (1.0 / ln(2)) + LOG_P1_LOG2[p1]
156-
double c0 = fputil::multiply_add(dx, 0x1.71547652b82fep+0, LOG_P1_LOG2[p1]);
157-
result += LIBC_NAMESPACE::fputil::polyeval(dx * dx, c0, c1, c2, c3, c4);
158-
return result;
159-
}
160-
161123
// x should be positive, normal finite value
162124
// TODO: Simplify range reduction and polynomial degree for float16.
163125
// See issue #137190.

libc/src/math/generic/CMakeLists.txt

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ add_entrypoint_object(
13441344
../exp2.h
13451345
DEPENDS
13461346
.common_constants
1347-
.explogxf
1347+
libc.src.__support.math.explogxf
13481348
libc.src.__support.CPP.bit
13491349
libc.src.__support.CPP.optional
13501350
libc.src.__support.FPUtil.dyadic_float
@@ -1365,7 +1365,7 @@ add_header_library(
13651365
HDRS
13661366
exp2f_impl.h
13671367
DEPENDS
1368-
.explogxf
1368+
libc.src.__support.math.explogxf
13691369
libc.src.__support.FPUtil.except_value_utils
13701370
libc.src.__support.FPUtil.fenv_impl
13711371
libc.src.__support.FPUtil.fp_bits
@@ -1413,7 +1413,7 @@ add_entrypoint_object(
14131413
HDRS
14141414
../exp2m1f.h
14151415
DEPENDS
1416-
.explogxf
1416+
libc.src.__support.math.explogxf
14171417
libc.src.errno.errno
14181418
libc.src.__support.common
14191419
libc.src.__support.FPUtil.except_value_utils
@@ -1500,7 +1500,7 @@ add_entrypoint_object(
15001500
HDRS
15011501
../exp10m1f.h
15021502
DEPENDS
1503-
.explogxf
1503+
libc.src.__support.math.explogxf
15041504
libc.src.errno.errno
15051505
libc.src.__support.common
15061506
libc.src.__support.FPUtil.except_value_utils
@@ -1541,7 +1541,7 @@ add_entrypoint_object(
15411541
../expm1.h
15421542
DEPENDS
15431543
.common_constants
1544-
.explogxf
1544+
libc.src.__support.math.explogxf
15451545
libc.src.__support.CPP.bit
15461546
libc.src.__support.CPP.optional
15471547
libc.src.__support.FPUtil.dyadic_float
@@ -1605,7 +1605,7 @@ add_entrypoint_object(
16051605
DEPENDS
16061606
.common_constants
16071607
.exp2f_impl
1608-
.explogxf
1608+
libc.src.__support.math.explogxf
16091609
libc.src.__support.math.exp10f
16101610
libc.src.__support.CPP.bit
16111611
libc.src.__support.FPUtil.fenv_impl
@@ -3765,29 +3765,14 @@ add_entrypoint_object(
37653765
libc.src.__support.FPUtil.nearest_integer_operations
37663766
)
37673767

3768-
#TODO: Add errno include to the hyperbolic functions.
3769-
add_object_library(
3770-
explogxf
3771-
HDRS
3772-
explogxf.h
3773-
SRCS
3774-
explogxf.cpp
3775-
DEPENDS
3776-
.common_constants
3777-
libc.src.__support.math.exp_utils
3778-
libc.src.__support.math.exp10f_utils
3779-
libc.src.__support.macros.properties.cpu_features
3780-
libc.src.errno.errno
3781-
)
3782-
37833768
add_entrypoint_object(
37843769
coshf
37853770
SRCS
37863771
coshf.cpp
37873772
HDRS
37883773
../coshf.h
37893774
DEPENDS
3790-
.explogxf
3775+
libc.src.__support.math.explogxf
37913776
libc.src.__support.FPUtil.fp_bits
37923777
libc.src.__support.FPUtil.multiply_add
37933778
libc.src.__support.FPUtil.rounding_mode
@@ -3818,7 +3803,7 @@ add_entrypoint_object(
38183803
HDRS
38193804
../sinhf.h
38203805
DEPENDS
3821-
.explogxf
3806+
libc.src.__support.math.explogxf
38223807
libc.src.__support.FPUtil.fp_bits
38233808
libc.src.__support.FPUtil.rounding_mode
38243809
libc.src.__support.macros.optimization
@@ -3848,7 +3833,7 @@ add_entrypoint_object(
38483833
HDRS
38493834
../tanhf.h
38503835
DEPENDS
3851-
.explogxf
3836+
libc.src.__support.math.explogxf
38523837
libc.src.__support.FPUtil.fp_bits
38533838
libc.src.__support.FPUtil.rounding_mode
38543839
libc.src.__support.FPUtil.multiply_add
@@ -3884,7 +3869,7 @@ add_entrypoint_object(
38843869
HDRS
38853870
../acoshf.h
38863871
DEPENDS
3887-
.explogxf
3872+
libc.src.__support.math.explogxf
38883873
libc.src.__support.FPUtil.fenv_impl
38893874
libc.src.__support.FPUtil.fp_bits
38903875
libc.src.__support.FPUtil.multiply_add
@@ -3900,7 +3885,7 @@ add_entrypoint_object(
39003885
HDRS
39013886
../acoshf16.h
39023887
DEPENDS
3903-
.explogxf
3888+
libc.src.__support.math.explogxf
39043889
libc.hdr.errno_macros
39053890
libc.hdr.fenv_macros
39063891
libc.src.__support.FPUtil.cast
@@ -3921,7 +3906,7 @@ add_entrypoint_object(
39213906
HDRS
39223907
../asinhf.h
39233908
DEPENDS
3924-
.explogxf
3909+
libc.src.__support.math.explogxf
39253910
libc.src.__support.FPUtil.fp_bits
39263911
libc.src.__support.FPUtil.multiply_add
39273912
libc.src.__support.FPUtil.polyeval
@@ -3936,7 +3921,7 @@ add_entrypoint_object(
39363921
HDRS
39373922
../asinhf16.h
39383923
DEPENDS
3939-
.explogxf
3924+
libc.src.__support.math.explogxf
39403925
libc.hdr.fenv_macros
39413926
libc.src.__support.FPUtil.cast
39423927
libc.src.__support.FPUtil.except_value_utils
@@ -3957,7 +3942,7 @@ add_entrypoint_object(
39573942
HDRS
39583943
../atanhf.h
39593944
DEPENDS
3960-
.explogxf
3945+
libc.src.__support.math.explogxf
39613946
libc.src.__support.FPUtil.fp_bits
39623947
libc.src.__support.FPUtil.fenv_impl
39633948
libc.src.__support.macros.optimization
@@ -3970,7 +3955,7 @@ add_entrypoint_object(
39703955
HDRS
39713956
../atanhf16.h
39723957
DEPENDS
3973-
.explogxf
3958+
libc.src.__support.math.explogxf
39743959
libc.hdr.errno_macros
39753960
libc.hdr.fenv_macros
39763961
libc.src.__support.FPUtil.cast

libc/src/math/generic/acoshf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "src/__support/macros/config.h"
1616
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1717
#include "src/math/generic/common_constants.h"
18-
#include "src/math/generic/explogxf.h"
18+
#include "src/__support/math/explogxf.h"
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

libc/src/math/generic/acoshf16.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/math/acoshf16.h"
10-
#include "explogxf.h"
10+
#include "src/__support/math/explogxf.h"
1111
#include "hdr/errno_macros.h"
1212
#include "hdr/fenv_macros.h"
1313
#include "src/__support/FPUtil/FEnvImpl.h"

libc/src/math/generic/asinhf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "src/__support/macros/config.h"
1515
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1616
#include "src/math/generic/common_constants.h"
17-
#include "src/math/generic/explogxf.h"
17+
#include "src/__support/math/explogxf.h"
1818

1919
namespace LIBC_NAMESPACE_DECL {
2020

libc/src/math/generic/asinhf16.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/math/asinhf16.h"
10-
#include "explogxf.h"
10+
#include "src/__support/math/explogxf.h"
1111
#include "hdr/fenv_macros.h"
1212
#include "src/__support/FPUtil/FEnvImpl.h"
1313
#include "src/__support/FPUtil/FPBits.h"

libc/src/math/generic/atanhf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "src/__support/FPUtil/FPBits.h"
1212
#include "src/__support/macros/config.h"
1313
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
14-
#include "src/math/generic/explogxf.h"
14+
#include "src/__support/math/explogxf.h"
1515

1616
namespace LIBC_NAMESPACE_DECL {
1717

libc/src/math/generic/atanhf16.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/math/atanhf16.h"
10-
#include "explogxf.h"
10+
#include "src/__support/math/explogxf.h"
1111
#include "hdr/errno_macros.h"
1212
#include "hdr/fenv_macros.h"
1313
#include "src/__support/FPUtil/FEnvImpl.h"

libc/src/math/generic/coshf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "src/__support/FPUtil/rounding_mode.h"
1313
#include "src/__support/macros/config.h"
1414
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
15-
#include "src/math/generic/explogxf.h"
15+
#include "src/__support/math/explogxf.h"
1616

1717
namespace LIBC_NAMESPACE_DECL {
1818

0 commit comments

Comments
 (0)