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

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: Add Int32x4 shift ops 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
bbudge 2017/02/28 19:34:39 It would be better to adjust the #ifdefs rather th
gdeepti 2017/03/13 20:37:52 Sgtm, makes a lot more sense to move the macros, f
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
946 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op,
947 int shift) {
948 FLAG_wasm_simd_prototype = true;
949 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
950 byte a = 0;
951 byte expected = 1;
952 byte simd = r.AllocateLocal(kWasmS128);
953 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
954 WASM_SET_LOCAL(
955 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
956 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
957
958 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); }
959 }
960
961 WASM_EXEC_COMPILED_TEST(I32x4Shl) {
962 RunI32x4ShiftOpTest(kExprI32x4Shl, LogicalShiftLeft, 1);
963 }
964
965 WASM_EXEC_COMPILED_TEST(I32x4ShrS) {
966 RunI32x4ShiftOpTest(kExprI32x4ShrS, ArithmeticShiftRight, 1);
967 }
968
969 WASM_EXEC_COMPILED_TEST(I32x4ShrU) {
970 RunI32x4ShiftOpTest(kExprI32x4ShrU, LogicalShiftRight, 1);
971 }
972
973 #endif // V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_X64
974
975 #if V8_TARGET_ARCH_ARM
911 WASM_EXEC_COMPILED_TEST(I32x4Greater) { 976 WASM_EXEC_COMPILED_TEST(I32x4Greater) {
912 RunI32x4CompareOpTest(kExprI32x4GtS, Greater); 977 RunI32x4CompareOpTest(kExprI32x4GtS, Greater);
913 } 978 }
914 979
915 WASM_EXEC_COMPILED_TEST(I32x4GreaterEqual) { 980 WASM_EXEC_COMPILED_TEST(I32x4GreaterEqual) {
916 RunI32x4CompareOpTest(kExprI32x4GeS, GreaterEqual); 981 RunI32x4CompareOpTest(kExprI32x4GeS, GreaterEqual);
917 } 982 }
918 983
919 WASM_EXEC_COMPILED_TEST(I32x4Less) { 984 WASM_EXEC_COMPILED_TEST(I32x4Less) {
920 RunI32x4CompareOpTest(kExprI32x4LtS, Less); 985 RunI32x4CompareOpTest(kExprI32x4LtS, Less);
(...skipping 12 matching lines...) Expand all
933 } 998 }
934 999
935 WASM_EXEC_COMPILED_TEST(Ui32x4Less) { 1000 WASM_EXEC_COMPILED_TEST(Ui32x4Less) {
936 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess); 1001 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess);
937 } 1002 }
938 1003
939 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) { 1004 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) {
940 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); 1005 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual);
941 } 1006 }
942 1007
943 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op,
944 int shift) {
945 FLAG_wasm_simd_prototype = true;
946 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
947 byte a = 0;
948 byte expected = 1;
949 byte simd = r.AllocateLocal(kWasmS128);
950 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
951 WASM_SET_LOCAL(
952 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
953 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
954
955 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i, shift))); }
956 }
957
958 WASM_EXEC_COMPILED_TEST(I32x4Shl) {
959 RunI32x4ShiftOpTest(kExprI32x4Shl, LogicalShiftLeft, 1);
960 }
961
962 WASM_EXEC_COMPILED_TEST(I32x4ShrS) {
963 RunI32x4ShiftOpTest(kExprI32x4ShrS, ArithmeticShiftRight, 1);
964 }
965
966 WASM_EXEC_COMPILED_TEST(I32x4ShrU) {
967 RunI32x4ShiftOpTest(kExprI32x4ShrU, LogicalShiftRight, 1);
968 }
969
970 void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) { 1008 void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) {
971 FLAG_wasm_simd_prototype = true; 1009 FLAG_wasm_simd_prototype = true;
972 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); 1010 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
973 byte a = 0; 1011 byte a = 0;
974 byte expected = 1; 1012 byte expected = 1;
975 byte simd = r.AllocateLocal(kWasmS128); 1013 byte simd = r.AllocateLocal(kWasmS128);
976 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))), 1014 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
977 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))), 1015 WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
978 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE); 1016 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE);
979 1017
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 } 1318 }
1281 1319
1282 WASM_EXEC_COMPILED_TEST(I8x16ShrS) { 1320 WASM_EXEC_COMPILED_TEST(I8x16ShrS) {
1283 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1); 1321 RunI8x16ShiftOpTest(kExprI8x16ShrS, ArithmeticShiftRight, 1);
1284 } 1322 }
1285 1323
1286 WASM_EXEC_COMPILED_TEST(I8x16ShrU) { 1324 WASM_EXEC_COMPILED_TEST(I8x16ShrU) {
1287 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1); 1325 RunI8x16ShiftOpTest(kExprI8x16ShrU, LogicalShiftRight, 1);
1288 } 1326 }
1289 1327
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) 1328 WASM_SIMD_SELECT_TEST(16x8)
1327 WASM_SIMD_SELECT_TEST(8x16) 1329 WASM_SIMD_SELECT_TEST(8x16)
1328 #endif // V8_TARGET_ARCH_ARM 1330 #endif // V8_TARGET_ARCH_ARM
1329 1331
1330 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET 1332 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
1331 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) { 1333 WASM_EXEC_COMPILED_TEST(SimdI32x4ExtractWithF32x4) {
1332 FLAG_wasm_simd_prototype = true; 1334 FLAG_wasm_simd_prototype = true;
1333 WasmRunner<int32_t> r(kExecuteCompiled); 1335 WasmRunner<int32_t> r(kExecuteCompiled);
1334 BUILD(r, WASM_IF_ELSE_I( 1336 BUILD(r, WASM_IF_ELSE_I(
1335 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE( 1337 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), 1553 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
1552 WASM_F32(65.0))), 1554 WASM_F32(65.0))),
1553 WASM_I32V(1)); 1555 WASM_I32V(1));
1554 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } 1556 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
1555 CHECK_EQ(*global, 13.5); 1557 CHECK_EQ(*global, 13.5);
1556 CHECK_EQ(*(global + 1), 45.5); 1558 CHECK_EQ(*(global + 1), 45.5);
1557 CHECK_EQ(*(global + 2), 32.25); 1559 CHECK_EQ(*(global + 2), 32.25);
1558 CHECK_EQ(*(global + 3), 65.0); 1560 CHECK_EQ(*(global + 3), 65.0);
1559 } 1561 }
1560 #endif // SIMD_LOWERING_TARGET 1562 #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