Skip to content

Commit a1d4c69

Browse files
authored
Revert "[reland][libc][NFC] Use user defined literals to build 128 and 256 bit constants" (#81882)
Reverts #81835 This is breaking arm32 which does not support 64 bit types.
1 parent 5375009 commit a1d4c69

File tree

16 files changed

+2510
-2544
lines changed

16 files changed

+2510
-2544
lines changed

libc/src/__support/integer_literals.h

Lines changed: 10 additions & 11 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 {
@@ -64,7 +64,6 @@ template <typename T, int base> struct DigitBuffer {
6464
: 0;
6565
LIBC_INLINE_VAR static constexpr size_t MAX_DIGITS =
6666
sizeof(T) * CHAR_BIT / BITS_PER_DIGIT;
67-
LIBC_INLINE_VAR static constexpr uint8_t INVALID_DIGIT = 255;
6867

6968
uint8_t digits[MAX_DIGITS] = {};
7069
size_t size = 0;
@@ -75,26 +74,26 @@ template <typename T, int base> struct DigitBuffer {
7574
}
7675

7776
// Returns the digit for a particular character.
78-
// Returns INVALID_DIGIT if the character is invalid.
77+
// Returns 255 if the character is invalid.
7978
LIBC_INLINE static constexpr uint8_t get_digit_value(const char c) {
8079
const auto to_lower = [](char c) { return c | 32; };
8180
const auto is_digit = [](char c) { return c >= '0' && c <= '9'; };
8281
const auto is_alpha = [](char c) {
8382
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
8483
};
8584
if (is_digit(c))
86-
return static_cast<uint8_t>(c - '0');
85+
return c - '0';
8786
if (base > 10 && is_alpha(c))
88-
return static_cast<uint8_t>(to_lower(c) - 'a' + 10);
89-
return INVALID_DIGIT;
87+
return to_lower(c) - 'a' + 10;
88+
return 255;
9089
}
9190

9291
// Adds a single character to this buffer.
9392
LIBC_INLINE constexpr void push(char c) {
9493
if (c == '\'')
9594
return; // ' is valid but not taken into account.
9695
const uint8_t value = get_digit_value(c);
97-
if (value == INVALID_DIGIT || size >= MAX_DIGITS) {
96+
if (value == 255 || size >= MAX_DIGITS) {
9897
// During constant evaluation `__builtin_unreachable` will halt the
9998
// compiler as it is not executable. This is preferable over `assert` that
10099
// will only trigger in debug mode. Also we can't use `static_assert`
@@ -132,7 +131,7 @@ struct Parser<LIBC_NAMESPACE::cpp::BigInt<N, false, uint64_t>> {
132131
// Fast path, we consume blocks of uint64_t and creates the BigInt's
133132
// internal representation directly.
134133
using U64ArrayT = cpp::array<uint64_t, UIntT::WORD_COUNT>;
135-
U64ArrayT array = {};
134+
U64ArrayT array;
136135
size_t size = buffer.size;
137136
const uint8_t *digit_ptr = buffer.digits + size;
138137
for (size_t i = 0; i < array.size(); ++i) {

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
)
@@ -1078,13 +1074,12 @@ add_entrypoint_object(
10781074
DEPENDS
10791075
.common_constants
10801076
.log_range_reduction
1081-
libc.src.__support.FPUtil.double_double
1082-
libc.src.__support.FPUtil.dyadic_float
10831077
libc.src.__support.FPUtil.fenv_impl
10841078
libc.src.__support.FPUtil.fp_bits
10851079
libc.src.__support.FPUtil.multiply_add
10861080
libc.src.__support.FPUtil.polyeval
1087-
libc.src.__support.integer_literals
1081+
libc.src.__support.FPUtil.double_double
1082+
libc.src.__support.FPUtil.dyadic_float
10881083
libc.src.__support.macros.optimization
10891084
COMPILE_OPTIONS
10901085
-O3
@@ -1115,13 +1110,12 @@ add_entrypoint_object(
11151110
../log1p.h
11161111
DEPENDS
11171112
.common_constants
1118-
libc.src.__support.FPUtil.double_double
1119-
libc.src.__support.FPUtil.dyadic_float
11201113
libc.src.__support.FPUtil.fenv_impl
11211114
libc.src.__support.FPUtil.fp_bits
11221115
libc.src.__support.FPUtil.multiply_add
11231116
libc.src.__support.FPUtil.polyeval
1124-
libc.src.__support.integer_literals
1117+
libc.src.__support.FPUtil.double_double
1118+
libc.src.__support.FPUtil.dyadic_float
11251119
libc.src.__support.macros.optimization
11261120
COMPILE_OPTIONS
11271121
-O3
@@ -1154,13 +1148,12 @@ add_entrypoint_object(
11541148
DEPENDS
11551149
.common_constants
11561150
.log_range_reduction
1157-
libc.src.__support.FPUtil.double_double
1158-
libc.src.__support.FPUtil.dyadic_float
11591151
libc.src.__support.FPUtil.fenv_impl
11601152
libc.src.__support.FPUtil.fp_bits
11611153
libc.src.__support.FPUtil.multiply_add
11621154
libc.src.__support.FPUtil.polyeval
1163-
libc.src.__support.integer_literals
1155+
libc.src.__support.FPUtil.double_double
1156+
libc.src.__support.FPUtil.dyadic_float
11641157
libc.src.__support.macros.optimization
11651158
COMPILE_OPTIONS
11661159
-O3
@@ -1193,13 +1186,12 @@ add_entrypoint_object(
11931186
DEPENDS
11941187
.common_constants
11951188
.log_range_reduction
1196-
libc.src.__support.FPUtil.double_double
1197-
libc.src.__support.FPUtil.dyadic_float
11981189
libc.src.__support.FPUtil.fenv_impl
11991190
libc.src.__support.FPUtil.fp_bits
12001191
libc.src.__support.FPUtil.multiply_add
12011192
libc.src.__support.FPUtil.polyeval
1202-
libc.src.__support.integer_literals
1193+
libc.src.__support.FPUtil.double_double
1194+
libc.src.__support.FPUtil.dyadic_float
12031195
libc.src.__support.macros.optimization
12041196
COMPILE_OPTIONS
12051197
-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],

0 commit comments

Comments
 (0)