9
9
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
10
10
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
11
11
12
+ #include " src/__support/FPUtil/FPBits.h"
12
13
#include " test/UnitTest/FPMatcher.h"
13
14
#include " test/UnitTest/Test.h"
14
15
@@ -28,6 +29,8 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
28
29
29
30
public:
30
31
typedef T (*CanonicalizeFunc)(T *, T *);
32
+ using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
33
+ using StorageType = typename FPBits::StorageType;
31
34
32
35
void testSpecialNumbers (CanonicalizeFunc f) {
33
36
T cx;
@@ -45,6 +48,104 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
45
48
EXPECT_EQ (cx, -aNaN);
46
49
}
47
50
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
+
48
149
void testRegularNumbers (CanonicalizeFunc func) {
49
150
T cx;
50
151
TEST_REGULAR (cx, T (1.0 ), 0 );
@@ -71,4 +172,10 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
71
172
testRegularNumbers (&func); \
72
173
}
73
174
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
+
74
181
#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
0 commit comments