| 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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 792 |
| 793 FOR_INT32_INPUTS(i) { | 793 FOR_INT32_INPUTS(i) { |
| 794 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } | 794 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } |
| 795 } | 795 } |
| 796 } | 796 } |
| 797 | 797 |
| 798 WASM_EXEC_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); } | 798 WASM_EXEC_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); } |
| 799 | 799 |
| 800 WASM_EXEC_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } | 800 WASM_EXEC_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } |
| 801 | 801 |
| 802 #if V8_TARGET_ARCH_ARM | |
| 803 WASM_EXEC_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); } | 802 WASM_EXEC_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); } |
| 804 | 803 |
| 805 WASM_EXEC_TEST(I32x4Min) { RunI32x4BinOpTest(kExprI32x4MinS, Minimum); } | 804 WASM_EXEC_TEST(I32x4Min) { RunI32x4BinOpTest(kExprI32x4MinS, Minimum); } |
| 806 | 805 |
| 807 WASM_EXEC_TEST(I32x4Max) { RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); } | 806 WASM_EXEC_TEST(I32x4Max) { RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); } |
| 808 | 807 |
| 809 WASM_EXEC_TEST(Ui32x4Min) { | 808 WASM_EXEC_TEST(Ui32x4Min) { |
| 810 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); | 809 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); |
| 811 } | 810 } |
| 812 | 811 |
| 813 WASM_EXEC_TEST(Ui32x4Max) { | 812 WASM_EXEC_TEST(Ui32x4Max) { |
| 814 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); | 813 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); |
| 815 } | 814 } |
| 816 | 815 |
| 817 WASM_EXEC_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } | |
| 818 | |
| 819 WASM_EXEC_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } | |
| 820 | |
| 821 WASM_EXEC_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } | |
| 822 | 816 |
| 823 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { | 817 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { |
| 824 FLAG_wasm_simd_prototype = true; | 818 FLAG_wasm_simd_prototype = true; |
| 825 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); | 819 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); |
| 826 byte a = 0; | 820 byte a = 0; |
| 827 byte b = 1; | 821 byte b = 1; |
| 828 byte expected = 2; | 822 byte expected = 2; |
| 829 byte simd0 = r.AllocateLocal(kWasmS128); | 823 byte simd0 = r.AllocateLocal(kWasmS128); |
| 830 byte simd1 = r.AllocateLocal(kWasmS128); | 824 byte simd1 = r.AllocateLocal(kWasmS128); |
| 831 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 825 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
| 832 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | 826 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), |
| 833 WASM_SET_LOCAL(simd1, | 827 WASM_SET_LOCAL(simd1, |
| 834 WASM_SIMD_MATERIALIZE_BOOLS( | 828 WASM_SIMD_MATERIALIZE_BOOLS( |
| 835 32x4, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0), | 829 32x4, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0), |
| 836 WASM_GET_LOCAL(simd1)))), | 830 WASM_GET_LOCAL(simd1)))), |
| 837 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE); | 831 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE); |
| 838 | 832 |
| 839 FOR_INT32_INPUTS(i) { | 833 FOR_INT32_INPUTS(i) { |
| 840 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } | 834 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } |
| 841 } | 835 } |
| 842 } | 836 } |
| 843 | 837 |
| 844 WASM_EXEC_TEST(I32x4Equal) { RunI32x4CompareOpTest(kExprI32x4Eq, Equal); } | 838 WASM_EXEC_TEST(I32x4Equal) { RunI32x4CompareOpTest(kExprI32x4Eq, Equal); } |
| 845 | 839 |
| 846 WASM_EXEC_TEST(I32x4NotEqual) { RunI32x4CompareOpTest(kExprI32x4Ne, NotEqual); } | 840 WASM_EXEC_TEST(I32x4NotEqual) { RunI32x4CompareOpTest(kExprI32x4Ne, NotEqual); } |
| 847 | 841 |
| 842 // Test Select by making a mask where the first two lanes are true and the rest |
| 843 // false, and comparing for non-equality with zero to materialize a bool vector. |
| 844 #define WASM_SIMD_SELECT_TEST(format) \ |
| 845 WASM_EXEC_TEST(S##format##Select) { \ |
| 846 FLAG_wasm_simd_prototype = true; \ |
| 847 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \ |
| 848 byte val1 = 0; \ |
| 849 byte val2 = 1; \ |
| 850 byte src1 = r.AllocateLocal(kWasmS128); \ |
| 851 byte src2 = r.AllocateLocal(kWasmS128); \ |
| 852 byte zero = r.AllocateLocal(kWasmS128); \ |
| 853 byte mask = r.AllocateLocal(kWasmS128); \ |
| 854 BUILD(r, WASM_SET_LOCAL( \ |
| 855 src1, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \ |
| 856 WASM_SET_LOCAL(src2, \ |
| 857 WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \ |
| 858 WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ |
| 859 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \ |
| 860 1, WASM_GET_LOCAL(zero), WASM_I32V(-1))), \ |
| 861 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \ |
| 862 2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \ |
| 863 WASM_SET_LOCAL( \ |
| 864 mask, \ |
| 865 WASM_SIMD_SELECT(format, WASM_SIMD_BINOP(kExprI##format##Ne, \ |
| 866 WASM_GET_LOCAL(mask), \ |
| 867 WASM_GET_LOCAL(zero)), \ |
| 868 WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2))), \ |
| 869 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \ |
| 870 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ |
| 871 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ |
| 872 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ |
| 873 \ |
| 874 CHECK_EQ(1, r.Call(0x12, 0x34)); \ |
| 875 } |
| 876 |
| 877 WASM_SIMD_SELECT_TEST(32x4) |
| 878 |
| 879 #if V8_TARGET_ARCH_ARM |
| 880 WASM_EXEC_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } |
| 881 |
| 882 WASM_EXEC_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } |
| 883 |
| 884 WASM_EXEC_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } |
| 885 |
| 848 WASM_EXEC_TEST(I32x4Greater) { RunI32x4CompareOpTest(kExprI32x4GtS, Greater); } | 886 WASM_EXEC_TEST(I32x4Greater) { RunI32x4CompareOpTest(kExprI32x4GtS, Greater); } |
| 849 | 887 |
| 850 WASM_EXEC_TEST(I32x4GreaterEqual) { | 888 WASM_EXEC_TEST(I32x4GreaterEqual) { |
| 851 RunI32x4CompareOpTest(kExprI32x4GeS, GreaterEqual); | 889 RunI32x4CompareOpTest(kExprI32x4GeS, GreaterEqual); |
| 852 } | 890 } |
| 853 | 891 |
| 854 WASM_EXEC_TEST(I32x4Less) { RunI32x4CompareOpTest(kExprI32x4LtS, Less); } | 892 WASM_EXEC_TEST(I32x4Less) { RunI32x4CompareOpTest(kExprI32x4LtS, Less); } |
| 855 | 893 |
| 856 WASM_EXEC_TEST(I32x4LessEqual) { | 894 WASM_EXEC_TEST(I32x4LessEqual) { |
| 857 RunI32x4CompareOpTest(kExprI32x4LeS, LessEqual); | 895 RunI32x4CompareOpTest(kExprI32x4LeS, LessEqual); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 } | 1227 } |
| 1190 | 1228 |
| 1191 WASM_EXEC_TEST(I8x16ShrS) { | 1229 WASM_EXEC_TEST(I8x16ShrS) { |
| 1192 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1); | 1230 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1); |
| 1193 } | 1231 } |
| 1194 | 1232 |
| 1195 WASM_EXEC_TEST(I8x16ShrU) { | 1233 WASM_EXEC_TEST(I8x16ShrU) { |
| 1196 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1); | 1234 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1); |
| 1197 } | 1235 } |
| 1198 | 1236 |
| 1199 // Test Select by making a mask where the first two lanes are true and the rest | |
| 1200 // false, and comparing for non-equality with zero to materialize a bool vector. | |
| 1201 #define WASM_SIMD_SELECT_TEST(format) \ | |
| 1202 WASM_EXEC_TEST(S##format##Select) { \ | |
| 1203 FLAG_wasm_simd_prototype = true; \ | |
| 1204 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \ | |
| 1205 byte val1 = 0; \ | |
| 1206 byte val2 = 1; \ | |
| 1207 byte src1 = r.AllocateLocal(kWasmS128); \ | |
| 1208 byte src2 = r.AllocateLocal(kWasmS128); \ | |
| 1209 byte zero = r.AllocateLocal(kWasmS128); \ | |
| 1210 byte mask = r.AllocateLocal(kWasmS128); \ | |
| 1211 BUILD(r, WASM_SET_LOCAL( \ | |
| 1212 src1, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \ | |
| 1213 WASM_SET_LOCAL(src2, \ | |
| 1214 WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \ | |
| 1215 WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \ | |
| 1216 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \ | |
| 1217 1, WASM_GET_LOCAL(zero), WASM_I32V(-1))), \ | |
| 1218 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \ | |
| 1219 2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \ | |
| 1220 WASM_SET_LOCAL( \ | |
| 1221 mask, \ | |
| 1222 WASM_SIMD_SELECT(format, WASM_SIMD_BINOP(kExprI##format##Ne, \ | |
| 1223 WASM_GET_LOCAL(mask), \ | |
| 1224 WASM_GET_LOCAL(zero)), \ | |
| 1225 WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2))), \ | |
| 1226 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \ | |
| 1227 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \ | |
| 1228 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \ | |
| 1229 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \ | |
| 1230 \ | |
| 1231 CHECK_EQ(1, r.Call(0x12, 0x34)); \ | |
| 1232 } | |
| 1233 | |
| 1234 WASM_SIMD_SELECT_TEST(32x4) | |
| 1235 WASM_SIMD_SELECT_TEST(16x8) | 1237 WASM_SIMD_SELECT_TEST(16x8) |
| 1236 WASM_SIMD_SELECT_TEST(8x16) | 1238 WASM_SIMD_SELECT_TEST(8x16) |
| 1237 #endif // V8_TARGET_ARCH_ARM | 1239 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |