usearch 2.10.3 → 2.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +1 -1
  2. package/binding.gyp +101 -0
  3. package/c/CMakeLists.txt +27 -0
  4. package/c/README.md +34 -0
  5. package/c/lib.cpp +362 -0
  6. package/c/test.c +382 -0
  7. package/c/usearch.h +356 -0
  8. package/cmake/clipp.cmake +7 -0
  9. package/cmake/config.cmake.in +15 -0
  10. package/cmake/emscripten.cmake +8 -0
  11. package/cmake/jemalloc.cmake +62 -0
  12. package/cmake/pkg-config.pc.in +4 -0
  13. package/cmake/usearchConfigVersion.cmake.in +20 -0
  14. package/cpp/CMakeLists.txt +14 -0
  15. package/cpp/README.md +161 -0
  16. package/cpp/bench.cpp +616 -0
  17. package/cpp/test.cpp +324 -0
  18. package/fp16/CMakeLists.txt +176 -0
  19. package/fp16/LICENSE +11 -0
  20. package/fp16/README.md +20 -0
  21. package/fp16/bench/alt-element.cc +89 -0
  22. package/fp16/bench/from-alt-array.cc +175 -0
  23. package/fp16/bench/from-ieee-array.cc +399 -0
  24. package/fp16/bench/ieee-element.cc +272 -0
  25. package/fp16/bench/to-alt-array.cc +91 -0
  26. package/fp16/bench/to-ieee-array.cc +303 -0
  27. package/fp16/cmake/DownloadGoogleBenchmark.cmake +15 -0
  28. package/fp16/cmake/DownloadGoogleTest.cmake +15 -0
  29. package/fp16/cmake/DownloadPSimd.cmake +15 -0
  30. package/fp16/configure.py +65 -0
  31. package/fp16/confu.yaml +8 -0
  32. package/fp16/include/fp16/__init__.py +0 -0
  33. package/fp16/include/fp16/avx.py +50 -0
  34. package/fp16/include/fp16/avx2.py +53 -0
  35. package/fp16/include/fp16/bitcasts.h +92 -0
  36. package/fp16/include/fp16/fp16.h +451 -0
  37. package/fp16/include/fp16/psimd.h +131 -0
  38. package/fp16/include/fp16.h +11 -0
  39. package/fp16/jni/Android.mk +6 -0
  40. package/fp16/jni/Application.mk +4 -0
  41. package/fp16/test/alt-from-fp32-value.cc +498 -0
  42. package/fp16/test/alt-to-fp32-bits.cc +263 -0
  43. package/fp16/test/alt-to-fp32-psimd.cc +145 -0
  44. package/fp16/test/alt-to-fp32-value.cc +348 -0
  45. package/fp16/test/alt-to-fp32x2-psimd.cc +245 -0
  46. package/fp16/test/bitcasts.cc +56 -0
  47. package/fp16/test/ieee-from-fp32-value.cc +523 -0
  48. package/fp16/test/ieee-to-fp32-bits.cc +333 -0
  49. package/fp16/test/ieee-to-fp32-psimd.cc +312 -0
  50. package/fp16/test/ieee-to-fp32-value.cc +420 -0
  51. package/fp16/test/ieee-to-fp32x2-psimd.cc +541 -0
  52. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +96 -0
  53. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +96 -0
  54. package/fp16/test/peachpy/stubs.py +38 -0
  55. package/fp16/test/tables.cc +530 -0
  56. package/fp16/test/tables.h +13 -0
  57. package/fp16/third-party/THHalf.h +92 -0
  58. package/fp16/third-party/eigen-half.h +170 -0
  59. package/fp16/third-party/float16-compressor.h +80 -0
  60. package/fp16/third-party/half.hpp +2916 -0
  61. package/fp16/third-party/npy-halffloat.h +328 -0
  62. package/include/usearch/index.hpp +3838 -0
  63. package/include/usearch/index_dense.hpp +2004 -0
  64. package/include/usearch/index_plugins.hpp +2255 -0
  65. package/javascript/dist-package-cjs.json +3 -0
  66. package/javascript/dist-package-esm.json +3 -0
  67. package/javascript/lib.cpp +350 -0
  68. package/javascript/node-gyp-build.d.ts +1 -0
  69. package/javascript/tsconfig-base.json +25 -0
  70. package/javascript/tsconfig-cjs.json +8 -0
  71. package/javascript/tsconfig-esm.json +8 -0
  72. package/javascript/usearch.test.js +84 -0
  73. package/javascript/usearch.ts +640 -0
  74. package/package.json +10 -3
  75. package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
  76. package/prebuilds/linux-arm64/usearch.node +0 -0
  77. package/prebuilds/linux-x64/usearch.node +0 -0
  78. package/prebuilds/win32-ia32/usearch.node +0 -0
  79. package/prebuilds/win32-x64/usearch.node +0 -0
  80. package/simsimd/.releaserc +87 -0
  81. package/simsimd/CONTRIBUTING.md +114 -0
  82. package/simsimd/Cargo.lock +709 -0
  83. package/simsimd/Cargo.toml +44 -0
  84. package/simsimd/LICENSE +201 -0
  85. package/simsimd/README.md +708 -0
  86. package/simsimd/binding.gyp +36 -0
  87. package/simsimd/build.rs +51 -0
  88. package/simsimd/c/lib.c +110 -0
  89. package/simsimd/include/simsimd/binary.h +258 -0
  90. package/simsimd/include/simsimd/dot.h +1237 -0
  91. package/simsimd/include/simsimd/geospatial.h +37 -0
  92. package/simsimd/include/simsimd/probability.h +563 -0
  93. package/simsimd/include/simsimd/simsimd.h +1129 -0
  94. package/simsimd/include/simsimd/spatial.h +1019 -0
  95. package/simsimd/include/simsimd/types.h +309 -0
  96. package/simsimd/javascript/bench.js +127 -0
  97. package/simsimd/javascript/dist-package-cjs.json +3 -0
  98. package/simsimd/javascript/dist-package-esm.json +3 -0
  99. package/simsimd/javascript/fallback.ts +203 -0
  100. package/simsimd/javascript/lib.c +107 -0
  101. package/simsimd/javascript/node-gyp-build.d.ts +1 -0
  102. package/simsimd/javascript/simsimd.ts +135 -0
  103. package/simsimd/javascript/test.mjs +179 -0
  104. package/simsimd/javascript/tsconfig-base.json +37 -0
  105. package/simsimd/javascript/tsconfig-cjs.json +8 -0
  106. package/simsimd/javascript/tsconfig-esm.json +8 -0
  107. package/simsimd/package-lock.json +1709 -0
  108. package/simsimd/package.json +61 -0
  109. package/simsimd/rust/benches/cosine.rs +27 -0
  110. package/simsimd/rust/benches/native.rs +30 -0
  111. package/simsimd/rust/benches/sqeuclidean.rs +27 -0
  112. package/simsimd/rust/lib.rs +778 -0
