1*5f32b710SXin Li #include <gtest/gtest.h>
2*5f32b710SXin Li
3*5f32b710SXin Li #include <cstdint>
4*5f32b710SXin Li
5*5f32b710SXin Li #include <fp16.h>
6*5f32b710SXin Li #include "tables.h"
7*5f32b710SXin Li
8*5f32b710SXin Li
TEST(FP16_ALT_TO_FP32_BITS,normalized_powers_of_2)9*5f32b710SXin Li TEST(FP16_ALT_TO_FP32_BITS, normalized_powers_of_2) {
10*5f32b710SXin Li const uint16_t min_po2_f16 = UINT16_C(0x0400);
11*5f32b710SXin Li const uint16_t eighths_f16 = UINT16_C(0x3000);
12*5f32b710SXin Li const uint16_t quarter_f16 = UINT16_C(0x3400);
13*5f32b710SXin Li const uint16_t half_f16 = UINT16_C(0x3800);
14*5f32b710SXin Li const uint16_t one_f16 = UINT16_C(0x3C00);
15*5f32b710SXin Li const uint16_t two_f16 = UINT16_C(0x4000);
16*5f32b710SXin Li const uint16_t four_f16 = UINT16_C(0x4400);
17*5f32b710SXin Li const uint16_t eight_f16 = UINT16_C(0x4800);
18*5f32b710SXin Li const uint16_t sixteen_f16 = UINT16_C(0x4C00);
19*5f32b710SXin Li const uint16_t thirtytwo_f16 = UINT16_C(0x5000);
20*5f32b710SXin Li const uint16_t sixtyfour_f16 = UINT16_C(0x5400);
21*5f32b710SXin Li const uint16_t max_po2_f16 = UINT16_C(0x7C00);
22*5f32b710SXin Li
23*5f32b710SXin Li const uint32_t min_po2_f32 = UINT32_C(0x38800000);
24*5f32b710SXin Li const uint32_t eighths_f32 = UINT32_C(0x3E000000);
25*5f32b710SXin Li const uint32_t quarter_f32 = UINT32_C(0x3E800000);
26*5f32b710SXin Li const uint32_t half_f32 = UINT32_C(0x3F000000);
27*5f32b710SXin Li const uint32_t one_f32 = UINT32_C(0x3F800000);
28*5f32b710SXin Li const uint32_t two_f32 = UINT32_C(0x40000000);
29*5f32b710SXin Li const uint32_t four_f32 = UINT32_C(0x40800000);
30*5f32b710SXin Li const uint32_t eight_f32 = UINT32_C(0x41000000);
31*5f32b710SXin Li const uint32_t sixteen_f32 = UINT32_C(0x41800000);
32*5f32b710SXin Li const uint32_t thirtytwo_f32 = UINT32_C(0x42000000);
33*5f32b710SXin Li const uint32_t sixtyfour_f32 = UINT32_C(0x42800000);
34*5f32b710SXin Li const uint32_t max_po2_f32 = UINT32_C(0x47800000);
35*5f32b710SXin Li
36*5f32b710SXin Li EXPECT_EQ(min_po2_f32, fp16_alt_to_fp32_bits(min_po2_f16)) <<
37*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
38*5f32b710SXin Li "F16 = 0x" << std::setw(4) << min_po2_f16 << ", " <<
39*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(min_po2_f16) << ", " <<
40*5f32b710SXin Li "F32 = 0x" << std::setw(8) << min_po2_f32;
41*5f32b710SXin Li
42*5f32b710SXin Li EXPECT_EQ(eighths_f32, fp16_alt_to_fp32_bits(eighths_f16)) <<
43*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
44*5f32b710SXin Li "F16 = 0x" << std::setw(4) << eighths_f16 << ", " <<
45*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(eighths_f16) << ", " <<
46*5f32b710SXin Li "F32 = 0x" << std::setw(8) << eighths_f32;
47*5f32b710SXin Li
48*5f32b710SXin Li EXPECT_EQ(quarter_f32, fp16_alt_to_fp32_bits(quarter_f16)) <<
49*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
50*5f32b710SXin Li "F16 = 0x" << std::setw(4) << quarter_f16 << ", " <<
51*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(quarter_f16) << ", " <<
52*5f32b710SXin Li "F32 = 0x" << std::setw(8) << quarter_f32;
53*5f32b710SXin Li
54*5f32b710SXin Li EXPECT_EQ(half_f32, fp16_alt_to_fp32_bits(half_f16)) <<
55*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
56*5f32b710SXin Li "F16 = 0x" << std::setw(4) << half_f16 << ", " <<
57*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(half_f16) << ", " <<
58*5f32b710SXin Li "F32 = 0x" << std::setw(8) << half_f32;
59*5f32b710SXin Li
60*5f32b710SXin Li EXPECT_EQ(one_f32, fp16_alt_to_fp32_bits(one_f16)) <<
61*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
62*5f32b710SXin Li "F16 = 0x" << std::setw(4) << one_f16 << ", " <<
63*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(one_f16) << ", " <<
64*5f32b710SXin Li "F32 = 0x" << std::setw(8) << one_f32;
65*5f32b710SXin Li
66*5f32b710SXin Li EXPECT_EQ(two_f32, fp16_alt_to_fp32_bits(two_f16)) <<
67*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
68*5f32b710SXin Li "F16 = 0x" << std::setw(4) << two_f16 << ", " <<
69*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(two_f16) << ", " <<
70*5f32b710SXin Li "F32 = 0x" << std::setw(8) << two_f32;
71*5f32b710SXin Li
72*5f32b710SXin Li EXPECT_EQ(four_f32, fp16_alt_to_fp32_bits(four_f16)) <<
73*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
74*5f32b710SXin Li "F16 = 0x" << std::setw(4) << four_f16 << ", " <<
75*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(four_f16) << ", " <<
76*5f32b710SXin Li "F32 = 0x" << std::setw(8) << four_f32;
77*5f32b710SXin Li
78*5f32b710SXin Li EXPECT_EQ(eight_f32, fp16_alt_to_fp32_bits(eight_f16)) <<
79*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
80*5f32b710SXin Li "F16 = 0x" << std::setw(4) << eight_f16 << ", " <<
81*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(eight_f16) << ", " <<
82*5f32b710SXin Li "F32 = 0x" << std::setw(8) << eight_f32;
83*5f32b710SXin Li
84*5f32b710SXin Li EXPECT_EQ(sixteen_f32, fp16_alt_to_fp32_bits(sixteen_f16)) <<
85*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
86*5f32b710SXin Li "F16 = 0x" << std::setw(4) << sixteen_f16 << ", " <<
87*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(sixteen_f16) << ", " <<
88*5f32b710SXin Li "F32 = 0x" << std::setw(8) << sixteen_f32;
89*5f32b710SXin Li
90*5f32b710SXin Li EXPECT_EQ(thirtytwo_f32, fp16_alt_to_fp32_bits(thirtytwo_f16)) <<
91*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
92*5f32b710SXin Li "F16 = 0x" << std::setw(4) << thirtytwo_f16 << ", " <<
93*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(thirtytwo_f16) << ", " <<
94*5f32b710SXin Li "F32 = 0x" << std::setw(8) << thirtytwo_f32;
95*5f32b710SXin Li
96*5f32b710SXin Li EXPECT_EQ(sixtyfour_f32, fp16_alt_to_fp32_bits(sixtyfour_f16)) <<
97*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
98*5f32b710SXin Li "F16 = 0x" << std::setw(4) << sixtyfour_f16 << ", " <<
99*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(sixtyfour_f16) << ", " <<
100*5f32b710SXin Li "F32 = 0x" << std::setw(8) << sixtyfour_f32;
101*5f32b710SXin Li
102*5f32b710SXin Li EXPECT_EQ(max_po2_f32, fp16_alt_to_fp32_bits(max_po2_f16)) <<
103*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
104*5f32b710SXin Li "F16 = 0x" << std::setw(4) << max_po2_f16 << ", " <<
105*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(max_po2_f16) << ", " <<
106*5f32b710SXin Li "F32 = 0x" << std::setw(8) << max_po2_f32;
107*5f32b710SXin Li }
108*5f32b710SXin Li
TEST(FP16_ALT_TO_FP32_BITS,denormalized_powers_of_2)109*5f32b710SXin Li TEST(FP16_ALT_TO_FP32_BITS, denormalized_powers_of_2) {
110*5f32b710SXin Li const uint16_t exp2_minus_15_f16 = UINT16_C(0x0200);
111*5f32b710SXin Li const uint16_t exp2_minus_16_f16 = UINT16_C(0x0100);
112*5f32b710SXin Li const uint16_t exp2_minus_17_f16 = UINT16_C(0x0080);
113*5f32b710SXin Li const uint16_t exp2_minus_18_f16 = UINT16_C(0x0040);
114*5f32b710SXin Li const uint16_t exp2_minus_19_f16 = UINT16_C(0x0020);
115*5f32b710SXin Li const uint16_t exp2_minus_20_f16 = UINT16_C(0x0010);
116*5f32b710SXin Li const uint16_t exp2_minus_21_f16 = UINT16_C(0x0008);
117*5f32b710SXin Li const uint16_t exp2_minus_22_f16 = UINT16_C(0x0004);
118*5f32b710SXin Li const uint16_t exp2_minus_23_f16 = UINT16_C(0x0002);
119*5f32b710SXin Li const uint16_t exp2_minus_24_f16 = UINT16_C(0x0001);
120*5f32b710SXin Li
121*5f32b710SXin Li const uint32_t exp2_minus_15_f32 = UINT32_C(0x38000000);
122*5f32b710SXin Li const uint32_t exp2_minus_16_f32 = UINT32_C(0x37800000);
123*5f32b710SXin Li const uint32_t exp2_minus_17_f32 = UINT32_C(0x37000000);
124*5f32b710SXin Li const uint32_t exp2_minus_18_f32 = UINT32_C(0x36800000);
125*5f32b710SXin Li const uint32_t exp2_minus_19_f32 = UINT32_C(0x36000000);
126*5f32b710SXin Li const uint32_t exp2_minus_20_f32 = UINT32_C(0x35800000);
127*5f32b710SXin Li const uint32_t exp2_minus_21_f32 = UINT32_C(0x35000000);
128*5f32b710SXin Li const uint32_t exp2_minus_22_f32 = UINT32_C(0x34800000);
129*5f32b710SXin Li const uint32_t exp2_minus_23_f32 = UINT32_C(0x34000000);
130*5f32b710SXin Li const uint32_t exp2_minus_24_f32 = UINT32_C(0x33800000);
131*5f32b710SXin Li
132*5f32b710SXin Li EXPECT_EQ(exp2_minus_15_f32, fp16_alt_to_fp32_bits(exp2_minus_15_f16)) <<
133*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
134*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_15_f16 << ", " <<
135*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_15_f16) << ", " <<
136*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_15_f32;
137*5f32b710SXin Li
138*5f32b710SXin Li EXPECT_EQ(exp2_minus_16_f32, fp16_alt_to_fp32_bits(exp2_minus_16_f16)) <<
139*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
140*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_16_f16 << ", " <<
141*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_16_f16) << ", " <<
142*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_16_f32;
143*5f32b710SXin Li
144*5f32b710SXin Li EXPECT_EQ(exp2_minus_17_f32, fp16_alt_to_fp32_bits(exp2_minus_17_f16)) <<
145*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
146*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_17_f16 << ", " <<
147*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_17_f16) << ", " <<
148*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_17_f32;
149*5f32b710SXin Li
150*5f32b710SXin Li EXPECT_EQ(exp2_minus_18_f32, fp16_alt_to_fp32_bits(exp2_minus_18_f16)) <<
151*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
152*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_18_f16 << ", " <<
153*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_18_f16) << ", " <<
154*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_18_f32;
155*5f32b710SXin Li
156*5f32b710SXin Li EXPECT_EQ(exp2_minus_19_f32, fp16_alt_to_fp32_bits(exp2_minus_19_f16)) <<
157*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
158*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_19_f16 << ", " <<
159*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_19_f16) << ", " <<
160*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_19_f32;
161*5f32b710SXin Li
162*5f32b710SXin Li EXPECT_EQ(exp2_minus_20_f32, fp16_alt_to_fp32_bits(exp2_minus_20_f16)) <<
163*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
164*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_20_f16 << ", " <<
165*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_20_f16) << ", " <<
166*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_20_f32;
167*5f32b710SXin Li
168*5f32b710SXin Li EXPECT_EQ(exp2_minus_21_f32, fp16_alt_to_fp32_bits(exp2_minus_21_f16)) <<
169*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
170*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_21_f16 << ", " <<
171*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_21_f16) << ", " <<
172*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_21_f32;
173*5f32b710SXin Li
174*5f32b710SXin Li EXPECT_EQ(exp2_minus_22_f32, fp16_alt_to_fp32_bits(exp2_minus_22_f16)) <<
175*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
176*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_22_f16 << ", " <<
177*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_22_f16) << ", " <<
178*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_22_f32;
179*5f32b710SXin Li
180*5f32b710SXin Li EXPECT_EQ(exp2_minus_23_f32, fp16_alt_to_fp32_bits(exp2_minus_23_f16)) <<
181*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
182*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_23_f16 << ", " <<
183*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_23_f16) << ", " <<
184*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_23_f32;
185*5f32b710SXin Li
186*5f32b710SXin Li EXPECT_EQ(exp2_minus_24_f32, fp16_alt_to_fp32_bits(exp2_minus_24_f16)) <<
187*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
188*5f32b710SXin Li "F16 = 0x" << std::setw(4) << exp2_minus_24_f16 << ", " <<
189*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_24_f16) << ", " <<
190*5f32b710SXin Li "F32 = 0x" << std::setw(8) << exp2_minus_24_f32;
191*5f32b710SXin Li }
192*5f32b710SXin Li
TEST(FP16_ALT_TO_FP32_BITS,zero)193*5f32b710SXin Li TEST(FP16_ALT_TO_FP32_BITS, zero) {
194*5f32b710SXin Li const uint16_t positive_zero_f16 = UINT16_C(0x0000);
195*5f32b710SXin Li const uint16_t negative_zero_f16 = UINT16_C(0x8000);
196*5f32b710SXin Li
197*5f32b710SXin Li const uint32_t positive_zero_f32 = UINT32_C(0x00000000);
198*5f32b710SXin Li const uint32_t negative_zero_f32 = UINT32_C(0x80000000);
199*5f32b710SXin Li
200*5f32b710SXin Li EXPECT_EQ(positive_zero_f32, fp16_alt_to_fp32_bits(positive_zero_f16)) <<
201*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
202*5f32b710SXin Li "F16 = 0x" << std::setw(4) << positive_zero_f16 << ", " <<
203*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(positive_zero_f16) << ", " <<
204*5f32b710SXin Li "F32 = 0x" << std::setw(8) << positive_zero_f32;
205*5f32b710SXin Li
206*5f32b710SXin Li EXPECT_EQ(negative_zero_f32, fp16_alt_to_fp32_bits(negative_zero_f16)) <<
207*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
208*5f32b710SXin Li "F16 = 0x" << std::setw(4) << negative_zero_f16 << ", " <<
209*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(negative_zero_f16) << ", " <<
210*5f32b710SXin Li "F32 = 0x" << std::setw(8) << negative_zero_f32;
211*5f32b710SXin Li }
212*5f32b710SXin Li
TEST(FP16_ALT_TO_FP32_BITS,positive_normalized_values)213*5f32b710SXin Li TEST(FP16_ALT_TO_FP32_BITS, positive_normalized_values) {
214*5f32b710SXin Li const uint32_t exponentBias = 15;
215*5f32b710SXin Li for (int32_t e = -14; e <= 16; e++) {
216*5f32b710SXin Li for (uint16_t h = 0; h < 0x0400; h++) {
217*5f32b710SXin Li const uint16_t fp16 = h + ((uint16_t) (e + exponentBias) << 10);
218*5f32b710SXin Li const uint32_t fp32 = fp16::normalizedValues[h] + ((uint32_t) e << 23);
219*5f32b710SXin Li EXPECT_EQ(fp32, fp16_alt_to_fp32_bits(fp16)) <<
220*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
221*5f32b710SXin Li "F16 = 0x" << std::setw(4) << fp16 << ", " <<
222*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16) << ", " <<
223*5f32b710SXin Li "F32 = 0x" << std::setw(8) << fp32;
224*5f32b710SXin Li }
225*5f32b710SXin Li }
226*5f32b710SXin Li }
227*5f32b710SXin Li
TEST(FP16_ALT_TO_FP32_BITS,negative_normalized_values)228*5f32b710SXin Li TEST(FP16_ALT_TO_FP32_BITS, negative_normalized_values) {
229*5f32b710SXin Li const uint32_t exponentBias = 15;
230*5f32b710SXin Li for (int32_t e = -14; e <= 16; e++) {
231*5f32b710SXin Li for (uint16_t h = 0; h < 0x0400; h++) {
232*5f32b710SXin Li const uint16_t fp16 = (h + ((uint16_t) (e + exponentBias) << 10)) ^ UINT16_C(0x8000);
233*5f32b710SXin Li const uint32_t fp32 = (fp16::normalizedValues[h] + ((uint32_t) e << 23)) ^ UINT32_C(0x80000000);
234*5f32b710SXin Li EXPECT_EQ(fp32, fp16_alt_to_fp32_bits(fp16)) <<
235*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
236*5f32b710SXin Li "F16 = 0x" << std::setw(4) << fp16 << ", " <<
237*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16) << ", " <<
238*5f32b710SXin Li "F32 = 0x" << std::setw(8) << fp32;
239*5f32b710SXin Li }
240*5f32b710SXin Li }
241*5f32b710SXin Li }
242*5f32b710SXin Li
TEST(FP16_ALT_TO_FP32_BITS,positive_denormalized_values)243*5f32b710SXin Li TEST(FP16_ALT_TO_FP32_BITS, positive_denormalized_values) {
244*5f32b710SXin Li for (uint16_t h = 0; h < 0x0400; h++) {
245*5f32b710SXin Li EXPECT_EQ(fp16::denormalizedValues[h], fp16_alt_to_fp32_bits(h)) <<
246*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
247*5f32b710SXin Li "F16 = 0x" << std::setw(4) << h << ", " <<
248*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(h) << ", " <<
249*5f32b710SXin Li "F32 = 0x" << std::setw(8) << fp16::denormalizedValues[h];
250*5f32b710SXin Li }
251*5f32b710SXin Li }
252*5f32b710SXin Li
TEST(FP16_ALT_TO_FP32_BITS,negative_denormalized_values)253*5f32b710SXin Li TEST(FP16_ALT_TO_FP32_BITS, negative_denormalized_values) {
254*5f32b710SXin Li for (uint16_t h = 0; h < 0x0400; h++) {
255*5f32b710SXin Li const uint16_t fp16 = h ^ UINT16_C(0x8000);
256*5f32b710SXin Li const uint32_t fp32 = fp16::denormalizedValues[h] ^ UINT32_C(0x80000000);
257*5f32b710SXin Li EXPECT_EQ(fp32, fp16_alt_to_fp32_bits(fp16)) <<
258*5f32b710SXin Li std::hex << std::uppercase << std::setfill('0') <<
259*5f32b710SXin Li "F16 = 0x" << std::setw(4) << fp16 << ", " <<
260*5f32b710SXin Li "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16) << ", " <<
261*5f32b710SXin Li "F32 = 0x" << std::setw(8) << fp32;
262*5f32b710SXin Li }
263*5f32b710SXin Li }
264