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 10 matching lines...) Expand all Loading... |
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 return ~a; | 227 return ~a; |
213 } | 228 } |
214 | 229 |
215 template <typename T> | 230 template <typename T> |
216 T Sqrt(T a) { | 231 T Sqrt(T a) { |
217 return std::sqrt(a); | 232 return std::sqrt(a); |
218 } | 233 } |
219 | 234 |
220 } // namespace | 235 } // namespace |
221 | 236 |
222 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 | |
223 #define SIMD_LOWERING_TARGET 1 | |
224 #else | |
225 #define SIMD_LOWERING_TARGET 0 | |
226 #endif // !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_X64 | |
227 | |
228 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \ | 237 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \ |
229 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \ | 238 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \ |
230 WASM_SIMD_##TYPE##_EXTRACT_LANE( \ | 239 WASM_SIMD_##TYPE##_EXTRACT_LANE( \ |
231 lane_index, WASM_GET_LOCAL(value))), \ | 240 lane_index, WASM_GET_LOCAL(value))), \ |
232 WASM_RETURN1(WASM_ZERO)) | 241 WASM_RETURN1(WASM_ZERO)) |
233 | 242 |
234 #define WASM_SIMD_CHECK_F32_LANE(value, lane_value, lane_index) \ | 243 #define WASM_SIMD_CHECK_F32_LANE(value, lane_value, lane_index) \ |
235 WASM_IF(WASM_F32_NE(WASM_GET_LOCAL(lane_value), \ | 244 WASM_IF(WASM_F32_NE(WASM_GET_LOCAL(lane_value), \ |
236 WASM_SIMD_F32x4_EXTRACT_LANE(lane_index, \ | 245 WASM_SIMD_F32x4_EXTRACT_LANE(lane_index, \ |
237 WASM_GET_LOCAL(value))), \ | 246 WASM_GET_LOCAL(value))), \ |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 WASM_EXEC_COMPILED_TEST(F32x4Mul) { RunF32x4BinOpTest(kExprF32x4Mul, Mul); } | 489 WASM_EXEC_COMPILED_TEST(F32x4Mul) { RunF32x4BinOpTest(kExprF32x4Mul, Mul); } |
481 WASM_EXEC_COMPILED_TEST(F32x4Div) { RunF32x4BinOpTest(kExprF32x4Div, Div); } | 490 WASM_EXEC_COMPILED_TEST(F32x4Div) { RunF32x4BinOpTest(kExprF32x4Div, Div); } |
482 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Min) { | 491 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Min) { |
483 RunF32x4BinOpTest(kExprF32x4Min, Minimum); | 492 RunF32x4BinOpTest(kExprF32x4Min, Minimum); |
484 } | 493 } |
485 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Max) { | 494 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Max) { |
486 RunF32x4BinOpTest(kExprF32x4Max, Maximum); | 495 RunF32x4BinOpTest(kExprF32x4Max, Maximum); |
487 } | 496 } |
488 #endif // SIMD_LOWERING_TARGET | 497 #endif // SIMD_LOWERING_TARGET |
489 | 498 |
490 #if V8_TARGET_ARCH_ARM | 499 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
491 void RunF32x4CompareOpTest(WasmOpcode simd_op, FloatCompareOp expected_op) { | 500 void RunF32x4CompareOpTest(WasmOpcode simd_op, FloatCompareOp expected_op) { |
492 FLAG_wasm_simd_prototype = true; | 501 FLAG_wasm_simd_prototype = true; |
493 WasmRunner<int32_t, float, float, int32_t> r(kExecuteCompiled); | 502 WasmRunner<int32_t, float, float, int32_t> r(kExecuteCompiled); |
494 byte a = 0; | 503 byte a = 0; |
495 byte b = 1; | 504 byte b = 1; |
496 byte expected = 2; | 505 byte expected = 2; |
497 byte simd0 = r.AllocateLocal(kWasmS128); | 506 byte simd0 = r.AllocateLocal(kWasmS128); |
498 byte simd1 = r.AllocateLocal(kWasmS128); | 507 byte simd1 = r.AllocateLocal(kWasmS128); |
499 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), | 508 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))), |
500 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))), | 509 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))), |
(...skipping 14 matching lines...) Expand all Loading... |
515 } | 524 } |
516 } | 525 } |
517 | 526 |
518 WASM_EXEC_COMPILED_TEST(F32x4Equal) { | 527 WASM_EXEC_COMPILED_TEST(F32x4Equal) { |
519 RunF32x4CompareOpTest(kExprF32x4Eq, Equal); | 528 RunF32x4CompareOpTest(kExprF32x4Eq, Equal); |
520 } | 529 } |
521 | 530 |
522 WASM_EXEC_COMPILED_TEST(F32x4NotEqual) { | 531 WASM_EXEC_COMPILED_TEST(F32x4NotEqual) { |
523 RunF32x4CompareOpTest(kExprF32x4Ne, NotEqual); | 532 RunF32x4CompareOpTest(kExprF32x4Ne, NotEqual); |
524 } | 533 } |
525 #endif // V8_TARGET_ARCH_ARM | 534 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET |
| 535 |
| 536 #if SIMD_LOWERING_TARGET |
| 537 WASM_EXEC_COMPILED_TEST(F32x4LessThan) { |
| 538 RunF32x4CompareOpTest(kExprF32x4Lt, Less); |
| 539 } |
| 540 WASM_EXEC_COMPILED_TEST(F32x4LessThanOrEqual) { |
| 541 RunF32x4CompareOpTest(kExprF32x4Le, LessEqual); |
| 542 } |
| 543 WASM_EXEC_COMPILED_TEST(F32x4GreaterThan) { |
| 544 RunF32x4CompareOpTest(kExprF32x4Gt, Greater); |
| 545 } |
| 546 WASM_EXEC_COMPILED_TEST(F32x4GreaterThanOrEqual) { |
| 547 RunF32x4CompareOpTest(kExprF32x4Ge, GreaterEqual); |
| 548 } |
| 549 #endif // SIMD_LOWERING_TARGET |
526 | 550 |
527 WASM_EXEC_COMPILED_TEST(I32x4Splat) { | 551 WASM_EXEC_COMPILED_TEST(I32x4Splat) { |
528 FLAG_wasm_simd_prototype = true; | 552 FLAG_wasm_simd_prototype = true; |
529 | 553 |
530 // Store SIMD value in a local variable, use extract lane to check lane values | 554 // Store SIMD value in a local variable, use extract lane to check lane values |
531 // This test is not a test for ExtractLane as Splat does not create | 555 // This test is not a test for ExtractLane as Splat does not create |
532 // interesting SIMD values. | 556 // interesting SIMD values. |
533 // | 557 // |
534 // SetLocal(1, I32x4Splat(Local(0))); | 558 // SetLocal(1, I32x4Splat(Local(0))); |
535 // For each lane index | 559 // For each lane index |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); | 906 RunI32x4BinOpTest(kExprI32x4MaxS, Maximum); |
883 } | 907 } |
884 | 908 |
885 WASM_EXEC_COMPILED_TEST(Ui32x4Min) { | 909 WASM_EXEC_COMPILED_TEST(Ui32x4Min) { |
886 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); | 910 RunI32x4BinOpTest(kExprI32x4MinU, UnsignedMinimum); |
887 } | 911 } |
888 | 912 |
889 WASM_EXEC_COMPILED_TEST(Ui32x4Max) { | 913 WASM_EXEC_COMPILED_TEST(Ui32x4Max) { |
890 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); | 914 RunI32x4BinOpTest(kExprI32x4MaxU, UnsignedMaximum); |
891 } | 915 } |
892 #endif // V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | |
893 | 916 |
894 #if V8_TARGET_ARCH_ARM | |
895 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { | 917 void RunI32x4CompareOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { |
896 FLAG_wasm_simd_prototype = true; | 918 FLAG_wasm_simd_prototype = true; |
897 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); | 919 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); |
898 byte a = 0; | 920 byte a = 0; |
899 byte b = 1; | 921 byte b = 1; |
900 byte expected = 2; | 922 byte expected = 2; |
901 byte simd0 = r.AllocateLocal(kWasmS128); | 923 byte simd0 = r.AllocateLocal(kWasmS128); |
902 byte simd1 = r.AllocateLocal(kWasmS128); | 924 byte simd1 = r.AllocateLocal(kWasmS128); |
903 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 925 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
904 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | 926 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual); | 967 RunI32x4CompareOpTest(kExprI32x4GeU, UnsignedGreaterEqual); |
946 } | 968 } |
947 | 969 |
948 WASM_EXEC_COMPILED_TEST(Ui32x4Less) { | 970 WASM_EXEC_COMPILED_TEST(Ui32x4Less) { |
949 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess); | 971 RunI32x4CompareOpTest(kExprI32x4LtU, UnsignedLess); |
950 } | 972 } |
951 | 973 |
952 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) { | 974 WASM_EXEC_COMPILED_TEST(Ui32x4LessEqual) { |
953 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); | 975 RunI32x4CompareOpTest(kExprI32x4LeU, UnsignedLessEqual); |
954 } | 976 } |
955 #endif // V8_TARGET_ARCH_ARM | |
956 | 977 |
957 #if V8_TARGET_ARCH_ARM || SIMD_LOWERING_TARGET | |
958 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, | 978 void RunI32x4ShiftOpTest(WasmOpcode simd_op, Int32ShiftOp expected_op, |
959 int shift) { | 979 int shift) { |
960 FLAG_wasm_simd_prototype = true; | 980 FLAG_wasm_simd_prototype = true; |
961 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 981 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); |
962 byte a = 0; | 982 byte a = 0; |
963 byte expected = 1; | 983 byte expected = 1; |
964 byte simd = r.AllocateLocal(kWasmS128); | 984 byte simd = r.AllocateLocal(kWasmS128); |
965 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 985 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
966 WASM_SET_LOCAL( | 986 WASM_SET_LOCAL( |
967 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), | 987 simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))), |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), | 1591 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0), |
1572 WASM_F32(65.0))), | 1592 WASM_F32(65.0))), |
1573 WASM_I32V(1)); | 1593 WASM_I32V(1)); |
1574 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } | 1594 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); } |
1575 CHECK_EQ(*global, 13.5); | 1595 CHECK_EQ(*global, 13.5); |
1576 CHECK_EQ(*(global + 1), 45.5); | 1596 CHECK_EQ(*(global + 1), 45.5); |
1577 CHECK_EQ(*(global + 2), 32.25); | 1597 CHECK_EQ(*(global + 2), 32.25); |
1578 CHECK_EQ(*(global + 3), 65.0); | 1598 CHECK_EQ(*(global + 3), 65.0); |
1579 } | 1599 } |
1580 #endif // SIMD_LOWERING_TARGET | 1600 #endif // SIMD_LOWERING_TARGET |
OLD | NEW |