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

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

Issue 2385393002: [wasm] Implement I32x4ReplaceLane, I32x4Add, I32x4Sub. (Closed)
Patch Set: Bill's review Created 4 years, 2 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
« src/wasm/ast-decoder.cc ('K') | « src/wasm/wasm-opcodes.h ('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/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 WASM_EXEC_TEST(I32x4Splat) {
17 FLAG_wasm_simd_prototype = true; 21 FLAG_wasm_simd_prototype = true;
18 22
19 // Store SIMD value in a local variable, use extract lane to check lane values 23 // 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 24 // This test is not a test for ExtractLane as Splat does not create
21 // interesting SIMD values. 25 // interesting SIMD values.
22 // 26 //
23 // SetLocal(1, I32x4Splat(Local(0))); 27 // SetLocal(1, I32x4Splat(Local(0)));
24 // For each lane index 28 // For each lane index
25 // if(Local(0) != I32x4ExtractLane(Local(1), index) 29 // if(Local(0) != I32x4ExtractLane(Local(1), index)
26 // return 0 30 // return 0
(...skipping 13 matching lines...) Expand all
40 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE( 44 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
41 2, WASM_GET_LOCAL(1))), 45 2, WASM_GET_LOCAL(1))),
42 WASM_RETURN1(WASM_ZERO)), 46 WASM_RETURN1(WASM_ZERO)),
43 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE( 47 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
44 3, WASM_GET_LOCAL(1))), 48 3, WASM_GET_LOCAL(1))),
45 WASM_RETURN1(WASM_ZERO)), 49 WASM_RETURN1(WASM_ZERO)),
46 WASM_RETURN1(WASM_ONE))); 50 WASM_RETURN1(WASM_ONE)));
47 51
48 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } 52 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
49 } 53 }
54
55 WASM_EXEC_TEST(I32x4ReplaceLane) {
56 FLAG_wasm_simd_prototype = true;
57 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
58 r.AllocateLocal(kAstS128);
59 BUILD(r,
60 WASM_BLOCK(
61 // (0xaced, 0xaced, 0xaced, 0xaced)
62 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
63 // (0xabcd, 0xaced, 0xaced, 0xaced)
64 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(1),
65 WASM_I32V(0xabcd))),
66 // (0xabcd, 0xbcde, 0xaced, 0xaced)
67 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
68 WASM_I32V(0xbcde))),
69 // (0xabcd, 0xbcde, 0xaced, 0xcdef)
70 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
71 WASM_I32V(0xcdef))),
72 WASM_IF(WASM_I32_NE(WASM_I32V(0xabcd), WASM_SIMD_I32x4_EXTRACT_LANE(
73 0, WASM_GET_LOCAL(1))),
74 WASM_RETURN1(WASM_ZERO)),
75 WASM_IF(WASM_I32_NE(WASM_I32V(0xbcde), WASM_SIMD_I32x4_EXTRACT_LANE(
76 1, WASM_GET_LOCAL(1))),
77 WASM_RETURN1(WASM_ZERO)),
78 WASM_IF(WASM_I32_NE(WASM_I32V(0xcdef), WASM_SIMD_I32x4_EXTRACT_LANE(
79 2, WASM_GET_LOCAL(1))),
80 WASM_RETURN1(WASM_ZERO)),
81 WASM_IF(WASM_I32_NE(WASM_I32V(0xaced), WASM_SIMD_I32x4_EXTRACT_LANE(
82 3, WASM_GET_LOCAL(1))),
83 WASM_RETURN1(WASM_ZERO)),
84 WASM_RETURN1(WASM_ONE)));
85
86 CHECK_EQ(1, r.Call(0xaced));
87 }
88
89 WASM_EXEC_TEST(I32x4Add) {
titzer 2016/10/07 12:20:14 I think these tests can get a bit simpler. E.g. wh
gdeepti 2016/11/22 01:15:20 bbudge@ suggested using only splat values instead
90 FLAG_wasm_simd_prototype = true;
91 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
92 MachineType::Int32());
93 r.AllocateLocal(kAstS128);
94 r.AllocateLocal(kAstS128);
95 BUILD(r,
96 WASM_BLOCK(
97 // (0x1111, 0x1111, 0x1111, 0x1111)
98 WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
99 // (0x2222, 0x2222, 0x2222, 0x2222)
100 WASM_SET_LOCAL(3, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(1))),
101 // (0x3333, 0x3333, 0x3333, 0x3333)
102 WASM_SET_LOCAL(
103 3, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(2), WASM_GET_LOCAL(3))),
104 WASM_IF(WASM_I32_NE(WASM_I32V(0x3333), WASM_SIMD_I32x4_EXTRACT_LANE(
105 0, WASM_GET_LOCAL(3))),
106 WASM_RETURN1(WASM_ZERO)),
107 WASM_IF(WASM_I32_NE(WASM_I32V(0x3333), WASM_SIMD_I32x4_EXTRACT_LANE(
108 1, WASM_GET_LOCAL(3))),
109 WASM_RETURN1(WASM_ZERO)),
110 WASM_IF(WASM_I32_NE(WASM_I32V(0x3333), WASM_SIMD_I32x4_EXTRACT_LANE(
111 2, WASM_GET_LOCAL(3))),
112 WASM_RETURN1(WASM_ZERO)),
113 WASM_IF(WASM_I32_NE(WASM_I32V(0x3333), WASM_SIMD_I32x4_EXTRACT_LANE(
114 3, WASM_GET_LOCAL(3))),
115 WASM_RETURN1(WASM_ZERO)),
116 WASM_RETURN1(WASM_ONE)));
117
118 CHECK_EQ(1, r.Call(0x1111, 0x2222));
119 }
120
121 WASM_EXEC_TEST(I32x4Sub) {
122 FLAG_wasm_simd_prototype = true;
123
124 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
125 MachineType::Int32());
126 r.AllocateLocal(kAstS128);
127 r.AllocateLocal(kAstS128);
128 BUILD(r,
129 WASM_BLOCK(
130 // (0xbf21, 0xbf21, 0xbf21, 0xbf21)
131 WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
132 // (0x1234, 0x1234, 0x1234, 0x1234)
133 WASM_SET_LOCAL(3, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(1))),
134 // (0xaced, 0xaced, 0xaced, 0xaced)
135 WASM_SET_LOCAL(
136 3, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(2), WASM_GET_LOCAL(3))),
137 WASM_IF(WASM_I32_NE(WASM_I32V(0xaced), WASM_SIMD_I32x4_EXTRACT_LANE(
138 0, WASM_GET_LOCAL(3))),
139 WASM_RETURN1(WASM_ZERO)),
140 WASM_IF(WASM_I32_NE(WASM_I32V(0xaced), WASM_SIMD_I32x4_EXTRACT_LANE(
141 1, WASM_GET_LOCAL(3))),
142 WASM_RETURN1(WASM_ZERO)),
143 WASM_IF(WASM_I32_NE(WASM_I32V(0xaced), WASM_SIMD_I32x4_EXTRACT_LANE(
144 2, WASM_GET_LOCAL(3))),
145 WASM_RETURN1(WASM_ZERO)),
146 WASM_IF(WASM_I32_NE(WASM_I32V(0xaced), WASM_SIMD_I32x4_EXTRACT_LANE(
147 3, WASM_GET_LOCAL(3))),
148 WASM_RETURN1(WASM_ZERO)),
149 WASM_RETURN1(WASM_ONE)));
150
151 CHECK_EQ(1, r.Call(0xBF21, 0x1234));
152 }
153
154 WASM_EXEC_TEST(I32x4AddReplace) {
155 FLAG_wasm_simd_prototype = true;
156 WasmRunner<int32_t> r(kExecuteCompiled);
157 r.AllocateLocal(kAstS128);
158 r.AllocateLocal(kAstS128);
159 BUILD(r,
160 WASM_BLOCK(
161 // (0x1357, 0x1357, 0x1357, 0x1357)
162 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(0x1357))),
163 // (0x3579, 0x1357, 0x1357, 0x1357)
164 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(0),
165 WASM_I32V(0x3579))),
166 // (0x3579, 0x5791, 0x1357, 0x1357)
167 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(0),
168 WASM_I32V(0x5791))),
169 // (0x3579, 0x5791, 0x7915, 0x1357)
170 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0),
171 WASM_I32V(0x7915))),
172 // (0x5432, 0x5432, 0x5432, 0x5432)
173 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(0x5432))),
174 // (0x3219, 0x5432, 0x5432, 0x5432)
175 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(1),
176 WASM_I32V(0x3219))),
177 // (0x3219, 0x2198, 0x5432, 0x5432)
178 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
179 WASM_I32V(0x2198))),
180 // (0x3219, 0x2198, 0x1987, 0x5432)
181 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
182 WASM_I32V(0x1987))),
183 // (0x6792, 0x7929, 0x929c, 0x6789)
184 WASM_SET_LOCAL(
185 0, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))),
186 WASM_IF(WASM_I32_NE(WASM_I32V(0x6792), WASM_SIMD_I32x4_EXTRACT_LANE(
187 0, WASM_GET_LOCAL(0))),
188 WASM_RETURN1(WASM_ZERO)),
189 WASM_IF(WASM_I32_NE(WASM_I32V(0x7929), WASM_SIMD_I32x4_EXTRACT_LANE(
190 1, WASM_GET_LOCAL(0))),
191 WASM_RETURN1(WASM_ZERO)),
192 WASM_IF(WASM_I32_NE(WASM_I32V(0x929c), WASM_SIMD_I32x4_EXTRACT_LANE(
193 2, WASM_GET_LOCAL(0))),
194 WASM_RETURN1(WASM_ZERO)),
195 WASM_IF(WASM_I32_NE(WASM_I32V(0x6789), WASM_SIMD_I32x4_EXTRACT_LANE(
196 3, WASM_GET_LOCAL(0))),
197 WASM_RETURN1(WASM_ZERO)),
198 WASM_RETURN1(WASM_ONE)));
199
200 CHECK_EQ(1, r.Call());
201 }
202
203 WASM_EXEC_TEST(I32x4SubReplace) {
204 FLAG_wasm_simd_prototype = true;
205 WasmRunner<int32_t> r(kExecuteCompiled);
206 r.AllocateLocal(kAstS128);
207 r.AllocateLocal(kAstS128);
208 BUILD(r,
209 WASM_BLOCK(
210 // (0xfedc, 0xfedc, 0xfedc, 0xfedc)
211 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(0xfedc))),
212 // (0xcba9, 0xfedc, 0xfedc, 0xfedc)
213 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(0),
214 WASM_I32V(0xcba9))),
215 // (0xcba9, 0xdcba, 0xfedc, 0xfedc)
216 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(0),
217 WASM_I32V(0xdcba))),
218 // (0xcba9, 0xdcba, 0xedcb, 0xfedc)
219 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0),
220 WASM_I32V(0xedcb))),
221 // (0x1234, 0x1234, 0x1234, 0x1234)
222 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(0x1234))),
223 // (0x4567, 0x1234, 0x1234, 0x1234)
224 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(1),
225 WASM_I32V(0x4567))),
226 // (0x4567, 0x3456, 0x1234, 0x1234)
227 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
228 WASM_I32V(0x3456))),
229 // (0x4567, 0x3456, 0x2345, 0x1234)
230 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
231 WASM_I32V(0x2345))),
232 // (0x8642, 0xa864, 0xca86, 0xeca8)
233 WASM_SET_LOCAL(
234 0, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))),
235 WASM_IF(WASM_I32_NE(WASM_I32V(0x8642), WASM_SIMD_I32x4_EXTRACT_LANE(
236 0, WASM_GET_LOCAL(0))),
237 WASM_RETURN1(WASM_ZERO)),
238 WASM_IF(WASM_I32_NE(WASM_I32V(0xa864), WASM_SIMD_I32x4_EXTRACT_LANE(
239 1, WASM_GET_LOCAL(0))),
240 WASM_RETURN1(WASM_ZERO)),
241 WASM_IF(WASM_I32_NE(WASM_I32V(0xca86), WASM_SIMD_I32x4_EXTRACT_LANE(
242 2, WASM_GET_LOCAL(0))),
243 WASM_RETURN1(WASM_ZERO)),
244 WASM_IF(WASM_I32_NE(WASM_I32V(0xeca8), WASM_SIMD_I32x4_EXTRACT_LANE(
245 3, WASM_GET_LOCAL(0))),
246 WASM_RETURN1(WASM_ZERO)),
247 WASM_RETURN1(WASM_ONE)));
248
249 CHECK_EQ(1, r.Call());
250 }
OLDNEW
« src/wasm/ast-decoder.cc ('K') | « src/wasm/wasm-opcodes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698