Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Unified Diff: test/cctest/wasm/test-run-wasm-simd.cc

Issue 2711863002: Implement remaining Boolean SIMD operations on ARM. (Closed)
Patch Set: Fix macro assembler test. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-macro-assembler-arm.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-run-wasm-simd.cc
diff --git a/test/cctest/wasm/test-run-wasm-simd.cc b/test/cctest/wasm/test-run-wasm-simd.cc
index 4fd1d63b18e511414ccb071624aa3c5912340936..7d0bc8a8a65f07e8b8ba802480e11cf1b7919e1e 100644
--- a/test/cctest/wasm/test-run-wasm-simd.cc
+++ b/test/cctest/wasm/test-run-wasm-simd.cc
@@ -213,6 +213,11 @@ T Not(T a) {
}
template <typename T>
+T LogicalNot(T a) {
+ return a == 0 ? 1 : 0;
+}
+
+template <typename T>
T Sqrt(T a) {
return std::sqrt(a);
}
@@ -1340,6 +1345,182 @@ WASM_EXEC_COMPILED_TEST(I8x16ShrU) {
WASM_SIMD_SELECT_TEST(32x4)
WASM_SIMD_SELECT_TEST(16x8)
WASM_SIMD_SELECT_TEST(8x16)
+
+// Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer
+// result. Use relational ops on numeric vectors to create the boolean vector
+// test inputs. Test inputs with all true, all false, one true, and one false.
+#define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \
+ WASM_EXEC_TEST(ReductionTest##lanes) { \
+ FLAG_wasm_simd_prototype = true; \
+ WasmRunner<int32_t> r(kExecuteCompiled); \
+ byte zero = r.AllocateLocal(kWasmS128); \
+ byte one_one = r.AllocateLocal(kWasmS128); \
+ byte reduced = r.AllocateLocal(kWasmI32); \
+ BUILD(r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Eq, \
+ WASM_GET_LOCAL(zero), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Ne, \
+ WASM_GET_LOCAL(zero), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Eq, \
+ WASM_GET_LOCAL(zero), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Ne, \
+ WASM_GET_LOCAL(zero), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_SET_LOCAL(one_one, \
+ WASM_SIMD_I##format##_REPLACE_LANE( \
+ lanes - 1, WASM_GET_LOCAL(zero), WASM_ONE)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Eq, \
+ WASM_GET_LOCAL(one_one), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Ne, \
+ WASM_GET_LOCAL(one_one), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Eq, \
+ WASM_GET_LOCAL(one_one), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_SET_LOCAL( \
+ reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
+ WASM_SIMD_BINOP(kExprI##format##Ne, \
+ WASM_GET_LOCAL(one_one), \
+ WASM_GET_LOCAL(zero)))), \
+ WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
+ WASM_RETURN1(WASM_ZERO)), \
+ WASM_ONE); \
+ CHECK_EQ(1, r.Call()); \
+ }
+
+WASM_SIMD_BOOL_REDUCTION_TEST(32x4, 4)
+WASM_SIMD_BOOL_REDUCTION_TEST(16x8, 8)
+WASM_SIMD_BOOL_REDUCTION_TEST(8x16, 16)
+
+#define WASM_SIMD_UNOP_HELPER(format, lanes, lane_size) \
+ void RunS1x##lanes##UnOpTest(WasmOpcode simd_op, \
+ Int##lane_size##UnOp expected_op) { \
+ FLAG_wasm_simd_prototype = true; \
+ WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \
+ byte a = 0; \
+ byte expected = 1; \
+ byte zero = r.AllocateLocal(kWasmS128); \
+ byte simd = r.AllocateLocal(kWasmS128); \
+ BUILD( \
+ r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
+ WASM_SET_LOCAL(simd, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(a))), \
+ WASM_SET_LOCAL( \
+ simd, \
+ WASM_SIMD_MATERIALIZE_BOOLS( \
+ format, WASM_SIMD_UNOP( \
+ simd_op, WASM_SIMD_BINOP(kExprI##format##Ne, \
+ WASM_GET_LOCAL(simd), \
+ WASM_GET_LOCAL(zero))))), \
+ WASM_SIMD_CHECK_SPLAT##lanes(I##format, simd, I32, expected), \
+ WASM_ONE); \
+ \
+ for (int i = 0; i <= 1; i++) { \
+ CHECK_EQ(1, r.Call(i, expected_op(i))); \
+ } \
+ }
+WASM_SIMD_UNOP_HELPER(32x4, 4, 32);
+WASM_SIMD_UNOP_HELPER(16x8, 8, 16);
+WASM_SIMD_UNOP_HELPER(8x16, 16, 8);
+#undef WASM_SIMD_UNOP_HELPER
+
+WASM_EXEC_COMPILED_TEST(S1x4Not) { RunS1x4UnOpTest(kExprS1x4Not, LogicalNot); }
+
+WASM_EXEC_COMPILED_TEST(S1x8Not) { RunS1x8UnOpTest(kExprS1x8Not, LogicalNot); }
+
+WASM_EXEC_COMPILED_TEST(S1x16Not) {
+ RunS1x16UnOpTest(kExprS1x16Not, LogicalNot);
+}
+
+#define WASM_SIMD_BINOP_HELPER(format, lanes, lane_size) \
+ void RunS1x##lanes##BinOpTest(WasmOpcode simd_op, \
+ Int##lane_size##BinOp expected_op) { \
+ FLAG_wasm_simd_prototype = true; \
+ WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); \
+ byte a = 0; \
+ byte b = 1; \
+ byte expected = 2; \
+ byte zero = r.AllocateLocal(kWasmS128); \
+ byte simd0 = r.AllocateLocal(kWasmS128); \
+ byte simd1 = r.AllocateLocal(kWasmS128); \
+ BUILD( \
+ r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
+ WASM_SET_LOCAL(simd0, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(a))), \
+ WASM_SET_LOCAL(simd1, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(b))), \
+ WASM_SET_LOCAL( \
+ simd1, \
+ WASM_SIMD_MATERIALIZE_BOOLS( \
+ format, \
+ WASM_SIMD_BINOP( \
+ simd_op, \
+ WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(simd0), \
+ WASM_GET_LOCAL(zero)), \
+ WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(simd1), \
+ WASM_GET_LOCAL(zero))))), \
+ WASM_SIMD_CHECK_SPLAT##lanes(I##format, simd1, I32, expected), \
+ WASM_ONE); \
+ \
+ for (int i = 0; i <= 1; i++) { \
+ for (int j = 0; j <= 1; j++) { \
+ CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); \
+ } \
+ } \
+ }
+
+WASM_SIMD_BINOP_HELPER(32x4, 4, 32);
+WASM_SIMD_BINOP_HELPER(16x8, 8, 16);
+WASM_SIMD_BINOP_HELPER(8x16, 16, 8);
+#undef WASM_SIMD_BINOP_HELPER
+
+WASM_EXEC_COMPILED_TEST(S1x4And) { RunS1x4BinOpTest(kExprS1x4And, And); }
+
+WASM_EXEC_COMPILED_TEST(S1x4Or) { RunS1x4BinOpTest(kExprS1x4Or, Or); }
+
+WASM_EXEC_COMPILED_TEST(S1x4Xor) { RunS1x4BinOpTest(kExprS1x4Xor, Xor); }
+
+WASM_EXEC_COMPILED_TEST(S1x8And) { RunS1x8BinOpTest(kExprS1x8And, And); }
+
+WASM_EXEC_COMPILED_TEST(S1x8Or) { RunS1x8BinOpTest(kExprS1x8Or, Or); }
+
+WASM_EXEC_COMPILED_TEST(S1x8Xor) { RunS1x8BinOpTest(kExprS1x8Xor, Xor); }
+
+WASM_EXEC_COMPILED_TEST(S1x16And) { RunS1x16BinOpTest(kExprS1x16And, And); }
+
+WASM_EXEC_COMPILED_TEST(S1x16Or) { RunS1x16BinOpTest(kExprS1x16Or, Or); }
+
+WASM_EXEC_COMPILED_TEST(S1x16Xor) { RunS1x16BinOpTest(kExprS1x16Xor, Xor); }
+
#endif // V8_TARGET_ARCH_ARM
#if SIMD_LOWERING_TARGET
« no previous file with comments | « test/cctest/test-macro-assembler-arm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698