VRND microkernels using native WAsm SIMD instructions
PiperOrigin-RevId: 394716216
diff --git a/eval/f32-roundne.cc b/eval/f32-roundne.cc
index ec60904..a491cf7 100644
--- a/eval/f32-roundne.cc
+++ b/eval/f32-roundne.cc
@@ -1259,6 +1259,212 @@
}
#endif // XNN_ARCH_WASMSIMD
+#if XNN_ARCH_WASMSIMD
+ TEST(ROUNDNE__WASMSIMD_NATIVE, positive_normal) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x00000000); n < UINT32_C(0x4B800000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(n + i);
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, negative_normal) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x80000000); n < UINT32_C(0xCB800000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(n + i);
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, positive_integral) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x4B800000); n < UINT32_C(0x7F800000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(n + i);
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, negative_integral) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0xCB800000); n < UINT32_C(0xFF800000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(n + i);
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, positive_infinity) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ std::fill(inputs.begin(), inputs.end(), +std::numeric_limits<float>::infinity());
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[0]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[0]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[0])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[0]);
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, negative_infinity) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ std::fill(inputs.begin(), inputs.end(), -std::numeric_limits<float>::infinity());
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[0]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[0]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[0])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[0]);
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, positive_qnan) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x7FC00000); n < UINT32_C(0x80000000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(n + i);
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, negative_qnan) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x7FC00000); n < UINT32_C(0x80000000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(UINT32_C(0x80000000) | (n + i));
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, positive_snan) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x7F800000); n < UINT32_C(0x7FC00000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(std::max<uint32_t>(n + i, UINT32_C(0x7F800001)));
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output & UINT32_C(0xFFBFFFFF), fp32_to_bits(outputs[i]) & UINT32_C(0xFFBFFFFF))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, negative_snan) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x7F800000); n < UINT32_C(0x7FC00000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(UINT32_C(0x80000000) | std::max<uint32_t>(n + i, UINT32_C(0x7F800001)));
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output & UINT32_C(0xFFBFFFFF), fp32_to_bits(outputs[i]) & UINT32_C(0xFFBFFFFF))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, positive_snan_to_qnan) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x7F800000); n < UINT32_C(0x7FC00000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(std::max<uint32_t>(n + i, UINT32_C(0x7F800001)));
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+
+ TEST(ROUNDNE__WASMSIMD_NATIVE, negative_snan_to_qnan) {
+ std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
+ std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);
+ for (uint32_t n = UINT32_C(0x7F800000); n < UINT32_C(0x7FC00000); n += kBlockSize) {
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ inputs[i] = fp32_from_bits(UINT32_C(0x80000000) | std::max<uint32_t>(n + i, UINT32_C(0x7F800001)));
+ }
+ xnn_math_f32_roundne__wasmsimd_native(kBlockSize * sizeof(float), inputs.data(), outputs.data());
+ for (uint32_t i = 0; i < kBlockSize; i++) {
+ const uint32_t reference_output = fp32_to_bits(std::nearbyint(inputs[i]));
+ ASSERT_EQ(reference_output, fp32_to_bits(outputs[i]))
+ << "input = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(inputs[i])
+ << ", reference = 0x" << std::hex << std::setw(8) << std::setfill('0') << reference_output
+ << ", optimized = 0x" << std::hex << std::setw(8) << std::setfill('0') << fp32_to_bits(outputs[i]);
+ }
+ }
+ }
+#endif // XNN_ARCH_WASMSIMD
+
TEST(ROUNDNE__SCALAR_ADDSUB, positive_normal) {
std::vector<float, AlignedAllocator<float, 64>> inputs(kBlockSize);
std::vector<float, AlignedAllocator<float, 64>> outputs(kBlockSize);