Skip to content

Commit b385c63

Browse files
authored
[libc] Fix canonicalize[f|l] tests for targets with long-double-is-double. (#115998)
1 parent ec4dab1 commit b385c63

File tree

1 file changed

+54
-58
lines changed

1 file changed

+54
-58
lines changed

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

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818

1919
#include "hdr/math_macros.h"
2020

21-
#if __SIZEOF_LONG_DOUBLE__ != 16 && __SIZEOF_LONG_DOUBLE__ != 12
22-
#error "unhandled long double type"
23-
#endif
24-
2521
#define TEST_SPECIAL(x, y, expected, expected_exception) \
2622
EXPECT_EQ(expected, f(&x, &y)); \
2723
EXPECT_FP_EXCEPTION(expected_exception); \
@@ -66,10 +62,10 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
6662
// Exponent | Significand | Meaning
6763
// | Bits 63-62 | Bits 61-0 |
6864
// All Ones | 00 | Zero | Pseudo Infinity, Value = SNaN
69-
#if __SIZEOF_LONG_DOUBLE__ == 16
70-
FPBits test1(0x00000000'00007FFF'00000000'00000000_u128);
71-
#elif __SIZEOF_LONG_DOUBLE__ == 12
65+
#if __SIZEOF_LONG_DOUBLE__ == 12
7266
FPBits test1(0x00007FFF'00000000'00000000_u96);
67+
#else
68+
FPBits test1(0x00000000'00007FFF'00000000'00000000_u128);
7369
#endif
7470
const T test1_val = test1.get_val();
7571
TEST_SPECIAL(cx, test1_val, 1, FE_INVALID);
@@ -78,37 +74,37 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
7874
// Exponent | Significand | Meaning
7975
// | Bits 63-62 | Bits 61-0 |
8076
// All Ones | 00 | Non-Zero | Pseudo NaN, Value = SNaN
81-
#if __SIZEOF_LONG_DOUBLE__ == 16
82-
FPBits test2_1(0x00000000'00007FFF'00000000'00000001_u128);
83-
#elif __SIZEOF_LONG_DOUBLE__ == 12
77+
#if __SIZEOF_LONG_DOUBLE__ == 12
8478
FPBits test2_1(0x00007FFF'00000000'00000001_u96);
79+
#else
80+
FPBits test2_1(0x00000000'00007FFF'00000000'00000001_u128);
8581
#endif
8682
const T test2_1_val = test2_1.get_val();
8783
TEST_SPECIAL(cx, test2_1_val, 1, FE_INVALID);
8884
EXPECT_FP_EQ(cx, aNaN);
8985

90-
#if __SIZEOF_LONG_DOUBLE__ == 16
91-
FPBits test2_2(0x00000000'00007FFF'00000042'70000001_u128);
92-
#elif __SIZEOF_LONG_DOUBLE__ == 12
86+
#if __SIZEOF_LONG_DOUBLE__ == 12
9387
FPBits test2_2(0x00007FFF'00000042'70000001_u96);
88+
#else
89+
FPBits test2_2(0x00000000'00007FFF'00000042'70000001_u128);
9490
#endif
9591
const T test2_2_val = test2_2.get_val();
9692
TEST_SPECIAL(cx, test2_2_val, 1, FE_INVALID);
9793
EXPECT_FP_EQ(cx, aNaN);
9894

99-
#if __SIZEOF_LONG_DOUBLE__ == 16
100-
FPBits test2_3(0x00000000'00007FFF'00000000'08261001_u128);
101-
#elif __SIZEOF_LONG_DOUBLE__ == 12
95+
#if __SIZEOF_LONG_DOUBLE__ == 12
10296
FPBits test2_3(0x00007FFF'00000000'08261001_u96);
97+
#else
98+
FPBits test2_3(0x00000000'00007FFF'00000000'08261001_u128);
10399
#endif
104100
const T test2_3_val = test2_3.get_val();
105101
TEST_SPECIAL(cx, test2_3_val, 1, FE_INVALID);
106102
EXPECT_FP_EQ(cx, aNaN);
107103

108-
#if __SIZEOF_LONG_DOUBLE__ == 16
109-
FPBits test2_4(0x00000000'00007FFF'00007800'08261001_u128);
110-
#elif __SIZEOF_LONG_DOUBLE__ == 12
104+
#if __SIZEOF_LONG_DOUBLE__ == 12
111105
FPBits test2_4(0x00007FFF'00007800'08261001_u96);
106+
#else
107+
FPBits test2_4(0x00000000'00007FFF'00007800'08261001_u128);
112108
#endif
113109
const T test2_4_val = test2_4.get_val();
114110
TEST_SPECIAL(cx, test2_4_val, 1, FE_INVALID);
@@ -117,37 +113,37 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
117113
// Exponent | Significand | Meaning
118114
// | Bits 63-62 | Bits 61-0 |
119115
// All Ones | 01 | Anything | Pseudo NaN, Value = SNaN
120-
#if __SIZEOF_LONG_DOUBLE__ == 16
121-
FPBits test3_1(0x00000000'00007FFF'40000000'00000000_u128);
122-
#elif __SIZEOF_LONG_DOUBLE__ == 12
116+
#if __SIZEOF_LONG_DOUBLE__ == 12
123117
FPBits test3_1(0x00007FFF'40000000'00000000_u96);
118+
#else
119+
FPBits test3_1(0x00000000'00007FFF'40000000'00000000_u128);
124120
#endif
125121
const T test3_1_val = test3_1.get_val();
126122
TEST_SPECIAL(cx, test3_1_val, 1, FE_INVALID);
127123
EXPECT_FP_EQ(cx, aNaN);
128124

129-
#if __SIZEOF_LONG_DOUBLE__ == 16
130-
FPBits test3_2(0x00000000'00007FFF'40000042'70000001_u128);
131-
#elif __SIZEOF_LONG_DOUBLE__ == 12
125+
#if __SIZEOF_LONG_DOUBLE__ == 12
132126
FPBits test3_2(0x00007FFF'40000042'70000001_u96);
127+
#else
128+
FPBits test3_2(0x00000000'00007FFF'40000042'70000001_u128);
133129
#endif
134130
const T test3_2_val = test3_2.get_val();
135131
TEST_SPECIAL(cx, test3_2_val, 1, FE_INVALID);
136132
EXPECT_FP_EQ(cx, aNaN);
137133

138-
#if __SIZEOF_LONG_DOUBLE__ == 16
139-
FPBits test3_3(0x00000000'00007FFF'40000000'08261001_u128);
140-
#elif __SIZEOF_LONG_DOUBLE__ == 12
134+
#if __SIZEOF_LONG_DOUBLE__ == 12
141135
FPBits test3_3(0x00007FFF'40000000'08261001_u96);
136+
#else
137+
FPBits test3_3(0x00000000'00007FFF'40000000'08261001_u128);
142138
#endif
143139
const T test3_3_val = test3_3.get_val();
144140
TEST_SPECIAL(cx, test3_3_val, 1, FE_INVALID);
145141
EXPECT_FP_EQ(cx, aNaN);
146142

147-
#if __SIZEOF_LONG_DOUBLE__ == 16
148-
FPBits test3_4(0x00000000'00007FFF'40007800'08261001_u128);
149-
#elif __SIZEOF_LONG_DOUBLE__ == 12
143+
#if __SIZEOF_LONG_DOUBLE__ == 12
150144
FPBits test3_4(0x00007FFF'40007800'08261001_u96);
145+
#else
146+
FPBits test3_4(0x00000000'00007FFF'40007800'08261001_u128);
151147
#endif
152148
const T test3_4_val = test3_4.get_val();
153149
TEST_SPECIAL(cx, test3_4_val, 1, FE_INVALID);
@@ -157,30 +153,30 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
157153
// | Bit 63 | Bits 62-0 |
158154
// All zeroes | One | Anything | Pseudo Denormal, Value =
159155
// | | | (−1)**s × m × 2**−16382
160-
#if __SIZEOF_LONG_DOUBLE__ == 16
161-
FPBits test4_1(0x00000000'00000000'80000000'00000000_u128);
162-
#elif __SIZEOF_LONG_DOUBLE__ == 12
156+
#if __SIZEOF_LONG_DOUBLE__ == 12
163157
FPBits test4_1(0x00000000'80000000'00000000_u96);
158+
#else
159+
FPBits test4_1(0x00000000'00000000'80000000'00000000_u128);
164160
#endif
165161
const T test4_1_val = test4_1.get_val();
166162
TEST_SPECIAL(cx, test4_1_val, 0, 0);
167163
EXPECT_FP_EQ(
168164
cx, FPBits::make_value(test4_1.get_explicit_mantissa(), 0).get_val());
169165

170-
#if __SIZEOF_LONG_DOUBLE__ == 16
171-
FPBits test4_2(0x00000000'00000000'80000042'70000001_u128);
172-
#elif __SIZEOF_LONG_DOUBLE__ == 12
166+
#if __SIZEOF_LONG_DOUBLE__ == 12
173167
FPBits test4_2(0x00000000'80000042'70000001_u96);
168+
#else
169+
FPBits test4_2(0x00000000'00000000'80000042'70000001_u128);
174170
#endif
175171
const T test4_2_val = test4_2.get_val();
176172
TEST_SPECIAL(cx, test4_2_val, 0, 0);
177173
EXPECT_FP_EQ(
178174
cx, FPBits::make_value(test4_2.get_explicit_mantissa(), 0).get_val());
179175

180-
#if __SIZEOF_LONG_DOUBLE__ == 16
181-
FPBits test4_3(0x00000000'00000000'80000000'08261001_u128);
182-
#elif __SIZEOF_LONG_DOUBLE__ == 12
176+
#if __SIZEOF_LONG_DOUBLE__ == 12
183177
FPBits test4_3(0x00000000'80000000'08261001_u96);
178+
#else
179+
FPBits test4_3(0x00000000'00000000'80000000'08261001_u128);
184180
#endif
185181
const T test4_3_val = test4_3.get_val();
186182
TEST_SPECIAL(cx, test4_3_val, 0, 0);
@@ -191,55 +187,55 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
191187
// | Bit 63 | Bits 62-0 |
192188
// All Other | Zero | Anything | Unnormal, Value = SNaN
193189
// Values | | |
194-
#if __SIZEOF_LONG_DOUBLE__ == 16
195-
FPBits test5_1(0x00000000'00000040'00000000'00000001_u128);
196-
#elif __SIZEOF_LONG_DOUBLE__ == 12
190+
#if __SIZEOF_LONG_DOUBLE__ == 12
197191
FPBits test5_1(0x00000040'00000000'00000001_u96);
192+
#else
193+
FPBits test5_1(0x00000000'00000040'00000000'00000001_u128);
198194
#endif
199195
const T test5_1_val = test5_1.get_val();
200196
TEST_SPECIAL(cx, test5_1_val, 1, FE_INVALID);
201197
EXPECT_FP_EQ(cx, aNaN);
202198

203-
#if __SIZEOF_LONG_DOUBLE__ == 16
204-
FPBits test5_2(0x00000000'00000230'00000042'70000001_u128);
205-
#elif __SIZEOF_LONG_DOUBLE__ == 12
199+
#if __SIZEOF_LONG_DOUBLE__ == 12
206200
FPBits test5_2(0x00000230'00000042'70000001_u96);
201+
#else
202+
FPBits test5_2(0x00000000'00000230'00000042'70000001_u128);
207203
#endif
208204
const T test5_2_val = test5_2.get_val();
209205
TEST_SPECIAL(cx, test5_2_val, 1, FE_INVALID);
210206
EXPECT_FP_EQ(cx, aNaN);
211207

212-
#if __SIZEOF_LONG_DOUBLE__ == 16
213-
FPBits test5_3(0x00000000'00000560'00000000'08261001_u128);
214-
#elif __SIZEOF_LONG_DOUBLE__ == 12
208+
#if __SIZEOF_LONG_DOUBLE__ == 12
215209
FPBits test5_3(0x00000560'00000000'08261001_u96);
210+
#else
211+
FPBits test5_3(0x00000000'00000560'00000000'08261001_u128);
216212
#endif
217213
const T test5_3_val = test5_3.get_val();
218214
TEST_SPECIAL(cx, test5_3_val, 1, FE_INVALID);
219215
EXPECT_FP_EQ(cx, aNaN);
220216

221-
#if __SIZEOF_LONG_DOUBLE__ == 16
222-
FPBits test5_4(0x00000000'00000780'00000028'16000000_u128);
223-
#elif __SIZEOF_LONG_DOUBLE__ == 12
217+
#if __SIZEOF_LONG_DOUBLE__ == 12
224218
FPBits test5_4(0x00000780'00000028'16000000_u96);
219+
#else
220+
FPBits test5_4(0x00000000'00000780'00000028'16000000_u128);
225221
#endif
226222
const T test5_4_val = test5_4.get_val();
227223
TEST_SPECIAL(cx, test5_4_val, 1, FE_INVALID);
228224
EXPECT_FP_EQ(cx, aNaN);
229225

230-
#if __SIZEOF_LONG_DOUBLE__ == 16
231-
FPBits test5_5(0x00000000'00000900'00000042'70000001_u128);
232-
#elif __SIZEOF_LONG_DOUBLE__ == 12
226+
#if __SIZEOF_LONG_DOUBLE__ == 12
233227
FPBits test5_5(0x00000900'00000042'70000001_u96);
228+
#else
229+
FPBits test5_5(0x00000000'00000900'00000042'70000001_u128);
234230
#endif
235231
const T test5_5_val = test5_5.get_val();
236232
TEST_SPECIAL(cx, test5_5_val, 1, FE_INVALID);
237233
EXPECT_FP_EQ(cx, aNaN);
238234

239-
#if __SIZEOF_LONG_DOUBLE__ == 16
240-
FPBits test5_6(0x00000000'00000AB0'00000000'08261001_u128);
241-
#elif __SIZEOF_LONG_DOUBLE__ == 12
235+
#if __SIZEOF_LONG_DOUBLE__ == 12
242236
FPBits test5_6(0x00000AB0'00000000'08261001_u96);
237+
#else
238+
FPBits test5_6(0x00000000'00000AB0'00000000'08261001_u128);
243239
#endif
244240
const T test5_6_val = test5_6.get_val();
245241
TEST_SPECIAL(cx, test5_6_val, 1, FE_INVALID);

0 commit comments

Comments
 (0)