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 62caa6176e63774946a3d938d4f9f733f8820581..32fa65331e3f62c9122c77f21f5aceb9337dc3a5 100644 |
--- a/test/cctest/wasm/test-run-wasm-simd.cc |
+++ b/test/cctest/wasm/test-run-wasm-simd.cc |
@@ -187,6 +187,26 @@ T UnsignedSubSaturate(T a, T b) { |
return Clamp<UnsignedT>(UnsignedWiden(a) - UnsignedWiden(b)); |
} |
+template <typename T> |
+T And(T a, T b) { |
+ return a & b; |
+} |
+ |
+template <typename T> |
+T Or(T a, T b) { |
+ return a | b; |
+} |
+ |
+template <typename T> |
+T Xor(T a, T b) { |
+ return a ^ b; |
+} |
+ |
+template <typename T> |
+T Not(T a) { |
+ return ~a; |
+} |
+ |
} // namespace |
// TODO(gdeepti): These are tests using sample values to verify functional |
@@ -264,11 +284,29 @@ T UnsignedSubSaturate(T a, T b) { |
#define WASM_SIMD_CHECK_SPLAT4_F32(TYPE, value, lv) \ |
WASM_SIMD_CHECK4_F32(TYPE, value, lv, lv, lv, lv) |
-#define WASM_SIMD_UNOP(opcode, x) x, kSimdPrefix, static_cast<byte>(opcode) |
-#define WASM_SIMD_BINOP(opcode, x, y) \ |
- x, y, kSimdPrefix, static_cast<byte>(opcode) |
-#define WASM_SIMD_SHIFT_OP(opcode, x, shift) \ |
- x, kSimdPrefix, static_cast<byte>(opcode), static_cast<byte>(shift) |
+#define TO_BYTE(val) static_cast<byte>(val) |
+#define WASM_SIMD_OP(op) kSimdPrefix, TO_BYTE(op) |
+#define WASM_SIMD_UNOP(op, x) x, WASM_SIMD_OP(op) |
+#define WASM_SIMD_BINOP(op, x, y) x, y, WASM_SIMD_OP(op) |
+#define WASM_SIMD_SHIFT_OP(op, shift, x) x, WASM_SIMD_OP(op), TO_BYTE(shift) |
+#define WASM_SIMD_SELECT(format, x, y, z) \ |
+ x, y, z, WASM_SIMD_OP(kExprS##format##Select) |
+ |
+#define WASM_SIMD_I16x8_SPLAT(x) x, WASM_SIMD_OP(kExprI16x8Splat) |
+#define WASM_SIMD_I16x8_EXTRACT_LANE(lane, x) \ |
+ x, WASM_SIMD_OP(kExprI16x8ExtractLane), TO_BYTE(lane) |
+#define WASM_SIMD_I16x8_REPLACE_LANE(lane, x, y) \ |
+ x, y, WASM_SIMD_OP(kExprI16x8ReplaceLane), TO_BYTE(lane) |
+#define WASM_SIMD_I8x16_SPLAT(x) x, WASM_SIMD_OP(kExprI8x16Splat) |
+#define WASM_SIMD_I8x16_EXTRACT_LANE(lane, x) \ |
+ x, WASM_SIMD_OP(kExprI8x16ExtractLane), TO_BYTE(lane) |
+#define WASM_SIMD_I8x16_REPLACE_LANE(lane, x, y) \ |
+ x, y, WASM_SIMD_OP(kExprI8x16ReplaceLane), TO_BYTE(lane) |
+ |
+#define WASM_SIMD_F32x4_FROM_I32x4(x) x, WASM_SIMD_OP(kExprF32x4SConvertI32x4) |
+#define WASM_SIMD_F32x4_FROM_U32x4(x) x, WASM_SIMD_OP(kExprF32x4UConvertI32x4) |
+#define WASM_SIMD_I32x4_FROM_F32x4(x) x, WASM_SIMD_OP(kExprI32x4SConvertF32x4) |
+#define WASM_SIMD_U32x4_FROM_F32x4(x) x, WASM_SIMD_OP(kExprI32x4UConvertF32x4) |
#if V8_TARGET_ARCH_ARM |
WASM_EXEC_TEST(F32x4Splat) { |
@@ -334,34 +372,6 @@ WASM_EXEC_TEST(F32x4FromInt32x4) { |
} |
} |
-WASM_EXEC_TEST(S32x4Select) { |
- FLAG_wasm_simd_prototype = true; |
- WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
- byte val1 = 0; |
- byte val2 = 1; |
- byte mask = r.AllocateLocal(kWasmS128); |
- byte src1 = r.AllocateLocal(kWasmS128); |
- byte src2 = r.AllocateLocal(kWasmS128); |
- BUILD(r, |
- |
- WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_SPLAT(WASM_ZERO)), |
- WASM_SET_LOCAL(src1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(val1))), |
- WASM_SET_LOCAL(src2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(val2))), |
- WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_REPLACE_LANE( |
- 1, WASM_GET_LOCAL(mask), WASM_I32V(-1))), |
- WASM_SET_LOCAL(mask, WASM_SIMD_I32x4_REPLACE_LANE( |
- 2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), |
- WASM_SET_LOCAL(mask, WASM_SIMD_S32x4_SELECT(WASM_GET_LOCAL(mask), |
- WASM_GET_LOCAL(src1), |
- WASM_GET_LOCAL(src2))), |
- WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val2, 0), |
- WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val1, 1), |
- WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val1, 2), |
- WASM_SIMD_CHECK_LANE(I32x4, mask, I32, val2, 3), WASM_ONE); |
- |
- CHECK_EQ(1, r.Call(0x1234, 0x5678)); |
-} |
- |
void RunF32x4UnOpTest(WasmOpcode simd_op, FloatUnOp expected_op) { |
FLAG_wasm_simd_prototype = true; |
WasmRunner<int32_t, float, float> r(kExecuteCompiled); |
@@ -753,6 +763,8 @@ void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) { |
} |
WASM_EXEC_TEST(I32x4Neg) { RunI32x4UnOpTest(kExprI32x4Neg, Negate); } |
+ |
+WASM_EXEC_TEST(S128Not) { RunI32x4UnOpTest(kExprS128Not, Not); } |
#endif // V8_TARGET_ARCH_ARM |
void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { |
@@ -821,6 +833,12 @@ WASM_EXEC_TEST(Ui32x4LessEqual) { |
RunI32x4BinOpTest(kExprI32x4LeU, UnsignedLessEqual); |
} |
+WASM_EXEC_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } |
+ |
+WASM_EXEC_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } |
+ |
+WASM_EXEC_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } |
+ |
void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, |
int shift) { |
FLAG_wasm_simd_prototype = true; |
@@ -830,7 +848,7 @@ void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, |
byte simd = r.AllocateLocal(kWasmS128); |
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
WASM_SET_LOCAL( |
- simd, WASM_SIMD_SHIFT_OP(simd_op, WASM_GET_LOCAL(simd), shift)), |
+ simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), |
WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); |
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } |
@@ -953,7 +971,7 @@ void RunI16x8ShiftOpTest(WasmOpcode simd_op, Int16ShiftOp expected_op, |
byte simd = r.AllocateLocal(kWasmS128); |
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), |
WASM_SET_LOCAL( |
- simd, WASM_SIMD_SHIFT_OP(simd_op, WASM_GET_LOCAL(simd), shift)), |
+ simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), |
WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); |
FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } |
@@ -1076,7 +1094,7 @@ void RunI8x16ShiftOpTest(WasmOpcode simd_op, Int8ShiftOp expected_op, |
byte simd = r.AllocateLocal(kWasmS128); |
BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))), |
WASM_SET_LOCAL( |
- simd, WASM_SIMD_SHIFT_OP(simd_op, WASM_GET_LOCAL(simd), shift)), |
+ simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), |
WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE); |
FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } |
@@ -1093,4 +1111,37 @@ WASM_EXEC_TEST(I8x16ShrS) { |
WASM_EXEC_TEST(I8x16ShrU) { |
RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1); |
} |
+ |
+#define WASM_SIMD_SELECT_TEST(format) \ |
+ WASM_EXEC_TEST(S##format##Select) { \ |
+ FLAG_wasm_simd_prototype = true; \ |
+ WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \ |
+ byte val1 = 0; \ |
+ byte val2 = 1; \ |
+ byte mask = r.AllocateLocal(kWasmS128); \ |
+ byte src1 = r.AllocateLocal(kWasmS128); \ |
+ byte src2 = r.AllocateLocal(kWasmS128); \ |
+ BUILD(r, WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
+ WASM_SET_LOCAL(src1, \ |
+ WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \ |
+ WASM_SET_LOCAL(src2, \ |
+ WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \ |
+ WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \ |
+ 1, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \ |
+ WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \ |
+ 2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \ |
+ WASM_SET_LOCAL(mask, WASM_SIMD_SELECT(format, WASM_GET_LOCAL(mask), \ |
+ WASM_GET_LOCAL(src1), \ |
+ WASM_GET_LOCAL(src2))), \ |
+ WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \ |
+ WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ |
+ WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ |
+ WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ |
+ \ |
+ CHECK_EQ(1, r.Call(0x12, 0x34)); \ |
+ } |
+ |
+WASM_SIMD_SELECT_TEST(32x4) |
+WASM_SIMD_SELECT_TEST(16x8) |
+WASM_SIMD_SELECT_TEST(8x16) |
#endif // V8_TARGET_ARCH_ARM |