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

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

Issue 2728823005: [wasm] Implement simd lowering for F32x4 and I32x4 compare ops (Closed)
Patch Set: rebase 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
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10 matching lines...) Expand all
21 typedef int32_t (*Int32UnOp)(int32_t); 21 typedef int32_t (*Int32UnOp)(int32_t);
22 typedef int32_t (*Int32BinOp)(int32_t, int32_t); 22 typedef int32_t (*Int32BinOp)(int32_t, int32_t);
23 typedef int32_t (*Int32ShiftOp)(int32_t, int); 23 typedef int32_t (*Int32ShiftOp)(int32_t, int);
24 typedef int16_t (*Int16UnOp)(int16_t); 24 typedef int16_t (*Int16UnOp)(int16_t);
25 typedef int16_t (*Int16BinOp)(int16_t, int16_t); 25 typedef int16_t (*Int16BinOp)(int16_t, int16_t);
26 typedef int16_t (*Int16ShiftOp)(int16_t, int); 26 typedef int16_t (*Int16ShiftOp)(int16_t, int);
27 typedef int8_t (*Int8UnOp)(int8_t); 27 typedef int8_t (*Int8UnOp)(int8_t);
28 typedef int8_t (*Int8BinOp)(int8_t, int8_t); 28 typedef int8_t (*Int8BinOp)(int8_t, int8_t);
29 typedef int8_t (*Int8ShiftOp)(int8_t, int); 29 typedef int8_t (*Int8ShiftOp)(int8_t, int);
30 30
31 #if V8_TARGET_ARCH_ARM 31 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64
32 // Floating point specific value functions, only used by ARM so far. 32 #define SIMD_LOWERING_TARGET 1
33 #else
34 #define SIMD_LOWERING_TARGET 0
35 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64
36
37 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
33 int32_t Equal(float a, float b) { return a == b ? 1 : 0; } 38 int32_t Equal(float a, float b) { return a == b ? 1 : 0; }
34 39
35 int32_t NotEqual(float a, float b) { return a != b ? 1 : 0; } 40 int32_t NotEqual(float a, float b) { return a != b ? 1 : 0; }
36 #endif // V8_TARGET_ARCH_ARM 41 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
42
43 #if SIMD_LOWERING_TARGET
44 int32_t Less(float a, float b) { return a < b ? 1 : 0; }
45
46 int32_t LessEqual(float a, float b) { return a <= b ? 1 : 0; }
47
48 int32_t Greater(float a, float b) { return a > b ? 1 : 0; }
49
50 int32_t GreaterEqual(float a, float b) { return a >= b ? 1 : 0; }
51 #endif // SIMD_LOWERING_TARGET
37 52
38 // Generic expected value functions. 53 // Generic expected value functions.
39 template <typename T> 54 template <typename T>
40 T Negate(T a) { 55 T Negate(T a) {
41 return -a; 56 return -a;
42 } 57 }
43 58
44 template <typename T> 59 template <typename T>
45 T Add(T a, T b) { 60 T Add(T a, T b) {
46 return a + b; 61 return a + b;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 return a == 0 ? 1 : 0; 232 return a == 0 ? 1 : 0;
218 } 233 }
219 234
220 template <typename T> 235 template <typename T>
221 T Sqrt(T a) { 236 T Sqrt(T a) {
222 return std::sqrt(a); 237 return std::sqrt(a);
223 } 238 }
224 239
225 } // namespace 240 } // namespace
226 241
227 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64
228 #define SIMD_LOWERING_TARGET 1
229 #else
230 #define SIMD_LOWERING_TARGET 0
231 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64
232
233 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \ 242 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \
234 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \ 243 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \
235 WASM_SIMD_##TYPE##_EXTRACT_LANE( \ 244 WASM_SIMD_##TYPE##_EXTRACT_LANE( \
236 lane_index, WASM_GET_LOCAL(value))), \ 245 lane_index, WASM_GET_LOCAL(value))), \
237 WASM_RETURN1(WASM_ZERO)) 246 WASM_RETURN1(WASM_ZERO))
238 247
239 #define WASM_SIMD_CHECK_F32_LANE(value, lane_value, lane_index) \ 248 #define WASM_SIMD_CHECK_F32_LANE(value, lane_value, lane_index) \
240 WASM_IF(WASM_F32_NE(WASM_GET_LOCAL(lane_value), \ 249 WASM_IF(WASM_F32_NE(WASM_GET_LOCAL(lane_value), \
241 WASM_SIMD_F32x4_EXTRACT_LANE(lane_index, \ 250 WASM_SIMD_F32x4_EXTRACT_LANE(lane_index, \
242 WASM_GET_LOCAL(value))), \ 251 WASM_GET_LOCAL(value))), \
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 WASM_EXEC_COMPILED_TEST(F32x4Mul) { RunF32x4BinOpTest(kExprF32x4Mul, Mul); } 494 WASM_EXEC_COMPILED_TEST(F32x4Mul) { RunF32x4BinOpTest(kExprF32x4Mul, Mul); }
486 WASM_EXEC_COMPILED_TEST(F32x4Div) { RunF32x4BinOpTest(kExprF32x4Div, Div); } 495 WASM_EXEC_COMPILED_TEST(F32x4Div) { RunF32x4BinOpTest(kExprF32x4Div, Div); }
487 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Min) { 496 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Min) {
488 RunF32x4BinOpTest(kExprF32x4Min, Minimum); 497 RunF32x4BinOpTest(kExprF32x4Min, Minimum);
489 } 498 }
490 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Max) { 499 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Max) {
491 RunF32x4BinOpTest(kExprF32x4Max, Maximum); 500 RunF32x4BinOpTest(kExprF32x4Max, Maximum);
492 } 501 }
493 #endif // SIMD_LOWERING_TARGET 502 #endif // SIMD_LOWERING_TARGET
494 503
495 #if V8_TARGET_ARCH_ARM 504 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
496 void RunF32x4CompareOpTest(WasmOpcode simd_op, FloatCompareOp expected_op) { 505 void RunF32x4CompareOpTest(WasmOpcode simd_op, FloatCompareOp expected_op) {
497 FLAG_wasm_simd_prototype = true; 506 FLAG_wasm_simd_prototype = true;
498 WasmRunner<int32_t, float, float, int32_t> r(kExecuteCompiled); 507 WasmRunner<int32_t, float, float, int32_t> r(kExecuteCompiled);
499 byte a = 0; 508 byte a = 0;
500 byte b = 1; 509 byte b = 1;
501 byte expected = 2; 510 byte expected = 2;
502 byte simd0 = r.AllocateLocal(kWasmS128); 511 byte simd0 = r.AllocateLocal(kWasmS128);
503 byte simd1 = r.AllocateLocal(kWasmS128); 512 byte simd1 = r.AllocateLocal(kWasmS128);
504 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), 513 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
505 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))), 514 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
(...skipping 14 matching lines...) Expand all
520 } 529 }
521 } 530 }
522 531
523 WASM_EXEC_COMPILED_TEST(F32x4Equal) { 532 WASM_EXEC_COMPILED_TEST(F32x4Equal) {
524 RunF32x4CompareOpTest(kExprF32x4Eq, Equal); 533 RunF32x4CompareOpTest(kExprF32x4Eq, Equal);
525 } 534 }
526 535
527 WASM_EXEC_COMPILED_TEST(F32x4NotEqual) { 536 WASM_EXEC_COMPILED_TEST(F32x4NotEqual) {
528 RunF32x4CompareOpTest(kExprF32x4Ne, NotEqual); 537 RunF32x4CompareOpTest(kExprF32x4Ne, NotEqual);
529 } 538 }
530 #endif // V8_TARGET_ARCH_ARM 539 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
540
541 #if SIMD_LOWERING_TARGET
542 WASM_EXEC_COMPILED_TEST(F32x4LessThan) {
543 RunF32x4CompareOpTest(kExprF32x4Lt, Less);
544 }
545 WASM_EXEC_COMPILED_TEST(F32x4LessThanOrEqual) {
546 RunF32x4CompareOpTest(kExprF32x4Le, LessEqual);
547 }
548 WASM_EXEC_COMPILED_TEST(F32x4GreaterThan) {
549 RunF32x4CompareOpTest(kExprF32x4Gt, Greater);
550 }
551 WASM_EXEC_COMPILED_TEST(F32x4GreaterThanOrEqual) {
552 RunF32x4CompareOpTest(kExprF32x4Ge, GreaterEqual);
553 }
554 #endif // SIMD_LOWERING_TARGET
531 555
532 WASM_EXEC_COMPILED_TEST(I32x4Splat) { 556 WASM_EXEC_COMPILED_TEST(I32x4Splat) {
533 FLAG_wasm_simd_prototype = true; 557 FLAG_wasm_simd_prototype = true;
534 558
535 // Store SIMD value in a local variable, use extract lane to check lane values 559 // Store SIMD value in a local variable, use extract lane to check lane values
536 // This test is not a test for ExtractLane as Splat does not create 560 // This test is not a test for ExtractLane as Splat does not create
537 // interesting SIMD values. 561 // interesting SIMD values.
538 // 562 //
539 // SetLocal(1, I32x4Splat(Local(0))); 563 // SetLocal(1, I32x4Splat(Local(0)));
540 // For each lane index 564 // For each lane index
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); 911 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum);
888 } 912 }
889 913
890 WASM_EXEC_COMPILED_TEST(Ui32x4Min) { 914 WASM_EXEC_COMPILED_TEST(Ui32x4Min) {
891 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); 915 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum);
892 } 916 }
893 917
894 WASM_EXEC_COMPILED_TEST(Ui32x4Max) { 918 WASM_EXEC_COMPILED_TEST(Ui32x4Max) {
895 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); 919 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum);
896 } 920 }
897 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
898 921
899 #if V8_TARGET_ARCH_ARM
900 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { 922 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) {
901 FLAG_wasm_simd_prototype = true; 923 FLAG_wasm_simd_prototype = true;
902 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); 924 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
903 byte a = 0; 925 byte a = 0;
904 byte b = 1; 926 byte b = 1;
905 byte expected = 2; 927 byte expected = 2;
906 byte simd0 = r.AllocateLocal(kWasmS128); 928 byte simd0 = r.AllocateLocal(kWasmS128);
907 byte simd1 = r.AllocateLocal(kWasmS128); 929 byte simd1 = r.AllocateLocal(kWasmS128);
908 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), 930 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
909 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), 931 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual); 972 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual);
951 } 973 }
952 974
953 WASM_EXEC_COMPILED_TEST(Ui32x4Less) { 975 WASM_EXEC_COMPILED_TEST(Ui32x4Less) {
954 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess); 976 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess);
955 } 977 }
956 978
957 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) { 979 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) {
958 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); 980 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual);
959 } 981 }
960 #endif // V8_TARGET_ARCH_ARM
961 982
962 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET
963 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, 983 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op,
964 int shift) { 984 int shift) {
965 FLAG_wasm_simd_prototype = true; 985 FLAG_wasm_simd_prototype = true;
966 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); 986 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
967 byte a = 0; 987 byte a = 0;
968 byte expected = 1; 988 byte expected = 1;
969 byte simd = r.AllocateLocal(kWasmS128); 989 byte simd = r.AllocateLocal(kWasmS128);
970 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), 990 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
971 WASM_SET_LOCAL( 991 WASM_SET_LOCAL(
972 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), 992 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), 1772 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
1753 WASM_F32(65.0))), 1773 WASM_F32(65.0))),
1754 WASM_I32V(1)); 1774 WASM_I32V(1));
1755 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } 1775 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
1756 CHECK_EQ(*global, 13.5); 1776 CHECK_EQ(*global, 13.5);
1757 CHECK_EQ(*(global + 1), 45.5); 1777 CHECK_EQ(*(global + 1), 45.5);
1758 CHECK_EQ(*(global + 2), 32.25); 1778 CHECK_EQ(*(global + 2), 32.25);
1759 CHECK_EQ(*(global + 3), 65.0); 1779 CHECK_EQ(*(global + 3), 65.0);
1760 } 1780 }
1761 #endif // SIMD_LOWERING_TARGET 1781 #endif // SIMD_LOWERING_TARGET
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698