1818namespace LIBC_NAMESPACE_DECL {
1919namespace fputil {
2020
21+ #define DEFAULT_DOUBLE_SPLIT 27
22+
2123using DoubleDouble = LIBC_NAMESPACE::NumberPair<double >;
2224
2325// The output of Dekker's FastTwoSum algorithm is correct, i.e.:
@@ -61,7 +63,8 @@ LIBC_INLINE constexpr DoubleDouble add(const DoubleDouble &a, double b) {
6163// Zimmermann, P., "Note on the Veltkamp/Dekker Algorithms with Directed
6264// Roundings," https://inria.hal.science/hal-04480440.
6365// Default splitting constant = 2^ceil(prec(double)/2) + 1 = 2^27 + 1.
64- template <size_t N = 27 > LIBC_INLINE constexpr DoubleDouble split (double a) {
66+ template <size_t N = DEFAULT_DOUBLE_SPLIT>
67+ LIBC_INLINE constexpr DoubleDouble split (double a) {
6568 DoubleDouble r{0.0 , 0.0 };
6669 // CN = 2^N.
6770 constexpr double CN = static_cast <double >(1 << N);
@@ -73,16 +76,12 @@ template <size_t N = 27> LIBC_INLINE constexpr DoubleDouble split(double a) {
7376 return r;
7477}
7578
76- // Helper for non-fma exact mult where the first number is already splitted .
77- template <bool NO_FMA_ALL_ROUNDINGS = false >
79+ // Helper for non-fma exact mult where the first number is already split .
80+ template <size_t SPLIT_B = DEFAULT_DOUBLE_SPLIT >
7881LIBC_INLINE DoubleDouble exact_mult (const DoubleDouble &as, double a,
7982 double b) {
80- DoubleDouble bs, r;
81-
82- if constexpr (NO_FMA_ALL_ROUNDINGS)
83- bs = split<28 >(b);
84- else
85- bs = split (b);
83+ DoubleDouble bs = split<SPLIT_B>(b);
84+ DoubleDouble r{0.0 , 0.0 };
8685
8786 r.hi = a * b;
8887 double t1 = as.hi * bs.hi - r.hi ;
@@ -100,7 +99,7 @@ LIBC_INLINE DoubleDouble exact_mult(const DoubleDouble &as, double a,
10099// Using Theorem 1 in the paper above, without FMA instruction, if we restrict
101100// the generated constants to precision <= 51, and splitting it by 2^28 + 1,
102101// then a * b = r.hi + r.lo is exact for all rounding modes.
103- template <bool NO_FMA_ALL_ROUNDINGS = false >
102+ template <size_t SPLIT_B = 27 >
104103LIBC_INLINE DoubleDouble exact_mult (double a, double b) {
105104 DoubleDouble r{0.0 , 0.0 };
106105
@@ -111,7 +110,7 @@ LIBC_INLINE DoubleDouble exact_mult(double a, double b) {
111110 // Dekker's Product.
112111 DoubleDouble as = split (a);
113112
114- r = exact_mult<NO_FMA_ALL_ROUNDINGS >(as, a, b);
113+ r = exact_mult<SPLIT_B >(as, a, b);
115114#endif // LIBC_TARGET_CPU_HAS_FMA
116115
117116 return r;
0 commit comments