Skip to content

Commit 1d8d5d6

Browse files
authored
[libc] Moved range_reduction_double ifdef statement (#102659)
Sin/cos/tan fuzzers were having issues with ONE_TWENTY_EIGHT_OVER_PI, so the LIBC_TARGET_CPU_HAS_FMA ifdef statement got moved from the sin/cos/tan .cpp files to the range_reduction_double_common.cpp file.
1 parent 7299c7f commit 1d8d5d6

File tree

5 files changed

+22
-82
lines changed

5 files changed

+22
-82
lines changed

libc/src/math/generic/cos.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@
1919
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
2020
#include "src/math/generic/sincos_eval.h"
2121

22-
#ifdef LIBC_TARGET_CPU_HAS_FMA
23-
#include "range_reduction_double_fma.h"
24-
25-
using LIBC_NAMESPACE::fma::FAST_PASS_EXPONENT;
26-
using LIBC_NAMESPACE::fma::ONE_TWENTY_EIGHT_OVER_PI;
27-
using LIBC_NAMESPACE::fma::range_reduction_small;
28-
using LIBC_NAMESPACE::fma::SIN_K_PI_OVER_128;
29-
30-
LIBC_INLINE constexpr bool NO_FMA = false;
31-
#else
32-
#include "range_reduction_double_nofma.h"
33-
34-
using LIBC_NAMESPACE::nofma::FAST_PASS_EXPONENT;
35-
using LIBC_NAMESPACE::nofma::ONE_TWENTY_EIGHT_OVER_PI;
36-
using LIBC_NAMESPACE::nofma::range_reduction_small;
37-
using LIBC_NAMESPACE::nofma::SIN_K_PI_OVER_128;
38-
39-
LIBC_INLINE constexpr bool NO_FMA = true;
40-
#endif // LIBC_TARGET_CPU_HAS_FMA
41-
4222
// TODO: We might be able to improve the performance of large range reduction of
4323
// non-FMA targets further by operating directly on 25-bit chunks of 128/pi and
4424
// pre-split SIN_K_PI_OVER_128, but that might double the memory footprint of

libc/src/math/generic/range_reduction_double_common.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@
1818
#include "src/__support/integer_literals.h"
1919
#include "src/__support/macros/config.h"
2020

21+
#ifdef LIBC_TARGET_CPU_HAS_FMA
22+
#include "range_reduction_double_fma.h"
23+
24+
// With FMA, we limit the maxmimum exponent to be 2^16, so that the error bound
25+
// from the fma::range_reduction_small is bounded by 2^-88 instead of 2^-72.
26+
#define FAST_PASS_EXPONENT 16
27+
using LIBC_NAMESPACE::fma::ONE_TWENTY_EIGHT_OVER_PI;
28+
using LIBC_NAMESPACE::fma::range_reduction_small;
29+
using LIBC_NAMESPACE::fma::SIN_K_PI_OVER_128;
30+
31+
LIBC_INLINE constexpr bool NO_FMA = false;
32+
#else
33+
#include "range_reduction_double_nofma.h"
34+
35+
using LIBC_NAMESPACE::nofma::FAST_PASS_EXPONENT;
36+
using LIBC_NAMESPACE::nofma::ONE_TWENTY_EIGHT_OVER_PI;
37+
using LIBC_NAMESPACE::nofma::range_reduction_small;
38+
using LIBC_NAMESPACE::nofma::SIN_K_PI_OVER_128;
39+
40+
LIBC_INLINE constexpr bool NO_FMA = true;
41+
#endif // LIBC_TARGET_CPU_HAS_FMA
42+
2143
namespace LIBC_NAMESPACE_DECL {
2244

2345
namespace generic {

libc/src/math/generic/sin.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@
2020
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
2121
#include "src/math/generic/sincos_eval.h"
2222

23-
#ifdef LIBC_TARGET_CPU_HAS_FMA
24-
#include "range_reduction_double_fma.h"
25-
26-
using LIBC_NAMESPACE::fma::FAST_PASS_EXPONENT;
27-
using LIBC_NAMESPACE::fma::ONE_TWENTY_EIGHT_OVER_PI;
28-
using LIBC_NAMESPACE::fma::range_reduction_small;
29-
using LIBC_NAMESPACE::fma::SIN_K_PI_OVER_128;
30-
31-
LIBC_INLINE constexpr bool NO_FMA = false;
32-
#else
33-
#include "range_reduction_double_nofma.h"
34-
35-
using LIBC_NAMESPACE::nofma::FAST_PASS_EXPONENT;
36-
using LIBC_NAMESPACE::nofma::ONE_TWENTY_EIGHT_OVER_PI;
37-
using LIBC_NAMESPACE::nofma::range_reduction_small;
38-
using LIBC_NAMESPACE::nofma::SIN_K_PI_OVER_128;
39-
40-
LIBC_INLINE constexpr bool NO_FMA = true;
41-
#endif // LIBC_TARGET_CPU_HAS_FMA
42-
4323
// TODO: We might be able to improve the performance of large range reduction of
4424
// non-FMA targets further by operating directly on 25-bit chunks of 128/pi and
4525
// pre-split SIN_K_PI_OVER_128, but that might double the memory footprint of

libc/src/math/generic/sincos.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,6 @@
2121
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
2222
#include "src/math/generic/sincos_eval.h"
2323

24-
#ifdef LIBC_TARGET_CPU_HAS_FMA
25-
#include "range_reduction_double_fma.h"
26-
27-
using LIBC_NAMESPACE::fma::FAST_PASS_EXPONENT;
28-
using LIBC_NAMESPACE::fma::ONE_TWENTY_EIGHT_OVER_PI;
29-
using LIBC_NAMESPACE::fma::range_reduction_small;
30-
using LIBC_NAMESPACE::fma::SIN_K_PI_OVER_128;
31-
32-
LIBC_INLINE constexpr bool NO_FMA = false;
33-
#else
34-
#include "range_reduction_double_nofma.h"
35-
36-
using LIBC_NAMESPACE::nofma::FAST_PASS_EXPONENT;
37-
using LIBC_NAMESPACE::nofma::ONE_TWENTY_EIGHT_OVER_PI;
38-
using LIBC_NAMESPACE::nofma::range_reduction_small;
39-
using LIBC_NAMESPACE::nofma::SIN_K_PI_OVER_128;
40-
41-
LIBC_INLINE constexpr bool NO_FMA = true;
42-
#endif // LIBC_TARGET_CPU_HAS_FMA
43-
4424
// TODO: We might be able to improve the performance of large range reduction of
4525
// non-FMA targets further by operating directly on 25-bit chunks of 128/pi and
4626
// pre-split SIN_K_PI_OVER_128, but that might double the memory footprint of

libc/src/math/generic/tan.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,6 @@
2121
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
2222
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
2323

24-
#ifdef LIBC_TARGET_CPU_HAS_FMA
25-
#include "range_reduction_double_fma.h"
26-
27-
// With FMA, we limit the maxmimum exponent to be 2^16, so that the error bound
28-
// from the fma::range_reduction_small is bounded by 2^-88 instead of 2^-72.
29-
#define FAST_PASS_EXPONENT 16
30-
using LIBC_NAMESPACE::fma::ONE_TWENTY_EIGHT_OVER_PI;
31-
using LIBC_NAMESPACE::fma::range_reduction_small;
32-
using LIBC_NAMESPACE::fma::SIN_K_PI_OVER_128;
33-
34-
LIBC_INLINE constexpr bool NO_FMA = false;
35-
#else
36-
#include "range_reduction_double_nofma.h"
37-
38-
using LIBC_NAMESPACE::nofma::FAST_PASS_EXPONENT;
39-
using LIBC_NAMESPACE::nofma::ONE_TWENTY_EIGHT_OVER_PI;
40-
using LIBC_NAMESPACE::nofma::range_reduction_small;
41-
using LIBC_NAMESPACE::nofma::SIN_K_PI_OVER_128;
42-
43-
LIBC_INLINE constexpr bool NO_FMA = true;
44-
#endif // LIBC_TARGET_CPU_HAS_FMA
45-
4624
// TODO: We might be able to improve the performance of large range reduction of
4725
// non-FMA targets further by operating directly on 25-bit chunks of 128/pi and
4826
// pre-split SIN_K_PI_OVER_128, but that might double the memory footprint of

0 commit comments

Comments
 (0)