Skip to content

Commit d4ff844

Browse files
committed
Added more tests
1 parent 8503cd7 commit d4ff844

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
1111

12+
#include "src/__support/FPUtil/FPBits.h"
1213
#include "test/UnitTest/FPMatcher.h"
1314
#include "test/UnitTest/Test.h"
1415

@@ -28,6 +29,8 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
2829

2930
public:
3031
typedef T (*CanonicalizeFunc)(T *, T *);
32+
using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
33+
using StorageType = typename FPBits::StorageType;
3134

3235
void testSpecialNumbers(CanonicalizeFunc f) {
3336
T cx;
@@ -45,6 +48,104 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
4548
EXPECT_EQ(cx, -aNaN);
4649
}
4750

51+
void testX64_80SpecialNumbers(CanonicalizeFunc f) {
52+
T cx;
53+
// Exponent | Significand | Meaning
54+
// | Bits 63-62 | Bits 61-0 |
55+
// All Ones | 00 | Zero | Pseudo Infinity, Value = Infinty
56+
57+
FPBits test1(UInt128(0x7FFF) << 64 + UInt128(0x0000000000000000));
58+
TEST_SPECIAL(cx, test1.get_val(), 0, 0);
59+
EXPECT_EQ(cx, inf);
60+
61+
// Exponent | Significand | Meaning
62+
// | Bits 63-62 | Bits 61-0 |
63+
// All Ones | 00 | Non-Zero | Pseudo NaN, Value = SNaN
64+
65+
FPBits test2_1(UInt128(0x7FFF) << 64 + UInt128(0x0000000000000001));
66+
TEST_SPECIAL(cx, test2_1.get_val(), 1, FE_INVALID);
67+
EXPECT_EQ(cx, aNaN);
68+
69+
FPBits test2_2(UInt128(0x7FFF) << 64 + UInt128(0x0000004270000001));
70+
TEST_SPECIAL(cx, test2_2.get_val(), 1, FE_INVALID);
71+
EXPECT_EQ(cx, aNaN);
72+
73+
FPBits test2_3(UInt128(0x7FFF) << 64 + UInt128(0x0000000008261001));
74+
TEST_SPECIAL(cx, test2_3.get_val(), 1, FE_INVALID);
75+
EXPECT_EQ(cx, aNaN);
76+
77+
// Exponent | Significand | Meaning
78+
// | Bits 63-62 | Bits 61-0 |
79+
// All Ones | 01 | Anything | Pseudo NaN, Value = SNaN
80+
81+
FPBits test3_1(UInt128(0x7FFF) << 64 + UInt128(0x4000000000000000));
82+
TEST_SPECIAL(cx, test3_1.get_val(), 1, FE_INVALID);
83+
EXPECT_EQ(cx, aNaN);
84+
85+
FPBits test3_2(UInt128(0x7FFF) << 64 + UInt128(0x4000004270000001));
86+
TEST_SPECIAL(cx, test3_2.get_val(), 1, FE_INVALID);
87+
EXPECT_EQ(cx, aNaN);
88+
89+
FPBits test3_3(UInt128(0x7FFF) << 64 + UInt128(0x4000000008261001));
90+
TEST_SPECIAL(cx, test3_3.get_val(), 1, FE_INVALID);
91+
EXPECT_EQ(cx, aNaN);
92+
93+
// Exponent | Significand | Meaning
94+
// | Bit 63 | Bits 62-0 |
95+
// All zeroes | One | Anything | Pseudo Denormal, Value =
96+
// | | | (−1)**s × m × 2**−16382
97+
98+
FPBits test4_1(UInt128(0x0000) << 64 + UInt128(0x8000000000000000));
99+
TEST_SPECIAL(cx, test4_1.get_val(), 0, 0);
100+
EXPECT_EQ(
101+
cx, FPBits::make_value(test4_1.get_explicit_mantissa(), 1).get_val(););
102+
103+
FPBits test4_2(UInt128(0x0000) << 64 + UInt128(0x8000004270000001));
104+
TEST_SPECIAL(cx, test4_2.get_val(), 0, 0);
105+
EXPECT_EQ(
106+
cx, FPBits::make_value(test4_2.get_explicit_mantissa(), 1).get_val(););
107+
108+
FPBits test4_3(UInt128(0x0000) << 64 + UInt128(0x8000000008261001));
109+
TEST_SPECIAL(cx, test4_3.get_val(), 0, 0);
110+
EXPECT_EQ(
111+
cx, FPBits::make_value(test4_3.get_explicit_mantissa(), 1).get_val(););
112+
113+
// Exponent | Significand | Meaning
114+
// | Bit 63 | Bits 62-0 |
115+
// All Other | Zero | Anything | Unnormal, Value =
116+
// Values | | | (−1)**s × m × 2**−16382
117+
118+
FPBits test5_1(UInt128(0x0001) << 64 + UInt128(0x0000000000000000));
119+
TEST_SPECIAL(cx, test5_1.get_val(), 0, 0);
120+
EXPECT_EQ(
121+
cx, FPBits::make_value(test5_1.get_explicit_mantissa(), 1).get_val(););
122+
123+
FPBits test5_2(UInt128(0x0001) << 64 + UInt128(0x0000004270000001));
124+
TEST_SPECIAL(cx, test5_2.get_val(), 0, 0);
125+
EXPECT_EQ(
126+
cx, FPBits::make_value(test5_2.get_explicit_mantissa(), 1).get_val(););
127+
128+
FPBits test5_3(UInt128(0x0001) << 64 + UInt128(0x0000000008261001));
129+
TEST_SPECIAL(cx, test5_3.get_val(), 0, 0);
130+
EXPECT_EQ(
131+
cx, FPBits::make_value(test5_3.get_explicit_mantissa(), 1).get_val(););
132+
133+
FPBits test5_4(UInt128(0x0012) << 64 + UInt128(0x0000000000000000));
134+
TEST_SPECIAL(cx, test5_4.get_val(), 0, 0);
135+
EXPECT_EQ(
136+
cx, FPBits::make_value(test5_4.get_explicit_mantissa(), 1).get_val(););
137+
138+
FPBits test5_5(UInt128(0x0027) << 64 + UInt128(0x0000004270000001));
139+
TEST_SPECIAL(cx, test5_5.get_val(), 0, 0);
140+
EXPECT_EQ(
141+
cx, FPBits::make_value(test5_5.get_explicit_mantissa(), 1).get_val(););
142+
143+
FPBits test5_6(UInt128(0x0034) << 64 + UInt128(0x0000000008261001));
144+
TEST_SPECIAL(cx, test5_6.get_val(), 0, 0);
145+
EXPECT_EQ(
146+
cx, FPBits::make_value(test5_6.get_explicit_mantissa(), 1).get_val(););
147+
}
148+
48149
void testRegularNumbers(CanonicalizeFunc func) {
49150
T cx;
50151
TEST_REGULAR(cx, T(1.0), 0);
@@ -71,4 +172,10 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
71172
testRegularNumbers(&func); \
72173
}
73174

175+
#define X86_80_SPECIAL_CANONICALIZE_TEST(T, func) \
176+
using LlvmLibcCanonicalizeTest = CanonicalizeTest<T>; \
177+
TEST_F(LlvmLibcCanonicalizeTest, X64_80SpecialNumbers) { \
178+
testX64_80SpecialNumbers(&func); \
179+
}
180+
74181
#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H

libc/test/src/math/smoke/canonicalizel_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@
1111
#include "src/math/canonicalizel.h"
1212

1313
LIST_CANONICALIZE_TESTS(long double, LIBC_NAMESPACE::canonicalizel)
14+
15+
#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
16+
17+
X86_80_SPECIAL_CANONICALIZE_TEST(long double, LIBC_NAMESPACE::canonicalizel)
18+
19+
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80

0 commit comments

Comments
 (0)