@@ -0,0 +1,263 @@
1
+ #include <gtest/gtest.h>
2
+
3
+ #include <cstdint>
4
+
5
+ #include <fp16.h>
6
+ #include <tables.h>
7
+
8
+
9
+ TEST(FP16_ALT_TO_FP32_BITS, normalized_powers_of_2) {
10
+ const uint16_t min_po2_f16 = UINT16_C(0x0400);
11
+ const uint16_t eighths_f16 = UINT16_C(0x3000);
12
+ const uint16_t quarter_f16 = UINT16_C(0x3400);
13
+ const uint16_t half_f16 = UINT16_C(0x3800);
14
+ const uint16_t one_f16 = UINT16_C(0x3C00);
15
+ const uint16_t two_f16 = UINT16_C(0x4000);
16
+ const uint16_t four_f16 = UINT16_C(0x4400);
17
+ const uint16_t eight_f16 = UINT16_C(0x4800);
18
+ const uint16_t sixteen_f16 = UINT16_C(0x4C00);
19
+ const uint16_t thirtytwo_f16 = UINT16_C(0x5000);
20
+ const uint16_t sixtyfour_f16 = UINT16_C(0x5400);
21
+ const uint16_t max_po2_f16 = UINT16_C(0x7C00);
22
+
23
+ const uint32_t min_po2_f32 = UINT32_C(0x38800000);
24
+ const uint32_t eighths_f32 = UINT32_C(0x3E000000);
25
+ const uint32_t quarter_f32 = UINT32_C(0x3E800000);
26
+ const uint32_t half_f32 = UINT32_C(0x3F000000);
27
+ const uint32_t one_f32 = UINT32_C(0x3F800000);
28
+ const uint32_t two_f32 = UINT32_C(0x40000000);
29
+ const uint32_t four_f32 = UINT32_C(0x40800000);
30
+ const uint32_t eight_f32 = UINT32_C(0x41000000);
31
+ const uint32_t sixteen_f32 = UINT32_C(0x41800000);
32
+ const uint32_t thirtytwo_f32 = UINT32_C(0x42000000);
33
+ const uint32_t sixtyfour_f32 = UINT32_C(0x42800000);
34
+ const uint32_t max_po2_f32 = UINT32_C(0x47800000);
35
+
36
+ EXPECT_EQ(min_po2_f32, fp16_alt_to_fp32_bits(min_po2_f16)) <<
37
+ std::hex << std::uppercase << std::setfill('0') <<
38
+ "F16 = 0x" << std::setw(4) << min_po2_f16 << ", " <<
39
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(min_po2_f16) << ", " <<
40
+ "F32 = 0x" << std::setw(8) << min_po2_f32;
41
+
42
+ EXPECT_EQ(eighths_f32, fp16_alt_to_fp32_bits(eighths_f16)) <<
43
+ std::hex << std::uppercase << std::setfill('0') <<
44
+ "F16 = 0x" << std::setw(4) << eighths_f16 << ", " <<
45
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(eighths_f16) << ", " <<
46
+ "F32 = 0x" << std::setw(8) << eighths_f32;
47
+
48
+ EXPECT_EQ(quarter_f32, fp16_alt_to_fp32_bits(quarter_f16)) <<
49
+ std::hex << std::uppercase << std::setfill('0') <<
50
+ "F16 = 0x" << std::setw(4) << quarter_f16 << ", " <<
51
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(quarter_f16) << ", " <<
52
+ "F32 = 0x" << std::setw(8) << quarter_f32;
53
+
54
+ EXPECT_EQ(half_f32, fp16_alt_to_fp32_bits(half_f16)) <<
55
+ std::hex << std::uppercase << std::setfill('0') <<
56
+ "F16 = 0x" << std::setw(4) << half_f16 << ", " <<
57
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(half_f16) << ", " <<
58
+ "F32 = 0x" << std::setw(8) << half_f32;
59
+
60
+ EXPECT_EQ(one_f32, fp16_alt_to_fp32_bits(one_f16)) <<
61
+ std::hex << std::uppercase << std::setfill('0') <<
62
+ "F16 = 0x" << std::setw(4) << one_f16 << ", " <<
63
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(one_f16) << ", " <<
64
+ "F32 = 0x" << std::setw(8) << one_f32;
65
+
66
+ EXPECT_EQ(two_f32, fp16_alt_to_fp32_bits(two_f16)) <<
67
+ std::hex << std::uppercase << std::setfill('0') <<
68
+ "F16 = 0x" << std::setw(4) << two_f16 << ", " <<
69
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(two_f16) << ", " <<
70
+ "F32 = 0x" << std::setw(8) << two_f32;
71
+
72
+ EXPECT_EQ(four_f32, fp16_alt_to_fp32_bits(four_f16)) <<
73
+ std::hex << std::uppercase << std::setfill('0') <<
74
+ "F16 = 0x" << std::setw(4) << four_f16 << ", " <<
75
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(four_f16) << ", " <<
76
+ "F32 = 0x" << std::setw(8) << four_f32;
77
+
78
+ EXPECT_EQ(eight_f32, fp16_alt_to_fp32_bits(eight_f16)) <<
79
+ std::hex << std::uppercase << std::setfill('0') <<
80
+ "F16 = 0x" << std::setw(4) << eight_f16 << ", " <<
81
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(eight_f16) << ", " <<
82
+ "F32 = 0x" << std::setw(8) << eight_f32;
83
+
84
+ EXPECT_EQ(sixteen_f32, fp16_alt_to_fp32_bits(sixteen_f16)) <<
85
+ std::hex << std::uppercase << std::setfill('0') <<
86
+ "F16 = 0x" << std::setw(4) << sixteen_f16 << ", " <<
87
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(sixteen_f16) << ", " <<
88
+ "F32 = 0x" << std::setw(8) << sixteen_f32;
89
+
90
+ EXPECT_EQ(thirtytwo_f32, fp16_alt_to_fp32_bits(thirtytwo_f16)) <<
91
+ std::hex << std::uppercase << std::setfill('0') <<
92
+ "F16 = 0x" << std::setw(4) << thirtytwo_f16 << ", " <<
93
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(thirtytwo_f16) << ", " <<
94
+ "F32 = 0x" << std::setw(8) << thirtytwo_f32;
95
+
96
+ EXPECT_EQ(sixtyfour_f32, fp16_alt_to_fp32_bits(sixtyfour_f16)) <<
97
+ std::hex << std::uppercase << std::setfill('0') <<
98
+ "F16 = 0x" << std::setw(4) << sixtyfour_f16 << ", " <<
99
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(sixtyfour_f16) << ", " <<
100
+ "F32 = 0x" << std::setw(8) << sixtyfour_f32;
101
+
102
+ EXPECT_EQ(max_po2_f32, fp16_alt_to_fp32_bits(max_po2_f16)) <<
103
+ std::hex << std::uppercase << std::setfill('0') <<
104
+ "F16 = 0x" << std::setw(4) << max_po2_f16 << ", " <<
105
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(max_po2_f16) << ", " <<
106
+ "F32 = 0x" << std::setw(8) << max_po2_f32;
107
+ }
108
+
109
+ TEST(FP16_ALT_TO_FP32_BITS, denormalized_powers_of_2) {
110
+ const uint16_t exp2_minus_15_f16 = UINT16_C(0x0200);
111
+ const uint16_t exp2_minus_16_f16 = UINT16_C(0x0100);
112
+ const uint16_t exp2_minus_17_f16 = UINT16_C(0x0080);
113
+ const uint16_t exp2_minus_18_f16 = UINT16_C(0x0040);
114
+ const uint16_t exp2_minus_19_f16 = UINT16_C(0x0020);
115
+ const uint16_t exp2_minus_20_f16 = UINT16_C(0x0010);
116
+ const uint16_t exp2_minus_21_f16 = UINT16_C(0x0008);
117
+ const uint16_t exp2_minus_22_f16 = UINT16_C(0x0004);
118
+ const uint16_t exp2_minus_23_f16 = UINT16_C(0x0002);
119
+ const uint16_t exp2_minus_24_f16 = UINT16_C(0x0001);
120
+
121
+ const uint32_t exp2_minus_15_f32 = UINT32_C(0x38000000);
122
+ const uint32_t exp2_minus_16_f32 = UINT32_C(0x37800000);
123
+ const uint32_t exp2_minus_17_f32 = UINT32_C(0x37000000);
124
+ const uint32_t exp2_minus_18_f32 = UINT32_C(0x36800000);
125
+ const uint32_t exp2_minus_19_f32 = UINT32_C(0x36000000);
126
+ const uint32_t exp2_minus_20_f32 = UINT32_C(0x35800000);
127
+ const uint32_t exp2_minus_21_f32 = UINT32_C(0x35000000);
128
+ const uint32_t exp2_minus_22_f32 = UINT32_C(0x34800000);
129
+ const uint32_t exp2_minus_23_f32 = UINT32_C(0x34000000);
130
+ const uint32_t exp2_minus_24_f32 = UINT32_C(0x33800000);
131
+
132
+ EXPECT_EQ(exp2_minus_15_f32, fp16_alt_to_fp32_bits(exp2_minus_15_f16)) <<
133
+ std::hex << std::uppercase << std::setfill('0') <<
134
+ "F16 = 0x" << std::setw(4) << exp2_minus_15_f16 << ", " <<
135
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_15_f16) << ", " <<
136
+ "F32 = 0x" << std::setw(8) << exp2_minus_15_f32;
137
+
138
+ EXPECT_EQ(exp2_minus_16_f32, fp16_alt_to_fp32_bits(exp2_minus_16_f16)) <<
139
+ std::hex << std::uppercase << std::setfill('0') <<
140
+ "F16 = 0x" << std::setw(4) << exp2_minus_16_f16 << ", " <<
141
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_16_f16) << ", " <<
142
+ "F32 = 0x" << std::setw(8) << exp2_minus_16_f32;
143
+
144
+ EXPECT_EQ(exp2_minus_17_f32, fp16_alt_to_fp32_bits(exp2_minus_17_f16)) <<
145
+ std::hex << std::uppercase << std::setfill('0') <<
146
+ "F16 = 0x" << std::setw(4) << exp2_minus_17_f16 << ", " <<
147
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_17_f16) << ", " <<
148
+ "F32 = 0x" << std::setw(8) << exp2_minus_17_f32;
149
+
150
+ EXPECT_EQ(exp2_minus_18_f32, fp16_alt_to_fp32_bits(exp2_minus_18_f16)) <<
151
+ std::hex << std::uppercase << std::setfill('0') <<
152
+ "F16 = 0x" << std::setw(4) << exp2_minus_18_f16 << ", " <<
153
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_18_f16) << ", " <<
154
+ "F32 = 0x" << std::setw(8) << exp2_minus_18_f32;
155
+
156
+ EXPECT_EQ(exp2_minus_19_f32, fp16_alt_to_fp32_bits(exp2_minus_19_f16)) <<
157
+ std::hex << std::uppercase << std::setfill('0') <<
158
+ "F16 = 0x" << std::setw(4) << exp2_minus_19_f16 << ", " <<
159
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_19_f16) << ", " <<
160
+ "F32 = 0x" << std::setw(8) << exp2_minus_19_f32;
161
+
162
+ EXPECT_EQ(exp2_minus_20_f32, fp16_alt_to_fp32_bits(exp2_minus_20_f16)) <<
163
+ std::hex << std::uppercase << std::setfill('0') <<
164
+ "F16 = 0x" << std::setw(4) << exp2_minus_20_f16 << ", " <<
165
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_20_f16) << ", " <<
166
+ "F32 = 0x" << std::setw(8) << exp2_minus_20_f32;
167
+
168
+ EXPECT_EQ(exp2_minus_21_f32, fp16_alt_to_fp32_bits(exp2_minus_21_f16)) <<
169
+ std::hex << std::uppercase << std::setfill('0') <<
170
+ "F16 = 0x" << std::setw(4) << exp2_minus_21_f16 << ", " <<
171
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_21_f16) << ", " <<
172
+ "F32 = 0x" << std::setw(8) << exp2_minus_21_f32;
173
+
174
+ EXPECT_EQ(exp2_minus_22_f32, fp16_alt_to_fp32_bits(exp2_minus_22_f16)) <<
175
+ std::hex << std::uppercase << std::setfill('0') <<
176
+ "F16 = 0x" << std::setw(4) << exp2_minus_22_f16 << ", " <<
177
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_22_f16) << ", " <<
178
+ "F32 = 0x" << std::setw(8) << exp2_minus_22_f32;
179
+
180
+ EXPECT_EQ(exp2_minus_23_f32, fp16_alt_to_fp32_bits(exp2_minus_23_f16)) <<
181
+ std::hex << std::uppercase << std::setfill('0') <<
182
+ "F16 = 0x" << std::setw(4) << exp2_minus_23_f16 << ", " <<
183
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_23_f16) << ", " <<
184
+ "F32 = 0x" << std::setw(8) << exp2_minus_23_f32;
185
+
186
+ EXPECT_EQ(exp2_minus_24_f32, fp16_alt_to_fp32_bits(exp2_minus_24_f16)) <<
187
+ std::hex << std::uppercase << std::setfill('0') <<
188
+ "F16 = 0x" << std::setw(4) << exp2_minus_24_f16 << ", " <<
189
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(exp2_minus_24_f16) << ", " <<
190
+ "F32 = 0x" << std::setw(8) << exp2_minus_24_f32;
191
+ }
192
+
193
+ TEST(FP16_ALT_TO_FP32_BITS, zero) {
194
+ const uint16_t positive_zero_f16 = UINT16_C(0x0000);
195
+ const uint16_t negative_zero_f16 = UINT16_C(0x8000);
196
+
197
+ const uint32_t positive_zero_f32 = UINT32_C(0x00000000);
198
+ const uint32_t negative_zero_f32 = UINT32_C(0x80000000);
199
+
200
+ EXPECT_EQ(positive_zero_f32, fp16_alt_to_fp32_bits(positive_zero_f16)) <<
201
+ std::hex << std::uppercase << std::setfill('0') <<
202
+ "F16 = 0x" << std::setw(4) << positive_zero_f16 << ", " <<
203
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(positive_zero_f16) << ", " <<
204
+ "F32 = 0x" << std::setw(8) << positive_zero_f32;
205
+
206
+ EXPECT_EQ(negative_zero_f32, fp16_alt_to_fp32_bits(negative_zero_f16)) <<
207
+ std::hex << std::uppercase << std::setfill('0') <<
208
+ "F16 = 0x" << std::setw(4) << negative_zero_f16 << ", " <<
209
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(negative_zero_f16) << ", " <<
210
+ "F32 = 0x" << std::setw(8) << negative_zero_f32;
211
+ }
212
+
213
+ TEST(FP16_ALT_TO_FP32_BITS, positive_normalized_values) {
214
+ const uint32_t exponentBias = 15;
215
+ for (int32_t e = -14; e <= 16; e++) {
216
+ for (uint16_t h = 0; h < 0x0400; h++) {
217
+ const uint16_t fp16 = h + ((uint16_t) (e + exponentBias) << 10);
218
+ const uint32_t fp32 = fp16::normalizedValues[h] + ((uint32_t) e << 23);
219
+ EXPECT_EQ(fp32, fp16_alt_to_fp32_bits(fp16)) <<
220
+ std::hex << std::uppercase << std::setfill('0') <<
221
+ "F16 = 0x" << std::setw(4) << fp16 << ", " <<
222
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16) << ", " <<
223
+ "F32 = 0x" << std::setw(8) << fp32;
224
+ }
225
+ }
226
+ }
227
+
228
+ TEST(FP16_ALT_TO_FP32_BITS, negative_normalized_values) {
229
+ const uint32_t exponentBias = 15;
230
+ for (int32_t e = -14; e <= 16; e++) {
231
+ for (uint16_t h = 0; h < 0x0400; h++) {
232
+ const uint16_t fp16 = (h + ((uint16_t) (e + exponentBias) << 10)) ^ UINT16_C(0x8000);
233
+ const uint32_t fp32 = (fp16::normalizedValues[h] + ((uint32_t) e << 23)) ^ UINT32_C(0x80000000);
234
+ EXPECT_EQ(fp32, fp16_alt_to_fp32_bits(fp16)) <<
235
+ std::hex << std::uppercase << std::setfill('0') <<
236
+ "F16 = 0x" << std::setw(4) << fp16 << ", " <<
237
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16) << ", " <<
238
+ "F32 = 0x" << std::setw(8) << fp32;
239
+ }
240
+ }
241
+ }
242
+
243
+ TEST(FP16_ALT_TO_FP32_BITS, positive_denormalized_values) {
244
+ for (uint16_t h = 0; h < 0x0400; h++) {
245
+ EXPECT_EQ(fp16::denormalizedValues[h], fp16_alt_to_fp32_bits(h)) <<
246
+ std::hex << std::uppercase << std::setfill('0') <<
247
+ "F16 = 0x" << std::setw(4) << h << ", " <<
248
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(h) << ", " <<
249
+ "F32 = 0x" << std::setw(8) << fp16::denormalizedValues[h];
250
+ }
251
+ }
252
+
253
+ TEST(FP16_ALT_TO_FP32_BITS, negative_denormalized_values) {
254
+ for (uint16_t h = 0; h < 0x0400; h++) {
255
+ const uint16_t fp16 = h ^ UINT16_C(0x8000);
256
+ const uint32_t fp32 = fp16::denormalizedValues[h] ^ UINT32_C(0x80000000);
257
+ EXPECT_EQ(fp32, fp16_alt_to_fp32_bits(fp16)) <<
258
+ std::hex << std::uppercase << std::setfill('0') <<
259
+ "F16 = 0x" << std::setw(4) << fp16 << ", " <<
260
+ "F32(F16) = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16) << ", " <<
261
+ "F32 = 0x" << std::setw(8) << fp32;
262
+ }
263
+ }
@@ -0,0 +1,145 @@
1
+ #include <gtest/gtest.h>
2
+
3
+ #include <cstdint>
4
+
5
+ #include <fp16.h>
6
+ #include <fp16/psimd.h>
7
+
8
+
9
+ TEST(FP16_ALT_TO_FP32_PSIMD, positive_normalized_values) {
10
+ const uint32_t exponentBias = 15;
11
+ for (int32_t e = -14; e <= 16; e++) {
12
+ for (uint16_t h = 0; h < 0x0400; h += 4) {
13
+ const psimd_u16 fp16 = {
14
+ (uint16_t) (h + ((e + exponentBias) << 10) + 0),
15
+ (uint16_t) (h + ((e + exponentBias) << 10) + 1),
16
+ (uint16_t) (h + ((e + exponentBias) << 10) + 2),
17
+ (uint16_t) (h + ((e + exponentBias) << 10) + 3),
18
+ };
19
+ const psimd_u32 fp32 = (psimd_u32) fp16_alt_to_fp32_psimd(fp16);
20
+
21
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[0]), fp32[0]) <<
22
+ std::hex << std::uppercase << std::setfill('0') <<
23
+ "F16 = 0x" << std::setw(4) << fp16[0] << ", " <<
24
+ "F32(F16) = 0x" << std::setw(8) << fp32[0] << ", " <<
25
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[0]);
26
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[1]), fp32[1]) <<
27
+ std::hex << std::uppercase << std::setfill('0') <<
28
+ "F16 = 0x" << std::setw(4) << fp16[1] << ", " <<
29
+ "F32(F16) = 0x" << std::setw(8) << fp32[1] << ", " <<
30
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[1]);
31
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[2]), fp32[2]) <<
32
+ std::hex << std::uppercase << std::setfill('0') <<
33
+ "F16 = 0x" << std::setw(4) << fp16[2] << ", " <<
34
+ "F32(F16) = 0x" << std::setw(8) << fp32[2] << ", " <<
35
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[2]);
36
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[3]), fp32[3]) <<
37
+ std::hex << std::uppercase << std::setfill('0') <<
38
+ "F16 = 0x" << std::setw(4) << fp16[3] << ", " <<
39
+ "F32(F16) = 0x" << std::setw(8) << fp32[3] << ", " <<
40
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[3]);
41
+ }
42
+ }
43
+ }
44
+
45
+ TEST(FP16_ALT_TO_FP32_PSIMD, negative_normalized_values) {
46
+ const uint32_t exponentBias = 15;
47
+ for (int32_t e = -14; e <= 16; e++) {
48
+ for (uint16_t h = 0; h < 0x0400; h += 4) {
49
+ const psimd_u16 fp16 = {
50
+ (uint16_t) (h + ((e + exponentBias) << 10) + 0x8000),
51
+ (uint16_t) (h + ((e + exponentBias) << 10) + 0x8001),
52
+ (uint16_t) (h + ((e + exponentBias) << 10) + 0x8002),
53
+ (uint16_t) (h + ((e + exponentBias) << 10) + 0x8003),
54
+ };
55
+ const psimd_u32 fp32 = (psimd_u32) fp16_alt_to_fp32_psimd(fp16);
56
+
57
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[0]), fp32[0]) <<
58
+ std::hex << std::uppercase << std::setfill('0') <<
59
+ "F16 = 0x" << std::setw(4) << fp16[0] << ", " <<
60
+ "F32(F16) = 0x" << std::setw(8) << fp32[0] << ", " <<
61
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[0]);
62
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[1]), fp32[1]) <<
63
+ std::hex << std::uppercase << std::setfill('0') <<
64
+ "F16 = 0x" << std::setw(4) << fp16[1] << ", " <<
65
+ "F32(F16) = 0x" << std::setw(8) << fp32[1] << ", " <<
66
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[1]);
67
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[2]), fp32[2]) <<
68
+ std::hex << std::uppercase << std::setfill('0') <<
69
+ "F16 = 0x" << std::setw(4) << fp16[2] << ", " <<
70
+ "F32(F16) = 0x" << std::setw(8) << fp32[2] << ", " <<
71
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[2]);
72
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[3]), fp32[3]) <<
73
+ std::hex << std::uppercase << std::setfill('0') <<
74
+ "F16 = 0x" << std::setw(4) << fp16[3] << ", " <<
75
+ "F32(F16) = 0x" << std::setw(8) << fp32[3] << ", " <<
76
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[3]);
77
+ }
78
+ }
79
+ }
80
+
81
+ TEST(FP16_ALT_TO_FP32_PSIMD, positive_denormalized_values) {
82
+ for (uint16_t h = 0; h < 0x0400; h += 4) {
83
+ const psimd_u16 fp16 = {
84
+ (uint16_t) (h + 0),
85
+ (uint16_t) (h + 1),
86
+ (uint16_t) (h + 2),
87
+ (uint16_t) (h + 3),
88
+ };
89
+ const psimd_u32 fp32 = (psimd_u32) fp16_alt_to_fp32_psimd(fp16);
90
+
91
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[0]), fp32[0]) <<
92
+ std::hex << std::uppercase << std::setfill('0') <<
93
+ "F16 = 0x" << std::setw(4) << fp16[0] << ", " <<
94
+ "F32(F16) = 0x" << std::setw(8) << fp32[0] << ", " <<
95
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[0]);
96
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[1]), fp32[1]) <<
97
+ std::hex << std::uppercase << std::setfill('0') <<
98
+ "F16 = 0x" << std::setw(4) << fp16[1] << ", " <<
99
+ "F32(F16) = 0x" << std::setw(8) << fp32[1] << ", " <<
100
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[1]);
101
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[2]), fp32[2]) <<
102
+ std::hex << std::uppercase << std::setfill('0') <<
103
+ "F16 = 0x" << std::setw(4) << fp16[2] << ", " <<
104
+ "F32(F16) = 0x" << std::setw(8) << fp32[2] << ", " <<
105
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[2]);
106
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[3]), fp32[3]) <<
107
+ std::hex << std::uppercase << std::setfill('0') <<
108
+ "F16 = 0x" << std::setw(4) << fp16[3] << ", " <<
109
+ "F32(F16) = 0x" << std::setw(8) << fp32[3] << ", " <<
110
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[3]);
111
+ }
112
+ }
113
+
114
+ TEST(FP16_ALT_TO_FP32_PSIMD, negative_denormalized_values) {
115
+ for (uint16_t h = 0; h < 0x0400; h += 4) {
116
+ const psimd_u16 fp16 = {
117
+ (uint16_t) (h + 0x8000),
118
+ (uint16_t) (h + 0x8001),
119
+ (uint16_t) (h + 0x8002),
120
+ (uint16_t) (h + 0x8003),
121
+ };
122
+ const psimd_u32 fp32 = (psimd_u32) fp16_alt_to_fp32_psimd(fp16);
123
+
124
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[0]), fp32[0]) <<
125
+ std::hex << std::uppercase << std::setfill('0') <<
126
+ "F16 = 0x" << std::setw(4) << fp16[0] << ", " <<
127
+ "F32(F16) = 0x" << std::setw(8) << fp32[0] << ", " <<
128
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[0]);
129
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[1]), fp32[1]) <<
130
+ std::hex << std::uppercase << std::setfill('0') <<
131
+ "F16 = 0x" << std::setw(4) << fp16[1] << ", " <<
132
+ "F32(F16) = 0x" << std::setw(8) << fp32[1] << ", " <<
133
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[1]);
134
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[2]), fp32[2]) <<
135
+ std::hex << std::uppercase << std::setfill('0') <<
136
+ "F16 = 0x" << std::setw(4) << fp16[2] << ", " <<
137
+ "F32(F16) = 0x" << std::setw(8) << fp32[2] << ", " <<
138
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[2]);
139
+ EXPECT_EQ(fp16_alt_to_fp32_bits(fp16[3]), fp32[3]) <<
140
+ std::hex << std::uppercase << std::setfill('0') <<
141
+ "F16 = 0x" << std::setw(4) << fp16[3] << ", " <<
142
+ "F32(F16) = 0x" << std::setw(8) << fp32[3] << ", " <<
143
+ "F32 = 0x" << std::setw(8) << fp16_alt_to_fp32_bits(fp16[3]);
144
+ }
145
+ }