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

Side by Side Diff: test/cctest/wasm/test-run-wasm-simd.cc

Issue 2719953002: Add Int32x4 Wasm Simd Binops, compare ops, select (Closed)
Patch Set: Rebase, use pshufd Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 843
844 FOR_INT32_INPUTS(i) { 844 FOR_INT32_INPUTS(i) {
845 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } 845 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
846 } 846 }
847 } 847 }
848 848
849 WASM_EXEC_COMPILED_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); } 849 WASM_EXEC_COMPILED_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); }
850 850
851 WASM_EXEC_COMPILED_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } 851 WASM_EXEC_COMPILED_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); }
852 852
853 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
854 WASM_EXEC_COMPILED_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); } 853 WASM_EXEC_COMPILED_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); }
855 854
855 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
856 WASM_EXEC_COMPILED_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); } 856 WASM_EXEC_COMPILED_TEST(S128And) { RunI32x4BinOpTest(kExprS128And, And); }
857 857
858 WASM_EXEC_COMPILED_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); } 858 WASM_EXEC_COMPILED_TEST(S128Or) { RunI32x4BinOpTest(kExprS128Or, Or); }
859 859
860 WASM_EXEC_COMPILED_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); } 860 WASM_EXEC_COMPILED_TEST(S128Xor) { RunI32x4BinOpTest(kExprS128Xor, Xor); }
861 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 861 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
862 862
863 #if V8_TARGET_ARCH_ARM 863 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64
864 WASM_EXEC_COMPILED_TEST(I32x4Min) { 864 WASM_EXEC_COMPILED_TEST(I32x4Min) {
865 RunI32x4BinOpTest(kExprI32x4MinS, Minimum); 865 RunI32x4BinOpTest(kExprI32x4MinS, Minimum);
866 } 866 }
867 867
868 WASM_EXEC_COMPILED_TEST(I32x4Max) { 868 WASM_EXEC_COMPILED_TEST(I32x4Max) {
869 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); 869 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum);
870 } 870 }
871 871
872 WASM_EXEC_COMPILED_TEST(Ui32x4Min) { 872 WASM_EXEC_COMPILED_TEST(Ui32x4Min) {
873 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); 873 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum);
874 } 874 }
875 875
876 WASM_EXEC_COMPILED_TEST(Ui32x4Max) { 876 WASM_EXEC_COMPILED_TEST(Ui32x4Max) {
877 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); 877 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum);
878 } 878 }
879 879
880
881
882 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { 880 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) {
883 FLAG_wasm_simd_prototype = true; 881 FLAG_wasm_simd_prototype = true;
884 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); 882 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
885 byte a = 0; 883 byte a = 0;
886 byte b = 1; 884 byte b = 1;
887 byte expected = 2; 885 byte expected = 2;
888 byte simd0 = r.AllocateLocal(kWasmS128); 886 byte simd0 = r.AllocateLocal(kWasmS128);
889 byte simd1 = r.AllocateLocal(kWasmS128); 887 byte simd1 = r.AllocateLocal(kWasmS128);
890 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), 888 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
891 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), 889 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
892 WASM_SET_LOCAL(simd1, 890 WASM_SET_LOCAL(simd1,
893 WASM_SIMD_MATERIALIZE_BOOLS( 891 WASM_SIMD_MATERIALIZE_BOOLS(
894 32x4, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0), 892 32x4, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
895 WASM_GET_LOCAL(simd1)))), 893 WASM_GET_LOCAL(simd1)))),
896 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE); 894 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
897 895
898 FOR_INT32_INPUTS(i) { 896 FOR_INT32_INPUTS(i) {
899 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } 897 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
900 } 898 }
901 } 899 }
902 900
903 WASM_EXEC_COMPILED_TEST(I32x4Equal) { 901 WASM_EXEC_COMPILED_TEST(I32x4Equal) {
904 RunI32x4CompareOpTest(kExprI32x4Eq, Equal); 902 RunI32x4CompareOpTest(kExprI32x4Eq, Equal);
905 } 903 }
906 904
907 WASM_EXEC_COMPILED_TEST(I32x4NotEqual) { 905 WASM_EXEC_COMPILED_TEST(I32x4NotEqual) {
908 RunI32x4CompareOpTest(kExprI32x4Ne, NotEqual); 906 RunI32x4CompareOpTest(kExprI32x4Ne, NotEqual);
909 } 907 }
910 908
909 // Test Select by making a mask where the first two lanes are true and the rest
910 // false, and comparing for non-equality with zero to materialize a bool vector.
911 #define WASM_SIMD_SELECT_TEST(format) \
912 WASM_EXEC_COMPILED_TEST(S##format##Select) { \
913 FLAG_wasm_simd_prototype = true; \
914 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \
915 byte val1 = 0; \
916 byte val2 = 1; \
917 byte src1 = r.AllocateLocal(kWasmS128); \
918 byte src2 = r.AllocateLocal(kWasmS128); \
919 byte zero = r.AllocateLocal(kWasmS128); \
920 byte mask = r.AllocateLocal(kWasmS128); \
921 BUILD(r, WASM_SET_LOCAL( \
922 src1, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \
923 WASM_SET_LOCAL(src2, \
924 WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \
925 WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
926 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
927 1, WASM_GET_LOCAL(zero), WASM_I32V(-1))), \
928 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
929 2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \
930 WASM_SET_LOCAL( \
931 mask, \
932 WASM_SIMD_SELECT(format, WASM_SIMD_BINOP(kExprI##format##Ne, \
933 WASM_GET_LOCAL(mask), \
934 WASM_GET_LOCAL(zero)), \
935 WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2))), \
936 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \
937 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \
938 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \
939 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \
940 \
941 CHECK_EQ(1, r.Call(0x12, 0x34)); \
942 }
943
944 WASM_SIMD_SELECT_TEST(32x4)
945 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64
946
947 #if V8_TARGET_ARCH_ARM
911 WASM_EXEC_COMPILED_TEST(I32x4Greater) { 948 WASM_EXEC_COMPILED_TEST(I32x4Greater) {
912 RunI32x4CompareOpTest(kExprI32x4GtS, Greater); 949 RunI32x4CompareOpTest(kExprI32x4GtS, Greater);
913 } 950 }
914 951
915 WASM_EXEC_COMPILED_TEST(I32x4GreaterEqual) { 952 WASM_EXEC_COMPILED_TEST(I32x4GreaterEqual) {
916 RunI32x4CompareOpTest(kExprI32x4GeS, GreaterEqual); 953 RunI32x4CompareOpTest(kExprI32x4GeS, GreaterEqual);
917 } 954 }
918 955
919 WASM_EXEC_COMPILED_TEST(I32x4Less) { 956 WASM_EXEC_COMPILED_TEST(I32x4Less) {
920 RunI32x4CompareOpTest(kExprI32x4LtS, Less); 957 RunI32x4CompareOpTest(kExprI32x4LtS, Less);
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 } 1317 }
1281 1318
1282 WASM_EXEC_COMPILED_TEST(I8x16ShrS) { 1319 WASM_EXEC_COMPILED_TEST(I8x16ShrS) {
1283 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1); 1320 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1);
1284 } 1321 }
1285 1322
1286 WASM_EXEC_COMPILED_TEST(I8x16ShrU) { 1323 WASM_EXEC_COMPILED_TEST(I8x16ShrU) {
1287 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1); 1324 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1);
1288 } 1325 }
1289 1326
1290 // Test Select by making a mask where the first two lanes are true and the rest
1291 // false, and comparing for non-equality with zero to materialize a bool vector.
1292 #define WASM_SIMD_SELECT_TEST(format) \
1293 WASM_EXEC_COMPILED_TEST(S##format##Select) { \
1294 FLAG_wasm_simd_prototype = true; \
1295 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); \
1296 byte val1 = 0; \
1297 byte val2 = 1; \
1298 byte src1 = r.AllocateLocal(kWasmS128); \
1299 byte src2 = r.AllocateLocal(kWasmS128); \
1300 byte zero = r.AllocateLocal(kWasmS128); \
1301 byte mask = r.AllocateLocal(kWasmS128); \
1302 BUILD(r, WASM_SET_LOCAL( \
1303 src1, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \
1304 WASM_SET_LOCAL(src2, \
1305 WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \
1306 WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
1307 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
1308 1, WASM_GET_LOCAL(zero), WASM_I32V(-1))), \
1309 WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
1310 2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \
1311 WASM_SET_LOCAL( \
1312 mask, \
1313 WASM_SIMD_SELECT(format, WASM_SIMD_BINOP(kExprI##format##Ne, \
1314 WASM_GET_LOCAL(mask), \
1315 WASM_GET_LOCAL(zero)), \
1316 WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2))), \
1317 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \
1318 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \
1319 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \
1320 WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \
1321 \
1322 CHECK_EQ(1, r.Call(0x12, 0x34)); \
1323 }
1324
1325 WASM_SIMD_SELECT_TEST(32x4)
1326 WASM_SIMD_SELECT_TEST(16x8) 1327 WASM_SIMD_SELECT_TEST(16x8)
1327 WASM_SIMD_SELECT_TEST(8x16) 1328 WASM_SIMD_SELECT_TEST(8x16)
1328 #endif // V8_TARGET_ARCH_ARM 1329 #endif // V8_TARGET_ARCH_ARM
1329 1330
1330 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 1331 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
1331 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { 1332 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) {
1332 FLAG_wasm_simd_prototype = true; 1333 FLAG_wasm_simd_prototype = true;
1333 WasmRunner<int32_t> r(kExecuteCompiled); 1334 WasmRunner<int32_t> r(kExecuteCompiled);
1334 BUILD(r, WASM_IF_ELSE_I( 1335 BUILD(r, WASM_IF_ELSE_I(
1335 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( 1336 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), 1552 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
1552 WASM_F32(65.0))), 1553 WASM_F32(65.0))),
1553 WASM_I32V(1)); 1554 WASM_I32V(1));
1554 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } 1555 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
1555 CHECK_EQ(*global, 13.5); 1556 CHECK_EQ(*global, 13.5);
1556 CHECK_EQ(*(global + 1), 45.5); 1557 CHECK_EQ(*(global + 1), 45.5);
1557 CHECK_EQ(*(global + 2), 32.25); 1558 CHECK_EQ(*(global + 2), 32.25);
1558 CHECK_EQ(*(global + 3), 65.0); 1559 CHECK_EQ(*(global + 3), 65.0);
1559 } 1560 }
1560 #endif // SIMD_LOWERING_TARGET 1561 #endif // SIMD_LOWERING_TARGET
OLDNEW
« src/compiler/x64/instruction-selector-x64.cc ('K') | « src/compiler/x64/instruction-selector-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698