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/wasm/wasm-macro-gen.h" | 5 #include "src/wasm/wasm-macro-gen.h" |
6 | 6 |
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 |
11 using namespace v8::base; | 11 using namespace v8::base; |
12 using namespace v8::internal; | 12 using namespace v8::internal; |
13 using namespace v8::internal::compiler; | 13 using namespace v8::internal::compiler; |
14 using namespace v8::internal::wasm; | 14 using namespace v8::internal::wasm; |
15 | 15 |
16 WASM_EXEC_TEST(Splat) { | 16 // TODO(gdeepti): These are tests using sample values to verify functional |
17 // correctness of opcodes, add more tests for a range of values and macroize | |
18 // tests. | |
19 | |
20 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \ | |
21 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \ | |
22 WASM_SIMD_##TYPE##_EXTRACT_LANE( \ | |
23 lane_index, WASM_GET_LOCAL(value))), \ | |
24 WASM_RETURN1(WASM_ZERO)) | |
25 | |
26 #define WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3) \ | |
27 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \ | |
28 , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \ | |
29 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \ | |
30 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3), \ | |
31 WASM_RETURN1(WASM_ONE) | |
bbudge
2016/11/22 18:06:42
This is my fault, but if we return 1 here, then we
gdeepti
2016/11/22 22:30:33
Sorry I did not catch this, fixed now to return in
| |
32 | |
33 #define WASM_SIMD_CHECK_SPLAT4(TYPE, value, LANE_TYPE, lv) \ | |
34 WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv, lv, lv, lv) | |
35 | |
36 WASM_EXEC_TEST(I32x4Splat) { | |
17 FLAG_wasm_simd_prototype = true; | 37 FLAG_wasm_simd_prototype = true; |
18 | 38 |
19 // Store SIMD value in a local variable, use extract lane to check lane values | 39 // Store SIMD value in a local variable, use extract lane to check lane values |
20 // This test is not a test for ExtractLane as Splat does not create | 40 // This test is not a test for ExtractLane as Splat does not create |
21 // interesting SIMD values. | 41 // interesting SIMD values. |
22 // | 42 // |
23 // SetLocal(1, I32x4Splat(Local(0))); | 43 // SetLocal(1, I32x4Splat(Local(0))); |
24 // For each lane index | 44 // For each lane index |
25 // if(Local(0) != I32x4ExtractLane(Local(1), index) | 45 // if(Local(0) != I32x4ExtractLane(Local(1), index) |
26 // return 0 | 46 // return 0 |
27 // | 47 // |
28 // return 1 | 48 // return 1 |
29 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); | 49 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); |
30 r.AllocateLocal(kAstS128); | 50 byte lane_val = 0; |
31 BUILD(r, | 51 byte simd = r.AllocateLocal(kAstS128); |
32 WASM_BLOCK( | 52 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT( |
33 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))), | 53 WASM_GET_LOCAL(lane_val))), |
34 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE( | 54 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val))); |
35 0, WASM_GET_LOCAL(1))), | |
36 WASM_RETURN1(WASM_ZERO)), | |
37 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE( | |
38 1, WASM_GET_LOCAL(1))), | |
39 WASM_RETURN1(WASM_ZERO)), | |
40 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE( | |
41 2, WASM_GET_LOCAL(1))), | |
42 WASM_RETURN1(WASM_ZERO)), | |
43 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE( | |
44 3, WASM_GET_LOCAL(1))), | |
45 WASM_RETURN1(WASM_ZERO)), | |
46 WASM_RETURN1(WASM_ONE))); | |
47 | 55 |
48 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } | 56 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } |
49 } | 57 } |
58 | |
59 WASM_EXEC_TEST(I32x4ReplaceLane) { | |
60 FLAG_wasm_simd_prototype = true; | |
61 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), | |
62 MachineType::Int32()); | |
63 byte old_val = 0; | |
64 byte new_val = 1; | |
65 byte simd = r.AllocateLocal(kAstS128); | |
66 BUILD(r, WASM_BLOCK( | |
67 WASM_SET_LOCAL(simd, | |
68 WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))), | |
69 WASM_SET_LOCAL( | |
70 simd, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd), | |
71 WASM_GET_LOCAL(new_val))), | |
72 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, | |
73 old_val), | |
74 WASM_SET_LOCAL( | |
75 simd, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd), | |
76 WASM_GET_LOCAL(new_val))), | |
77 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val, | |
78 old_val), | |
79 WASM_SET_LOCAL( | |
80 simd, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd), | |
81 WASM_GET_LOCAL(new_val))), | |
82 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, | |
83 old_val), | |
84 WASM_SET_LOCAL( | |
85 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), | |
86 WASM_GET_LOCAL(new_val))), | |
87 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val))); | |
88 | |
89 CHECK_EQ(1, r.Call(1, 2)); | |
90 } | |
91 | |
92 WASM_EXEC_TEST(I32x4Add) { | |
93 FLAG_wasm_simd_prototype = true; | |
94 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), | |
95 MachineType::Int32(), MachineType::Int32()); | |
96 byte a = 0; | |
97 byte b = 1; | |
98 byte expected = 2; | |
99 byte simd0 = r.AllocateLocal(kAstS128); | |
100 byte simd1 = r.AllocateLocal(kAstS128); | |
101 BUILD(r, | |
102 WASM_BLOCK( | |
103 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | |
104 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | |
105 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(simd0), | |
106 WASM_GET_LOCAL(simd1))), | |
107 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected))); | |
108 | |
109 FOR_INT32_INPUTS(i) { | |
110 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i + *j)); } | |
111 } | |
112 } | |
113 | |
114 WASM_EXEC_TEST(I32x4Sub) { | |
115 FLAG_wasm_simd_prototype = true; | |
116 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), | |
117 MachineType::Int32(), MachineType::Int32()); | |
118 byte a = 0; | |
119 byte b = 1; | |
120 byte expected = 2; | |
121 byte simd0 = r.AllocateLocal(kAstS128); | |
122 byte simd1 = r.AllocateLocal(kAstS128); | |
123 BUILD(r, | |
124 WASM_BLOCK( | |
125 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | |
126 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | |
127 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(simd0), | |
128 WASM_GET_LOCAL(simd1))), | |
129 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected))); | |
130 | |
131 FOR_INT32_INPUTS(i) { | |
132 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i - *j)); } | |
133 } | |
134 } | |
OLD | NEW |