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 |
(...skipping 27 matching lines...) Expand all Loading... |
38 // Store SIMD value in a local variable, use extract lane to check lane values | 38 // Store SIMD value in a local variable, use extract lane to check lane values |
39 // This test is not a test for ExtractLane as Splat does not create | 39 // This test is not a test for ExtractLane as Splat does not create |
40 // interesting SIMD values. | 40 // interesting SIMD values. |
41 // | 41 // |
42 // SetLocal(1, I32x4Splat(Local(0))); | 42 // SetLocal(1, I32x4Splat(Local(0))); |
43 // For each lane index | 43 // For each lane index |
44 // if(Local(0) != I32x4ExtractLane(Local(1), index) | 44 // if(Local(0) != I32x4ExtractLane(Local(1), index) |
45 // return 0 | 45 // return 0 |
46 // | 46 // |
47 // return 1 | 47 // return 1 |
48 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); | 48 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); |
49 byte lane_val = 0; | 49 byte lane_val = 0; |
50 byte simd = r.AllocateLocal(kAstS128); | 50 byte simd = r.AllocateLocal(kAstS128); |
51 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT( | 51 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT( |
52 WASM_GET_LOCAL(lane_val))), | 52 WASM_GET_LOCAL(lane_val))), |
53 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), | 53 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), |
54 WASM_RETURN1(WASM_ONE))); | 54 WASM_RETURN1(WASM_ONE))); |
55 | 55 |
56 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } | 56 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } |
57 } | 57 } |
58 | 58 |
59 WASM_EXEC_TEST(I32x4ReplaceLane) { | 59 WASM_EXEC_TEST(I32x4ReplaceLane) { |
60 FLAG_wasm_simd_prototype = true; | 60 FLAG_wasm_simd_prototype = true; |
61 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); | 61 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), |
| 62 MachineType::Int32()); |
62 byte old_val = 0; | 63 byte old_val = 0; |
63 byte new_val = 1; | 64 byte new_val = 1; |
64 byte simd = r.AllocateLocal(kAstS128); | 65 byte simd = r.AllocateLocal(kAstS128); |
65 BUILD(r, WASM_BLOCK( | 66 BUILD(r, WASM_BLOCK( |
66 WASM_SET_LOCAL(simd, | 67 WASM_SET_LOCAL(simd, |
67 WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))), | 68 WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))), |
68 WASM_SET_LOCAL( | 69 WASM_SET_LOCAL( |
69 simd, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd), | 70 simd, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd), |
70 WASM_GET_LOCAL(new_val))), | 71 WASM_GET_LOCAL(new_val))), |
71 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, | 72 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, |
(...skipping 12 matching lines...) Expand all Loading... |
84 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), | 85 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), |
85 WASM_GET_LOCAL(new_val))), | 86 WASM_GET_LOCAL(new_val))), |
86 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), | 87 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), |
87 WASM_RETURN1(WASM_ONE))); | 88 WASM_RETURN1(WASM_ONE))); |
88 | 89 |
89 CHECK_EQ(1, r.Call(1, 2)); | 90 CHECK_EQ(1, r.Call(1, 2)); |
90 } | 91 } |
91 | 92 |
92 WASM_EXEC_TEST(I32x4Add) { | 93 WASM_EXEC_TEST(I32x4Add) { |
93 FLAG_wasm_simd_prototype = true; | 94 FLAG_wasm_simd_prototype = true; |
94 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); | 95 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), |
| 96 MachineType::Int32(), MachineType::Int32()); |
95 byte a = 0; | 97 byte a = 0; |
96 byte b = 1; | 98 byte b = 1; |
97 byte expected = 2; | 99 byte expected = 2; |
98 byte simd0 = r.AllocateLocal(kAstS128); | 100 byte simd0 = r.AllocateLocal(kAstS128); |
99 byte simd1 = r.AllocateLocal(kAstS128); | 101 byte simd1 = r.AllocateLocal(kAstS128); |
100 BUILD(r, | 102 BUILD(r, |
101 WASM_BLOCK( | 103 WASM_BLOCK( |
102 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 104 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
103 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | 105 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), |
104 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(simd0), | 106 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(simd0), |
105 WASM_GET_LOCAL(simd1))), | 107 WASM_GET_LOCAL(simd1))), |
106 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), | 108 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), |
107 WASM_RETURN1(WASM_ONE))); | 109 WASM_RETURN1(WASM_ONE))); |
108 | 110 |
109 FOR_INT32_INPUTS(i) { | 111 FOR_INT32_INPUTS(i) { |
110 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i + *j)); } | 112 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i + *j)); } |
111 } | 113 } |
112 } | 114 } |
113 | 115 |
114 WASM_EXEC_TEST(I32x4Sub) { | 116 WASM_EXEC_TEST(I32x4Sub) { |
115 FLAG_wasm_simd_prototype = true; | 117 FLAG_wasm_simd_prototype = true; |
116 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); | 118 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(), |
| 119 MachineType::Int32(), MachineType::Int32()); |
117 byte a = 0; | 120 byte a = 0; |
118 byte b = 1; | 121 byte b = 1; |
119 byte expected = 2; | 122 byte expected = 2; |
120 byte simd0 = r.AllocateLocal(kAstS128); | 123 byte simd0 = r.AllocateLocal(kAstS128); |
121 byte simd1 = r.AllocateLocal(kAstS128); | 124 byte simd1 = r.AllocateLocal(kAstS128); |
122 BUILD(r, | 125 BUILD(r, |
123 WASM_BLOCK( | 126 WASM_BLOCK( |
124 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), | 127 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), |
125 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), | 128 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), |
126 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(simd0), | 129 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(simd0), |
127 WASM_GET_LOCAL(simd1))), | 130 WASM_GET_LOCAL(simd1))), |
128 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), | 131 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), |
129 WASM_RETURN1(WASM_ONE))); | 132 WASM_RETURN1(WASM_ONE))); |
130 | 133 |
131 FOR_INT32_INPUTS(i) { | 134 FOR_INT32_INPUTS(i) { |
132 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i - *j)); } | 135 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i - *j)); } |
133 } | 136 } |
134 } | 137 } |
OLD | NEW |