OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/assembler-inl.h" | 5 #include "src/assembler-inl.h" |
6 #include "src/wasm/wasm-macro-gen.h" | 6 #include "src/wasm/wasm-macro-gen.h" |
7 #include "test/cctest/cctest.h" | 7 #include "test/cctest/cctest.h" |
8 #include "test/cctest/compiler/value-helper.h" | 8 #include "test/cctest/compiler/value-helper.h" |
9 #include "test/cctest/wasm/wasm-run-utils.h" | 9 #include "test/cctest/wasm/wasm-run-utils.h" |
10 | 10 |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 | 949 |
950 FOR_INT32_INPUTS(i) { | 950 FOR_INT32_INPUTS(i) { |
951 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } | 951 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } |
952 } | 952 } |
953 } | 953 } |
954 | 954 |
955 WASM_EXEC_COMPILED_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); } | 955 WASM_EXEC_COMPILED_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); } |
956 | 956 |
957 WASM_EXEC_COMPILED_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } | 957 WASM_EXEC_COMPILED_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } |
958 | 958 |
| 959 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || SIMD_LOWERING_TARGET |
| 960 WASM_EXEC_COMPILED_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); } |
| 961 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || SIMD_LOWERING_TARGET |
| 962 |
959 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 963 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
960 WASM_EXEC_COMPILED_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); } | |
961 | |
962 WASM_EXEC_COMPILED_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } | 964 WASM_EXEC_COMPILED_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } |
963 | 965 |
964 WASM_EXEC_COMPILED_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } | 966 WASM_EXEC_COMPILED_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } |
965 | 967 |
966 WASM_EXEC_COMPILED_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } | 968 WASM_EXEC_COMPILED_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } |
| 969 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
967 | 970 |
| 971 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || SIMD_LOWERING_TARGET |
968 WASM_EXEC_COMPILED_TEST(I32x4Min) { | 972 WASM_EXEC_COMPILED_TEST(I32x4Min) { |
969 RunI32x4BinOpTest(kExprI32x4MinS, Minimum); | 973 RunI32x4BinOpTest(kExprI32x4MinS, Minimum); |
970 } | 974 } |
971 | 975 |
972 WASM_EXEC_COMPILED_TEST(I32x4MaxS) { | 976 WASM_EXEC_COMPILED_TEST(I32x4MaxS) { |
973 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); | 977 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); |
974 } | 978 } |
975 | 979 |
976 WASM_EXEC_COMPILED_TEST(I32x4MinU) { | 980 WASM_EXEC_COMPILED_TEST(I32x4MinU) { |
977 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); | 981 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); |
(...skipping 22 matching lines...) Expand all Loading... |
1000 FOR_INT32_INPUTS(i) { | 1004 FOR_INT32_INPUTS(i) { |
1001 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } | 1005 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } |
1002 } | 1006 } |
1003 } | 1007 } |
1004 | 1008 |
1005 WASM_EXEC_COMPILED_TEST(I32x4Eq) { RunI32x4CompareOpTest(kExprI32x4Eq, Equal); } | 1009 WASM_EXEC_COMPILED_TEST(I32x4Eq) { RunI32x4CompareOpTest(kExprI32x4Eq, Equal); } |
1006 | 1010 |
1007 WASM_EXEC_COMPILED_TEST(I32x4Ne) { | 1011 WASM_EXEC_COMPILED_TEST(I32x4Ne) { |
1008 RunI32x4CompareOpTest(kExprI32x4Ne, NotEqual); | 1012 RunI32x4CompareOpTest(kExprI32x4Ne, NotEqual); |
1009 } | 1013 } |
| 1014 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || SIMD_LOWERING_TARGET |
1010 | 1015 |
| 1016 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
1011 WASM_EXEC_COMPILED_TEST(I32x4LtS) { | 1017 WASM_EXEC_COMPILED_TEST(I32x4LtS) { |
1012 RunI32x4CompareOpTest(kExprI32x4LtS, Less); | 1018 RunI32x4CompareOpTest(kExprI32x4LtS, Less); |
1013 } | 1019 } |
1014 | 1020 |
1015 WASM_EXEC_COMPILED_TEST(I32x4LeS) { | 1021 WASM_EXEC_COMPILED_TEST(I32x4LeS) { |
1016 RunI32x4CompareOpTest(kExprI32x4LeS, LessEqual); | 1022 RunI32x4CompareOpTest(kExprI32x4LeS, LessEqual); |
1017 } | 1023 } |
1018 | 1024 |
1019 WASM_EXEC_COMPILED_TEST(I32x4GtS) { | 1025 WASM_EXEC_COMPILED_TEST(I32x4GtS) { |
1020 RunI32x4CompareOpTest(kExprI32x4GtS, Greater); | 1026 RunI32x4CompareOpTest(kExprI32x4GtS, Greater); |
(...skipping 11 matching lines...) Expand all Loading... |
1032 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); | 1038 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); |
1033 } | 1039 } |
1034 | 1040 |
1035 WASM_EXEC_COMPILED_TEST(I32x4GtU) { | 1041 WASM_EXEC_COMPILED_TEST(I32x4GtU) { |
1036 RunI32x4CompareOpTest(kExprI32x4GtU, UnsignedGreater); | 1042 RunI32x4CompareOpTest(kExprI32x4GtU, UnsignedGreater); |
1037 } | 1043 } |
1038 | 1044 |
1039 WASM_EXEC_COMPILED_TEST(I32x4GeU) { | 1045 WASM_EXEC_COMPILED_TEST(I32x4GeU) { |
1040 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual); | 1046 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual); |
1041 } | 1047 } |
| 1048 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
1042 | 1049 |
| 1050 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || SIMD_LOWERING_TARGET |
1043 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, | 1051 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, |
1044 int shift) { | 1052 int shift) { |
1045 FLAG_wasm_simd_prototype = true; | 1053 FLAG_wasm_simd_prototype = true; |
1046 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 1054 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
1047 byte a = 0; | 1055 byte a = 0; |
1048 byte expected = 1; | 1056 byte expected = 1; |
1049 byte simd = r.AllocateLocal(kWasmS128); | 1057 byte simd = r.AllocateLocal(kWasmS128); |
1050 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 1058 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
1051 WASM_SET_LOCAL( | 1059 WASM_SET_LOCAL( |
1052 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), | 1060 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), |
1053 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); | 1061 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE); |
1054 | 1062 |
1055 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } | 1063 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); } |
1056 } | 1064 } |
1057 | 1065 |
1058 WASM_EXEC_COMPILED_TEST(I32x4Shl) { | 1066 WASM_EXEC_COMPILED_TEST(I32x4Shl) { |
1059 RunI32x4ShiftOpTest(kExprI32x4Shl, LogicalShiftLeft, 1); | 1067 RunI32x4ShiftOpTest(kExprI32x4Shl, LogicalShiftLeft, 1); |
1060 } | 1068 } |
1061 | 1069 |
1062 WASM_EXEC_COMPILED_TEST(I32x4ShrS) { | 1070 WASM_EXEC_COMPILED_TEST(I32x4ShrS) { |
1063 RunI32x4ShiftOpTest(kExprI32x4ShrS, ArithmeticShiftRight, 1); | 1071 RunI32x4ShiftOpTest(kExprI32x4ShrS, ArithmeticShiftRight, 1); |
1064 } | 1072 } |
1065 | 1073 |
1066 WASM_EXEC_COMPILED_TEST(I32x4ShrU) { | 1074 WASM_EXEC_COMPILED_TEST(I32x4ShrU) { |
1067 RunI32x4ShiftOpTest(kExprI32x4ShrU, LogicalShiftRight, 1); | 1075 RunI32x4ShiftOpTest(kExprI32x4ShrU, LogicalShiftRight, 1); |
1068 } | 1076 } |
1069 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | 1077 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 || SIMD_LOWERING_TARGET |
1070 | 1078 |
1071 #if V8_TARGET_ARCH_ARM | 1079 #if V8_TARGET_ARCH_ARM |
1072 | |
1073 void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) { | 1080 void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) { |
1074 FLAG_wasm_simd_prototype = true; | 1081 FLAG_wasm_simd_prototype = true; |
1075 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 1082 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
1076 byte a = 0; | 1083 byte a = 0; |
1077 byte expected = 1; | 1084 byte expected = 1; |
1078 byte simd = r.AllocateLocal(kWasmS128); | 1085 byte simd = r.AllocateLocal(kWasmS128); |
1079 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), | 1086 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), |
1080 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), | 1087 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), |
1081 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); | 1088 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); |
1082 | 1089 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 RunI8x16ShiftOpTest(kExprI8x16Shl, LogicalShiftLeft, 1); | 1385 RunI8x16ShiftOpTest(kExprI8x16Shl, LogicalShiftLeft, 1); |
1379 } | 1386 } |
1380 | 1387 |
1381 WASM_EXEC_COMPILED_TEST(I8x16ShrS) { | 1388 WASM_EXEC_COMPILED_TEST(I8x16ShrS) { |
1382 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1); | 1389 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1); |
1383 } | 1390 } |
1384 | 1391 |
1385 WASM_EXEC_COMPILED_TEST(I8x16ShrU) { | 1392 WASM_EXEC_COMPILED_TEST(I8x16ShrU) { |
1386 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1); | 1393 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1); |
1387 } | 1394 } |
| 1395 #endif // V8_TARGET_ARCH_ARM |
1388 | 1396 |
| 1397 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
1389 // Test Select by making a mask where the first two lanes are true and the rest | 1398 // Test Select by making a mask where the first two lanes are true and the rest |
1390 // false, and comparing for non-equality with zero to materialize a bool vector. | 1399 // false, and comparing for non-equality with zero to materialize a bool vector. |
1391 #define WASM_SIMD_SELECT_TEST(format) \ | 1400 #define WASM_SIMD_SELECT_TEST(format) \ |
1392 WASM_EXEC_COMPILED_TEST(S##format##Select) { \ | 1401 WASM_EXEC_COMPILED_TEST(S##format##Select) { \ |
1393 FLAG_wasm_simd_prototype = true; \ | 1402 FLAG_wasm_simd_prototype = true; \ |
1394 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \ | 1403 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \ |
1395 byte val1 = 0; \ | 1404 byte val1 = 0; \ |
1396 byte val2 = 1; \ | 1405 byte val2 = 1; \ |
1397 byte src1 = r.AllocateLocal(kWasmS128); \ | 1406 byte src1 = r.AllocateLocal(kWasmS128); \ |
1398 byte src2 = r.AllocateLocal(kWasmS128); \ | 1407 byte src2 = r.AllocateLocal(kWasmS128); \ |
(...skipping 16 matching lines...) Expand all Loading... |
1415 WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2))), \ | 1424 WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2))), \ |
1416 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \ | 1425 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \ |
1417 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ | 1426 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ |
1418 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ | 1427 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ |
1419 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ | 1428 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ |
1420 \ | 1429 \ |
1421 CHECK_EQ(1, r.Call(0x12, 0x34)); \ | 1430 CHECK_EQ(1, r.Call(0x12, 0x34)); \ |
1422 } | 1431 } |
1423 | 1432 |
1424 WASM_SIMD_SELECT_TEST(32x4) | 1433 WASM_SIMD_SELECT_TEST(32x4) |
| 1434 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64 |
| 1435 |
| 1436 #if V8_TARGET_ARCH_ARM |
1425 WASM_SIMD_SELECT_TEST(16x8) | 1437 WASM_SIMD_SELECT_TEST(16x8) |
1426 WASM_SIMD_SELECT_TEST(8x16) | 1438 WASM_SIMD_SELECT_TEST(8x16) |
1427 | 1439 |
1428 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer | 1440 // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer |
1429 // result. Use relational ops on numeric vectors to create the boolean vector | 1441 // result. Use relational ops on numeric vectors to create the boolean vector |
1430 // test inputs. Test inputs with all true, all false, one true, and one false. | 1442 // test inputs. Test inputs with all true, all false, one true, and one false. |
1431 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ | 1443 #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \ |
1432 WASM_EXEC_TEST(ReductionTest##lanes) { \ | 1444 WASM_EXEC_TEST(ReductionTest##lanes) { \ |
1433 FLAG_wasm_simd_prototype = true; \ | 1445 FLAG_wasm_simd_prototype = true; \ |
1434 WasmRunner<int32_t> r(kExecuteCompiled); \ | 1446 WasmRunner<int32_t> r(kExecuteCompiled); \ |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1828 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 1840 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
1829 WASM_F32(65.0))), | 1841 WASM_F32(65.0))), |
1830 WASM_I32V(1)); | 1842 WASM_I32V(1)); |
1831 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 1843 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
1832 CHECK_EQ(*global, 13.5); | 1844 CHECK_EQ(*global, 13.5); |
1833 CHECK_EQ(*(global + 1), 45.5); | 1845 CHECK_EQ(*(global + 1), 45.5); |
1834 CHECK_EQ(*(global + 2), 32.25); | 1846 CHECK_EQ(*(global + 2), 32.25); |
1835 CHECK_EQ(*(global + 3), 65.0); | 1847 CHECK_EQ(*(global + 3), 65.0); |
1836 } | 1848 } |
1837 #endif // SIMD_LOWERING_TARGET | 1849 #endif // SIMD_LOWERING_TARGET |
OLD | NEW |