1 #include <gtest/gtest.h>
2
3 #include <cstdint>
4
5 #include <fp16.h>
6
7
8 extern "C" void fp16_alt_xmm_to_fp32_ymm_peachpy__avx2(const uint16_t* fp16, uint32_t* fp32);
9 const size_t vector_elements = 8;
10
11
TEST(FP16_ALT_XMM_TO_FP32_YMM,positive_normalized_values)12 TEST(FP16_ALT_XMM_TO_FP32_YMM, positive_normalized_values) {
13 const uint32_t exponentBias = 15;
14 for (int32_t e = -14; e <= 16; e++) {
15 for (uint16_t h = 0; h < 0x0400; h += vector_elements) {
16 uint16_t fp16[vector_elements];
17 for (size_t i = 0; i < vector_elements; i++) {
18 fp16[i] = h + ((e + exponentBias) << 10) + i;
19 }
20 uint32_t fp32[vector_elements];
21 fp16_alt_xmm_to_fp32_ymm_peachpy__avx2(fp16, fp32);
22
23 for (size_t i = 0; i < vector_elements; i++) {
24 EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[i]), fp32[i]) <<
25 std::hex << std::uppercase << std::setfill('0') <<
26 "F16 = 0x" << std::setw(4) << fp16[i] << ", " <<
27 "F32(F16) = 0x" << std::setw(8) << fp32[i] << ", " <<
28 "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[i]) <<
29 ", lane " << i << "/" << vector_elements;
30 }
31 }
32 }
33 }
34
TEST(FP16_ALT_XMM_TO_FP32_YMM,negative_normalized_values)35 TEST(FP16_ALT_XMM_TO_FP32_YMM, negative_normalized_values) {
36 const uint32_t exponentBias = 15;
37 for (int32_t e = -14; e <= 16; e++) {
38 for (uint16_t h = 0; h < 0x0400; h += vector_elements) {
39 uint16_t fp16[vector_elements];
40 for (size_t i = 0; i < vector_elements; i++) {
41 fp16[i] = 0x8000 + h + ((e + exponentBias) << 10) + i;
42 }
43 uint32_t fp32[vector_elements];
44 fp16_alt_xmm_to_fp32_ymm_peachpy__avx2(fp16, fp32);
45
46 for (size_t i = 0; i < vector_elements; i++) {
47 EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[i]), fp32[i]) <<
48 std::hex << std::uppercase << std::setfill('0') <<
49 "F16 = 0x" << std::setw(4) << fp16[i] << ", " <<
50 "F32(F16) = 0x" << std::setw(8) << fp32[i] << ", " <<
51 "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[i]) <<
52 ", lane " << i << "/" << vector_elements;
53 }
54 }
55 }
56 }
57
TEST(FP16_ALT_XMM_TO_FP32_YMM,positive_denormalized_values)58 TEST(FP16_ALT_XMM_TO_FP32_YMM, positive_denormalized_values) {
59 for (uint16_t h = 0; h < 0x0400; h += vector_elements) {
60 uint16_t fp16[vector_elements];
61 for (size_t i = 0; i < vector_elements; i++) {
62 fp16[i] = h + i;
63 }
64 uint32_t fp32[vector_elements];
65 fp16_alt_xmm_to_fp32_ymm_peachpy__avx2(fp16, fp32);
66
67 for (size_t i = 0; i < vector_elements; i++) {
68 EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[i]), fp32[i]) <<
69 std::hex << std::uppercase << std::setfill('0') <<
70 "F16 = 0x" << std::setw(4) << fp16[i] << ", " <<
71 "F32(F16) = 0x" << std::setw(8) << fp32[i] << ", " <<
72 "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[i]) <<
73 ", lane " << i << "/" << vector_elements;
74 }
75 }
76 }
77
TEST(FP16_ALT_XMM_TO_FP32_YMM,negative_denormalized_values)78 TEST(FP16_ALT_XMM_TO_FP32_YMM, negative_denormalized_values) {
79 for (uint16_t h = 0; h < 0x0400; h += vector_elements) {
80 uint16_t fp16[vector_elements];
81 for (size_t i = 0; i < vector_elements; i++) {
82 fp16[i] = 0x8000 + h + i;
83 }
84 uint32_t fp32[vector_elements];
85 fp16_alt_xmm_to_fp32_ymm_peachpy__avx2(fp16, fp32);
86
87 for (size_t i = 0; i < vector_elements; i++) {
88 EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[i]), fp32[i]) <<
89 std::hex << std::uppercase << std::setfill('0') <<
90 "F16 = 0x" << std::setw(4) << fp16[i] << ", " <<
91 "F32(F16) = 0x" << std::setw(8) << fp32[i] << ", " <<
92 "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[i]) <<
93 ", lane " << i << "/" << vector_elements;
94 }
95 }
96 }
97