Skip to content

Commit d357324

Browse files
Revert "[libc][math][c23] Fix X86_Binary80 special cases for canonicalize functions. (#86924)"
This reverts commit 7c1c07c. Fails in presubmit. Link: https://lab.llvm.org/buildbot/#/builders/90/builds/67461 Link: https://lab.llvm.org/buildbot/#/builders/225/builds/33519 Link: https://lab.llvm.org/buildbot/#/builders/163/builds/53858 Link: https://lab.llvm.org/buildbot/#/builders/250/builds/20983 Link: #86924
1 parent 44253a9 commit d357324

File tree

3 files changed

+56
-54
lines changed

3 files changed

+56
-54
lines changed

libc/src/__support/FPUtil/BasicOperations.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,27 @@ LIBC_INLINE int canonicalize(T &cx, const T &x) {
185185
// More precisely :
186186
// Exponent | Significand | Meaning
187187
// | Bits 63-62 | Bits 61-0 |
188-
// All Ones | 00 | Zero | Pseudo Infinity, Value = SNaN
188+
// All Ones | 00 | Zero | Pseudo Infinity, Value = Infinty
189189
// All Ones | 00 | Non-Zero | Pseudo NaN, Value = SNaN
190190
// All Ones | 01 | Anything | Pseudo NaN, Value = SNaN
191191
// | Bit 63 | Bits 62-0 |
192192
// All zeroes | One | Anything | Pseudo Denormal, Value =
193193
// | | | (−1)**s × m × 2**−16382
194-
// All Other | Zero | Anything | Unnormal, Value = SNaN
195-
// Values | | |
194+
// All Other | Zero | Anything | Unnormal, Value =
195+
// Values | | | (−1)**s × m × 2**−16382
196196
bool bit63 = sx.get_implicit_bit();
197197
UInt128 mantissa = sx.get_explicit_mantissa();
198198
bool bit62 = static_cast<bool>((mantissa & (1ULL << 62)) >> 62);
199199
int exponent = sx.get_biased_exponent();
200200
if (exponent == 0x7FFF) {
201201
if (!bit63 && !bit62) {
202-
if (mantissa == 0) {
202+
if (mantissa == 0)
203+
cx = FPBits<T>::inf(sx.sign()).get_val();
204+
else {
203205
cx = FPBits<T>::quiet_nan(sx.sign(), mantissa).get_val();
204206
raise_except_if_required(FE_INVALID);
205207
return 1;
206208
}
207-
cx = FPBits<T>::quiet_nan(sx.sign(), mantissa).get_val();
208-
raise_except_if_required(FE_INVALID);
209-
return 1;
210209
} else if (!bit63 && bit62) {
211210
cx = FPBits<T>::quiet_nan(sx.sign(), mantissa).get_val();
212211
raise_except_if_required(FE_INVALID);
@@ -220,11 +219,9 @@ LIBC_INLINE int canonicalize(T &cx, const T &x) {
220219
cx = x;
221220
} else if (exponent == 0 && bit63)
222221
cx = FPBits<T>::make_value(mantissa, 0).get_val();
223-
else if (exponent != 0 && !bit63) {
224-
cx = FPBits<T>::quiet_nan(sx.sign(), mantissa).get_val();
225-
raise_except_if_required(FE_INVALID);
226-
return 1;
227-
} else if (LIBC_UNLIKELY(sx.is_signaling_nan())) {
222+
else if (exponent != 0 && !bit63)
223+
cx = FPBits<T>::make_value(mantissa, 0).get_val();
224+
else if (LIBC_UNLIKELY(sx.is_signaling_nan())) {
228225
cx =
229226
FPBits<T>::quiet_nan(sx.sign(), sx.get_explicit_mantissa()).get_val();
230227
raise_except_if_required(FE_INVALID);

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ add_fp_unittest(
178178
libc.src.math.canonicalize
179179
libc.src.__support.FPUtil.fp_bits
180180
libc.src.__support.FPUtil.fenv_impl
181-
libc.src.__support.integer_literals
182181
)
183182

184183
add_fp_unittest(
@@ -194,7 +193,6 @@ add_fp_unittest(
194193
libc.src.math.canonicalizef
195194
libc.src.__support.FPUtil.fp_bits
196195
libc.src.__support.FPUtil.fenv_impl
197-
libc.src.__support.integer_literals
198196
)
199197

200198
add_fp_unittest(
@@ -210,7 +208,6 @@ add_fp_unittest(
210208
libc.src.math.canonicalizef128
211209
libc.src.__support.FPUtil.fp_bits
212210
libc.src.__support.FPUtil.fenv_impl
213-
libc.src.__support.integer_literals
214211
)
215212

216213
add_fp_unittest(
@@ -226,7 +223,6 @@ add_fp_unittest(
226223
libc.src.math.canonicalizel
227224
libc.src.__support.FPUtil.fp_bits
228225
libc.src.__support.FPUtil.fenv_impl
229-
libc.src.__support.integer_literals
230226
)
231227

232228
add_fp_unittest(

libc/test/src/math/smoke/CanonicalizeTest.h

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
1111

1212
#include "src/__support/FPUtil/FPBits.h"
13-
#include "src/__support/integer_literals.h"
1413
#include "test/UnitTest/FPMatcher.h"
1514
#include "test/UnitTest/Test.h"
1615

@@ -23,8 +22,6 @@
2322

2423
#define TEST_REGULAR(x, y, expected) TEST_SPECIAL(x, y, expected, 0)
2524

26-
using LIBC_NAMESPACE::operator""_u128;
27-
2825
template <typename T>
2926
class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
3027

@@ -58,54 +55,57 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
5855
T cx;
5956
// Exponent | Significand | Meaning
6057
// | Bits 63-62 | Bits 61-0 |
61-
// All Ones | 00 | Zero | Pseudo Infinity, Value = SNaN
62-
FPBits test1(0x00000000'00007FFF'00000000'00000000_u128);
58+
// All Ones | 00 | Zero | Pseudo Infinity, Value = Infinty
59+
60+
FPBits test1((UInt128(0x7FFF) << 64) + UInt128(0x0000000000000000));
6361
const T test1_val = test1.get_val();
64-
TEST_SPECIAL(cx, test1_val, 1, FE_INVALID);
65-
EXPECT_FP_EQ(cx, aNaN);
62+
TEST_SPECIAL(cx, test1_val, 0, 0);
63+
EXPECT_FP_EQ(cx, inf);
6664

6765
// Exponent | Significand | Meaning
6866
// | Bits 63-62 | Bits 61-0 |
6967
// All Ones | 00 | Non-Zero | Pseudo NaN, Value = SNaN
70-
FPBits test2_1(0x000000000'00007FFF'00000000'00000001_u128);
68+
69+
FPBits test2_1((UInt128(0x7FFF) << 64) + UInt128(0x0000000000000001));
7170
const T test2_1_val = test2_1.get_val();
7271
TEST_SPECIAL(cx, test2_1_val, 1, FE_INVALID);
7372
EXPECT_FP_EQ(cx, aNaN);
7473

75-
FPBits test2_2(0x000000000'00007FFF'00000042'70000001_u128);
74+
FPBits test2_2((UInt128(0x7FFF) << 64) + UInt128(0x0000004270000001));
7675
const T test2_2_val = test2_2.get_val();
7776
TEST_SPECIAL(cx, test2_2_val, 1, FE_INVALID);
7877
EXPECT_FP_EQ(cx, aNaN);
7978

80-
FPBits test2_3(0x000000000'00007FFF'00000000'08261001_u128);
79+
FPBits test2_3((UInt128(0x7FFF) << 64) + UInt128(0x0000000008261001));
8180
const T test2_3_val = test2_3.get_val();
8281
TEST_SPECIAL(cx, test2_3_val, 1, FE_INVALID);
8382
EXPECT_FP_EQ(cx, aNaN);
8483

85-
FPBits test2_4(0x000000000'00007FFF'00007800'08261001_u128);
84+
FPBits test2_4((UInt128(0x7FFF) << 64) + UInt128(0x0000780008261001));
8685
const T test2_4_val = test2_4.get_val();
8786
TEST_SPECIAL(cx, test2_4_val, 1, FE_INVALID);
8887
EXPECT_FP_EQ(cx, aNaN);
8988

9089
// Exponent | Significand | Meaning
9190
// | Bits 63-62 | Bits 61-0 |
9291
// All Ones | 01 | Anything | Pseudo NaN, Value = SNaN
93-
FPBits test3_1(0x00000000'00007FFF'40000000'00000000_u128);
92+
93+
FPBits test3_1((UInt128(0x7FFF) << 64) + UInt128(0x4000000000000000));
9494
const T test3_1_val = test3_1.get_val();
9595
TEST_SPECIAL(cx, test3_1_val, 1, FE_INVALID);
9696
EXPECT_FP_EQ(cx, aNaN);
9797

98-
FPBits test3_2(0x00000000'00007FFF'40000042'70000001_u128);
98+
FPBits test3_2((UInt128(0x7FFF) << 64) + UInt128(0x4000004270000001));
9999
const T test3_2_val = test3_2.get_val();
100100
TEST_SPECIAL(cx, test3_2_val, 1, FE_INVALID);
101101
EXPECT_FP_EQ(cx, aNaN);
102102

103-
FPBits test3_3(0x00000000'00007FFF'40000000'08261001_u128);
103+
FPBits test3_3((UInt128(0x7FFF) << 64) + UInt128(0x4000000008261001));
104104
const T test3_3_val = test3_3.get_val();
105105
TEST_SPECIAL(cx, test3_3_val, 1, FE_INVALID);
106106
EXPECT_FP_EQ(cx, aNaN);
107107

108-
FPBits test3_4(0x00000000'00007FFF'40007800'08261001_u128);
108+
FPBits test3_4((UInt128(0x7FFF) << 64) + UInt128(0x4007800008261001));
109109
const T test3_4_val = test3_4.get_val();
110110
TEST_SPECIAL(cx, test3_4_val, 1, FE_INVALID);
111111
EXPECT_FP_EQ(cx, aNaN);
@@ -114,56 +114,65 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
114114
// | Bit 63 | Bits 62-0 |
115115
// All zeroes | One | Anything | Pseudo Denormal, Value =
116116
// | | | (−1)**s × m × 2**−16382
117-
FPBits test4_1(0x00000000'00000000'80000000'00000000_u128);
117+
118+
FPBits test4_1((UInt128(0x0000) << 64) + UInt128(0x8000000000000000));
118119
const T test4_1_val = test4_1.get_val();
119120
TEST_SPECIAL(cx, test4_1_val, 0, 0);
120121
EXPECT_FP_EQ(
121122
cx, FPBits::make_value(test4_1.get_explicit_mantissa(), 0).get_val());
122123

123-
FPBits test4_2(0x00000000'00000000'80000042'70000001_u128);
124+
FPBits test4_2((UInt128(0x0000) << 64) + UInt128(0x8000004270000001));
124125
const T test4_2_val = test4_2.get_val();
125126
TEST_SPECIAL(cx, test4_2_val, 0, 0);
126127
EXPECT_FP_EQ(
127128
cx, FPBits::make_value(test4_2.get_explicit_mantissa(), 0).get_val());
128-
FPBits test4_3(0x00000000'00000000'80000000'08261001_u128);
129+
130+
FPBits test4_3((UInt128(0x0000) << 64) + UInt128(0x8000000008261001));
129131
const T test4_3_val = test4_3.get_val();
130132
TEST_SPECIAL(cx, test4_3_val, 0, 0);
131133
EXPECT_FP_EQ(
132134
cx, FPBits::make_value(test4_3.get_explicit_mantissa(), 0).get_val());
133135

134136
// Exponent | Significand | Meaning
135137
// | Bit 63 | Bits 62-0 |
136-
// All Other | Zero | Anything | Unnormal, Value = SNaN
137-
// Values | | |
138-
FPBits test5_1(0x00000000'00000040'00000000'00000001_u128);
138+
// All Other | Zero | Anything | Unnormal, Value =
139+
// Values | | | (−1)**s × m × 2**−16382
140+
141+
FPBits test5_1(UInt128(0x0000000000000001));
139142
const T test5_1_val = test5_1.get_val();
140-
TEST_SPECIAL(cx, test5_1_val, 1, FE_INVALID);
141-
EXPECT_FP_EQ(cx, aNaN);
143+
TEST_SPECIAL(cx, test5_1_val, 0, 0);
144+
EXPECT_FP_EQ(
145+
cx, FPBits::make_value(test5_1.get_explicit_mantissa(), 0).get_val());
142146

143-
FPBits test5_2(0x00000000'00000230'00000042'70000001_u128);
147+
FPBits test5_2(UInt128(0x0000004270000001));
144148
const T test5_2_val = test5_2.get_val();
145-
TEST_SPECIAL(cx, test5_2_val, 1, FE_INVALID);
146-
EXPECT_FP_EQ(cx, aNaN);
149+
TEST_SPECIAL(cx, test5_2_val, 0, 0);
150+
EXPECT_FP_EQ(
151+
cx, FPBits::make_value(test5_2.get_explicit_mantissa(), 0).get_val());
147152

148-
FPBits test5_3(0x00000000'00000560'00000000'08261001_u128);
153+
FPBits test5_3(UInt128(0x0000000008261001));
149154
const T test5_3_val = test5_3.get_val();
150-
TEST_SPECIAL(cx, test5_3_val, 1, FE_INVALID);
151-
EXPECT_FP_EQ(cx, aNaN);
155+
TEST_SPECIAL(cx, test5_3_val, 0, 0);
156+
EXPECT_FP_EQ(
157+
cx, FPBits::make_value(test5_3.get_explicit_mantissa(), 0).get_val());
152158

153-
FPBits test5_4(0x00000000'00000780'00000028'16000000_u128);
159+
FPBits test5_4(UInt128(0x0000002816000000));
154160
const T test5_4_val = test5_4.get_val();
155-
TEST_SPECIAL(cx, test5_4_val, 1, FE_INVALID);
156-
EXPECT_FP_EQ(cx, aNaN);
161+
TEST_SPECIAL(cx, test5_4_val, 0, 0);
162+
EXPECT_FP_EQ(
163+
cx, FPBits::make_value(test5_4.get_explicit_mantissa(), 0).get_val());
157164

158-
FPBits test5_5(0x00000000'00000900'00000042'70000001_u128);
165+
FPBits test5_5(UInt128(0x0000004270000001));
159166
const T test5_5_val = test5_5.get_val();
160-
TEST_SPECIAL(cx, test5_5_val, 1, FE_INVALID);
161-
EXPECT_FP_EQ(cx, aNaN);
167+
TEST_SPECIAL(cx, test5_5_val, 0, 0);
168+
EXPECT_FP_EQ(
169+
cx, FPBits::make_value(test5_5.get_explicit_mantissa(), 0).get_val());
162170

163-
FPBits test5_6(0x00000000'00000AB0'00000000'08261001_u128);
171+
FPBits test5_6(UInt128(0x0000000008261001));
164172
const T test5_6_val = test5_6.get_val();
165-
TEST_SPECIAL(cx, test5_6_val, 1, FE_INVALID);
166-
EXPECT_FP_EQ(cx, aNaN);
173+
TEST_SPECIAL(cx, test5_6_val, 0, 0);
174+
EXPECT_FP_EQ(
175+
cx, FPBits::make_value(test5_6.get_explicit_mantissa(), 0).get_val());
167176
}
168177
}
169178

0 commit comments

Comments
 (0)