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