Skip to content

Commit 78d401b

Browse files
authored
Revert "[libc][NFC] Use user defined literals to build 128 and 256 bit constants." (llvm#81771)
Reverts llvm#81746
1 parent 0f33c54 commit 78d401b

File tree

16 files changed

+2490
-2523
lines changed

16 files changed

+2490
-2523
lines changed

libc/src/__support/integer_literals.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
namespace LIBC_NAMESPACE {
2323

2424
LIBC_INLINE constexpr uint8_t operator""_u8(unsigned long long value) {
25-
return static_cast<uint8_t>(value);
25+
return value;
2626
}
2727

2828
LIBC_INLINE constexpr uint16_t operator""_u16(unsigned long long value) {
29-
return static_cast<uint16_t>(value);
29+
return value;
3030
}
3131

3232
LIBC_INLINE constexpr uint32_t operator""_u32(unsigned long long value) {
33-
return static_cast<uint32_t>(value);
33+
return value;
3434
}
3535

3636
LIBC_INLINE constexpr uint64_t operator""_u64(unsigned long long value) {
37-
return static_cast<uint64_t>(value);
37+
return value;
3838
}
3939

4040
namespace internal {
@@ -76,7 +76,7 @@ template <typename T, int base> struct DigitBuffer {
7676
// Returns the digit for a particular character.
7777
// Returns 255 if the character is invalid.
7878
LIBC_INLINE static constexpr uint8_t get_digit_value(const char c) {
79-
const auto to_lower = [](char c) -> uint8_t { return c | 32; };
79+
const auto to_lower = [](char c) { return c | 32; };
8080
const auto is_digit = [](char c) { return c >= '0' && c <= '9'; };
8181
const auto is_alpha = [](char c) {
8282
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');

libc/src/math/generic/CMakeLists.txt

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,6 @@ add_entrypoint_object(
622622
DEPENDS
623623
.common_constants
624624
.explogxf
625-
libc.include.errno
626-
libc.include.math
627625
libc.src.__support.CPP.bit
628626
libc.src.__support.CPP.optional
629627
libc.src.__support.FPUtil.dyadic_float
@@ -634,9 +632,10 @@ add_entrypoint_object(
634632
libc.src.__support.FPUtil.polyeval
635633
libc.src.__support.FPUtil.rounding_mode
636634
libc.src.__support.FPUtil.triple_double
637-
libc.src.__support.integer_literals
638635
libc.src.__support.macros.optimization
636+
libc.include.errno
639637
libc.src.errno.errno
638+
libc.include.math
640639
COMPILE_OPTIONS
641640
-O3
642641
)
@@ -673,8 +672,6 @@ add_entrypoint_object(
673672
DEPENDS
674673
.common_constants
675674
.explogxf
676-
libc.include.errno
677-
libc.include.math
678675
libc.src.__support.CPP.bit
679676
libc.src.__support.CPP.optional
680677
libc.src.__support.FPUtil.dyadic_float
@@ -685,9 +682,10 @@ add_entrypoint_object(
685682
libc.src.__support.FPUtil.polyeval
686683
libc.src.__support.FPUtil.rounding_mode
687684
libc.src.__support.FPUtil.triple_double
688-
libc.src.__support.integer_literals
689685
libc.src.__support.macros.optimization
686+
libc.include.errno
690687
libc.src.errno.errno
688+
libc.include.math
691689
COMPILE_OPTIONS
692690
-O3
693691
)
@@ -733,8 +731,6 @@ add_entrypoint_object(
733731
DEPENDS
734732
.common_constants
735733
.explogxf
736-
libc.include.errno
737-
libc.include.math
738734
libc.src.__support.CPP.bit
739735
libc.src.__support.CPP.optional
740736
libc.src.__support.FPUtil.dyadic_float
@@ -745,9 +741,10 @@ add_entrypoint_object(
745741
libc.src.__support.FPUtil.polyeval
746742
libc.src.__support.FPUtil.rounding_mode
747743
libc.src.__support.FPUtil.triple_double
748-
libc.src.__support.integer_literals
749744
libc.src.__support.macros.optimization
745+
libc.include.errno
750746
libc.src.errno.errno
747+
libc.include.math
751748
COMPILE_OPTIONS
752749
-O3
753750
)
@@ -794,8 +791,6 @@ add_entrypoint_object(
794791
DEPENDS
795792
.common_constants
796793
.explogxf
797-
libc.include.errno
798-
libc.include.math
799794
libc.src.__support.CPP.bit
800795
libc.src.__support.CPP.optional
801796
libc.src.__support.FPUtil.dyadic_float
@@ -806,9 +801,10 @@ add_entrypoint_object(
806801
libc.src.__support.FPUtil.polyeval
807802
libc.src.__support.FPUtil.rounding_mode
808803
libc.src.__support.FPUtil.triple_double
809-
libc.src.__support.integer_literals
810804
libc.src.__support.macros.optimization
805+
libc.include.errno
811806
libc.src.errno.errno
807+
libc.include.math
812808
COMPILE_OPTIONS
813809
-O3
814810
)
@@ -1065,13 +1061,12 @@ add_entrypoint_object(
10651061
DEPENDS
10661062
.common_constants
10671063
.log_range_reduction
1068-
libc.src.__support.FPUtil.double_double
1069-
libc.src.__support.FPUtil.dyadic_float
10701064
libc.src.__support.FPUtil.fenv_impl
10711065
libc.src.__support.FPUtil.fp_bits
10721066
libc.src.__support.FPUtil.multiply_add
10731067
libc.src.__support.FPUtil.polyeval
1074-
libc.src.__support.integer_literals
1068+
libc.src.__support.FPUtil.double_double
1069+
libc.src.__support.FPUtil.dyadic_float
10751070
libc.src.__support.macros.optimization
10761071
COMPILE_OPTIONS
10771072
-O3
@@ -1102,13 +1097,12 @@ add_entrypoint_object(
11021097
../log1p.h
11031098
DEPENDS
11041099
.common_constants
1105-
libc.src.__support.FPUtil.double_double
1106-
libc.src.__support.FPUtil.dyadic_float
11071100
libc.src.__support.FPUtil.fenv_impl
11081101
libc.src.__support.FPUtil.fp_bits
11091102
libc.src.__support.FPUtil.multiply_add
11101103
libc.src.__support.FPUtil.polyeval
1111-
libc.src.__support.integer_literals
1104+
libc.src.__support.FPUtil.double_double
1105+
libc.src.__support.FPUtil.dyadic_float
11121106
libc.src.__support.macros.optimization
11131107
COMPILE_OPTIONS
11141108
-O3
@@ -1141,13 +1135,12 @@ add_entrypoint_object(
11411135
DEPENDS
11421136
.common_constants
11431137
.log_range_reduction
1144-
libc.src.__support.FPUtil.double_double
1145-
libc.src.__support.FPUtil.dyadic_float
11461138
libc.src.__support.FPUtil.fenv_impl
11471139
libc.src.__support.FPUtil.fp_bits
11481140
libc.src.__support.FPUtil.multiply_add
11491141
libc.src.__support.FPUtil.polyeval
1150-
libc.src.__support.integer_literals
1142+
libc.src.__support.FPUtil.double_double
1143+
libc.src.__support.FPUtil.dyadic_float
11511144
libc.src.__support.macros.optimization
11521145
COMPILE_OPTIONS
11531146
-O3
@@ -1180,13 +1173,12 @@ add_entrypoint_object(
11801173
DEPENDS
11811174
.common_constants
11821175
.log_range_reduction
1183-
libc.src.__support.FPUtil.double_double
1184-
libc.src.__support.FPUtil.dyadic_float
11851176
libc.src.__support.FPUtil.fenv_impl
11861177
libc.src.__support.FPUtil.fp_bits
11871178
libc.src.__support.FPUtil.multiply_add
11881179
libc.src.__support.FPUtil.polyeval
1189-
libc.src.__support.integer_literals
1180+
libc.src.__support.FPUtil.double_double
1181+
libc.src.__support.FPUtil.dyadic_float
11901182
libc.src.__support.macros.optimization
11911183
COMPILE_OPTIONS
11921184
-O3

libc/src/math/generic/exp.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "src/__support/FPUtil/rounding_mode.h"
2222
#include "src/__support/FPUtil/triple_double.h"
2323
#include "src/__support/common.h"
24-
#include "src/__support/integer_literals.h"
2524
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
2625

2726
#include <errno.h>
@@ -32,7 +31,6 @@ using fputil::DoubleDouble;
3231
using fputil::TripleDouble;
3332
using Float128 = typename fputil::DyadicFloat<128>;
3433
using Sign = fputil::Sign;
35-
using LIBC_NAMESPACE::operator""_u128;
3634

3735
// log2(e)
3836
constexpr double LOG2_E = 0x1.71547652b82fep+0;
@@ -99,15 +97,21 @@ DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
9997
// For |dx| < 2^-13 + 2^-30:
10098
// | output - exp(dx) | < 2^-126.
10199
Float128 poly_approx_f128(const Float128 &dx) {
100+
using MType = typename Float128::MantissaType;
101+
102102
constexpr Float128 COEFFS_128[]{
103-
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
104-
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
105-
{Sign::POS, -128, 0x80000000'00000000'00000000'00000000_u128}, // 0.5
106-
{Sign::POS, -130, 0xaaaaaaaa'aaaaaaaa'aaaaaaaa'aaaaaaab_u128}, // 1/6
107-
{Sign::POS, -132, 0xaaaaaaaa'aaaaaaaa'aaaaaaaa'aaaaaaab_u128}, // 1/24
108-
{Sign::POS, -134, 0x88888888'88888888'88888888'88888889_u128}, // 1/120
109-
{Sign::POS, -137, 0xb60b60b6'0b60b60b'60b60b60'b60b60b6_u128}, // 1/720
110-
{Sign::POS, -140, 0xd00d00d0'0d00d00d'00d00d00'd00d00d0_u128}, // 1/5040
103+
{Sign::POS, -127, MType({0, 0x8000000000000000})}, // 1.0
104+
{Sign::POS, -127, MType({0, 0x8000000000000000})}, // 1.0
105+
{Sign::POS, -128, MType({0, 0x8000000000000000})}, // 0.5
106+
{Sign::POS, -130, MType({0xaaaaaaaaaaaaaaab, 0xaaaaaaaaaaaaaaaa})}, // 1/6
107+
{Sign::POS, -132,
108+
MType({0xaaaaaaaaaaaaaaab, 0xaaaaaaaaaaaaaaaa})}, // 1/24
109+
{Sign::POS, -134,
110+
MType({0x8888888888888889, 0x8888888888888888})}, // 1/120
111+
{Sign::POS, -137,
112+
MType({0x60b60b60b60b60b6, 0xb60b60b60b60b60b})}, // 1/720
113+
{Sign::POS, -140,
114+
MType({0x00d00d00d00d00d0, 0xd00d00d00d00d00d})}, // 1/5040
111115
};
112116

113117
Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],

libc/src/math/generic/exp10.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "src/__support/FPUtil/rounding_mode.h"
2222
#include "src/__support/FPUtil/triple_double.h"
2323
#include "src/__support/common.h"
24-
#include "src/__support/integer_literals.h"
2524
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
2625

2726
#include <errno.h>
@@ -32,7 +31,6 @@ using fputil::DoubleDouble;
3231
using fputil::TripleDouble;
3332
using Float128 = typename fputil::DyadicFloat<128>;
3433
using Sign = fputil::Sign;
35-
using LIBC_NAMESPACE::operator""_u128;
3634

3735
// log2(10)
3836
constexpr double LOG2_10 = 0x1.a934f0979a371p+1;
@@ -101,15 +99,17 @@ DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
10199
// For |dx| < 2^-14:
102100
// | output - 10^dx | < 1.5 * 2^-124.
103101
Float128 poly_approx_f128(const Float128 &dx) {
102+
using MType = typename Float128::MantissaType;
103+
104104
constexpr Float128 COEFFS_128[]{
105-
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
106-
{Sign::POS, -126, 0x935d8ddd'aaa8ac16'ea56d62b'82d30a2d_u128},
107-
{Sign::POS, -126, 0xa9a92639'e753443a'80a99ce7'5f4d5bdb_u128},
108-
{Sign::POS, -126, 0x82382c8e'f1652304'6a4f9d7d'bf6c9635_u128},
109-
{Sign::POS, -124, 0x12bd7609'fd98c44c'34578701'9216c7af_u128},
110-
{Sign::POS, -127, 0x450a7ff4'7535d889'cc41ed7e'0d27aee5_u128},
111-
{Sign::POS, -130, 0xd3f6b844'702d636b'8326bb91'a6e7601d_u128},
112-
{Sign::POS, -130, 0x45b937f0'd05bb1cd'fa7b46df'314112a9_u128},
105+
{Sign::POS, -127, MType({0, 0x8000000000000000})}, // 1.0
106+
{Sign::POS, -126, MType({0xea56d62b82d30a2d, 0x935d8dddaaa8ac16})},
107+
{Sign::POS, -126, MType({0x80a99ce75f4d5bdb, 0xa9a92639e753443a})},
108+
{Sign::POS, -126, MType({0x6a4f9d7dbf6c9635, 0x82382c8ef1652304})},
109+
{Sign::POS, -124, MType({0x345787019216c7af, 0x12bd7609fd98c44c})},
110+
{Sign::POS, -127, MType({0xcc41ed7e0d27aee5, 0x450a7ff47535d889})},
111+
{Sign::POS, -130, MType({0x8326bb91a6e7601d, 0xd3f6b844702d636b})},
112+
{Sign::POS, -130, MType({0xfa7b46df314112a9, 0x45b937f0d05bb1cd})},
113113
};
114114

115115
Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],

libc/src/math/generic/exp2.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "src/__support/FPUtil/rounding_mode.h"
2222
#include "src/__support/FPUtil/triple_double.h"
2323
#include "src/__support/common.h"
24-
#include "src/__support/integer_literals.h"
2524
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
2625

2726
#include <errno.h>
@@ -32,7 +31,6 @@ using fputil::DoubleDouble;
3231
using fputil::TripleDouble;
3332
using Float128 = typename fputil::DyadicFloat<128>;
3433
using Sign = fputil::Sign;
35-
using LIBC_NAMESPACE::operator""_u128;
3634

3735
// Error bounds:
3836
// Errors when using double precision.
@@ -90,15 +88,17 @@ DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
9088
// For |dx| < 2^-13 + 2^-30:
9189
// | output - exp(dx) | < 2^-126.
9290
Float128 poly_approx_f128(const Float128 &dx) {
91+
using MType = typename Float128::MantissaType;
92+
9393
constexpr Float128 COEFFS_128[]{
94-
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
95-
{Sign::POS, -128, 0xb17217f7'd1cf79ab'c9e3b398'03f2f6af_u128},
96-
{Sign::POS, -128, 0x3d7f7bff'058b1d50'de2d60dd'9c9a1d9f_u128},
97-
{Sign::POS, -132, 0xe35846b8'2505fc59'9d3b15d9'e7fb6897_u128},
98-
{Sign::POS, -134, 0x9d955b7d'd273b94e'184462f6'bcd2b9e7_u128},
99-
{Sign::POS, -137, 0xaec3ff3c'53398883'39ea1bb9'64c51a89_u128},
100-
{Sign::POS, -138, 0x2861225f'345c396a'842c5341'8fa8ae61_u128},
101-
{Sign::POS, -144, 0xffe5fe2d'109a319d'7abeb5ab'd5ad2079_u128},
94+
{Sign::POS, -127, MType({0, 0x8000000000000000})}, // 1.0
95+
{Sign::POS, -128, MType({0xc9e3b39803f2f6af, 0xb17217f7d1cf79ab})},
96+
{Sign::POS, -128, MType({0xde2d60dd9c9a1d9f, 0x3d7f7bff058b1d50})},
97+
{Sign::POS, -132, MType({0x9d3b15d9e7fb6897, 0xe35846b82505fc59})},
98+
{Sign::POS, -134, MType({0x184462f6bcd2b9e7, 0x9d955b7dd273b94e})},
99+
{Sign::POS, -137, MType({0x39ea1bb964c51a89, 0xaec3ff3c53398883})},
100+
{Sign::POS, -138, MType({0x842c53418fa8ae61, 0x2861225f345c396a})},
101+
{Sign::POS, -144, MType({0x7abeb5abd5ad2079, 0xffe5fe2d109a319d})},
102102
};
103103

104104
Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],

libc/src/math/generic/expm1.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "src/__support/FPUtil/rounding_mode.h"
2323
#include "src/__support/FPUtil/triple_double.h"
2424
#include "src/__support/common.h"
25-
#include "src/__support/integer_literals.h"
2625
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
2726

2827
#include <errno.h>
@@ -40,7 +39,6 @@ using fputil::DoubleDouble;
4039
using fputil::TripleDouble;
4140
using Float128 = typename fputil::DyadicFloat<128>;
4241
using Sign = fputil::Sign;
43-
using LIBC_NAMESPACE::operator""_u128;
4442

4543
// log2(e)
4644
constexpr double LOG2_E = 0x1.71547652b82fep+0;
@@ -109,14 +107,20 @@ DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
109107
// For |dx| < 2^-13 + 2^-30:
110108
// | output - exp(dx) | < 2^-126.
111109
Float128 poly_approx_f128(const Float128 &dx) {
110+
using MType = typename Float128::MantissaType;
111+
112112
constexpr Float128 COEFFS_128[]{
113-
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
114-
{Sign::POS, -128, 0x80000000'00000000'00000000'00000000_u128}, // 0.5
115-
{Sign::POS, -130, 0xaaaaaaaa'aaaaaaaa'aaaaaaaa'aaaaaaab_u128}, // 1/6
116-
{Sign::POS, -132, 0xaaaaaaaa'aaaaaaaa'aaaaaaaa'aaaaaaab_u128}, // 1/24
117-
{Sign::POS, -134, 0x88888888'88888888'88888888'88888889_u128}, // 1/120
118-
{Sign::POS, -137, 0xb60b60b6'0b60b60b'60b60b60'b60b60b6_u128}, // 1/720
119-
{Sign::POS, -140, 0xd00d00d0'0d00d00d'00d00d00'd00d00d0_u128}, // 1/5040
113+
{Sign::POS, -127, MType({0, 0x8000000000000000})}, // 1.0
114+
{Sign::POS, -128, MType({0, 0x8000000000000000})}, // 0.5
115+
{Sign::POS, -130, MType({0xaaaaaaaaaaaaaaab, 0xaaaaaaaaaaaaaaaa})}, // 1/6
116+
{Sign::POS, -132,
117+
MType({0xaaaaaaaaaaaaaaab, 0xaaaaaaaaaaaaaaaa})}, // 1/24
118+
{Sign::POS, -134,
119+
MType({0x8888888888888889, 0x8888888888888888})}, // 1/120
120+
{Sign::POS, -137,
121+
MType({0x60b60b60b60b60b6, 0xb60b60b60b60b60b})}, // 1/720
122+
{Sign::POS, -140,
123+
MType({0x00d00d00d00d00d0, 0xd00d00d00d00d00d})}, // 1/5040
120124
};
121125

122126
Float128 p = fputil::polyeval(dx, COEFFS_128[0], COEFFS_128[1], COEFFS_128[2],
@@ -142,6 +146,7 @@ std::ostream &operator<<(std::ostream &OS, const DoubleDouble &r) {
142146
// TODO(lntue): investigate triple-double precision implementation for this
143147
// step.
144148
Float128 expm1_f128(double x, double kd, int idx1, int idx2) {
149+
using MType = typename Float128::MantissaType;
145150
// Recalculate dx:
146151

147152
double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
@@ -165,8 +170,7 @@ Float128 expm1_f128(double x, double kd, int idx1, int idx2) {
165170
Float128 exp_mid = fputil::quick_mul(exp_mid1, exp_mid2);
166171

167172
int hi = static_cast<int>(kd) >> 12;
168-
Float128 minus_one{Sign::NEG, -127 - hi,
169-
0x80000000'00000000'00000000'00000000_u128};
173+
Float128 minus_one{Sign::NEG, -127 - hi, MType({0, 0x8000000000000000})};
170174

171175
Float128 exp_mid_m1 = fputil::quick_add(exp_mid, minus_one);
172176

0 commit comments

Comments
 (0)