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

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

Issue 2713613005: [wasm]implement simd lowering for F32x4 and I32x4 binops (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 | « test/cctest/wasm/test-run-wasm-simd.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/wasm/wasm-macro-gen.h"
6 #include "src/wasm/wasm-module.h"
7
8 #include "test/cctest/cctest.h"
9 #include "test/cctest/compiler/value-helper.h"
10 #include "test/cctest/wasm/wasm-run-utils.h"
11 #include "test/common/wasm/test-signatures.h"
12
13 using namespace v8::base;
14 using namespace v8::internal;
15 using namespace v8::internal::compiler;
16 using namespace v8::internal::wasm;
17
18 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat) {
19 FLAG_wasm_simd_prototype = true;
20 WasmRunner<int32_t> r(kExecuteCompiled);
21 BUILD(r,
22 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(5))));
23 FOR_INT32_INPUTS(i) { CHECK_EQ(5, r.Call()); }
24 }
25
26 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add) {
27 FLAG_wasm_simd_prototype = true;
28 WasmRunner<int32_t> r(kExecuteCompiled);
29 BUILD(r, WASM_SIMD_I32x4_EXTRACT_LANE(
30 0, WASM_SIMD_I32x4_ADD(WASM_SIMD_I32x4_SPLAT(WASM_I32V(5)),
31 WASM_SIMD_I32x4_SPLAT(WASM_I32V(6)))));
32 FOR_INT32_INPUTS(i) { CHECK_EQ(11, r.Call()); }
33 }
34
35 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) {
36 FLAG_wasm_simd_prototype = true;
37 WasmRunner<int32_t> r(kExecuteCompiled);
38 BUILD(r,
39 WASM_IF_ELSE_I(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
40 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(9.5))),
41 WASM_F32(9.5)),
42 WASM_I32V(1), WASM_I32V(0)));
43 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
44 }
45
46 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) {
47 FLAG_wasm_simd_prototype = true;
48 WasmRunner<int32_t> r(kExecuteCompiled);
49 BUILD(r, WASM_IF_ELSE_I(
50 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
51 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
52 WASM_I32_REINTERPRET_F32(WASM_F32(30.5))),
53 WASM_I32V(1), WASM_I32V(0)));
54 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
55 }
56
57 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) {
58 FLAG_wasm_simd_prototype = true;
59 WasmRunner<int32_t> r(kExecuteCompiled);
60 BUILD(r,
61 WASM_IF_ELSE_I(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
62 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))),
63 WASM_F32_REINTERPRET_I32(WASM_I32V(15))),
64 WASM_I32V(1), WASM_I32V(0)));
65 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
66 }
67
68 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) {
69 FLAG_wasm_simd_prototype = true;
70 WasmRunner<int32_t> r(kExecuteCompiled);
71 BUILD(r,
72 WASM_IF_ELSE_I(
73 WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
74 0, WASM_SIMD_F32x4_ADD(
75 WASM_SIMD_I32x4_SPLAT(WASM_I32V(32)),
76 WASM_SIMD_I32x4_SPLAT(WASM_I32V(19)))),
77 WASM_F32_ADD(WASM_F32_REINTERPRET_I32(WASM_I32V(32)),
78 WASM_F32_REINTERPRET_I32(WASM_I32V(19)))),
79 WASM_I32V(1), WASM_I32V(0)));
80 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
81 }
82
83 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) {
84 FLAG_wasm_simd_prototype = true;
85 WasmRunner<int32_t> r(kExecuteCompiled);
86 BUILD(r,
87 WASM_IF_ELSE_I(
88 WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
89 0, WASM_SIMD_I32x4_ADD(
90 WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25)),
91 WASM_SIMD_F32x4_SPLAT(WASM_F32(31.5)))),
92 WASM_I32_ADD(WASM_I32_REINTERPRET_F32(WASM_F32(21.25)),
93 WASM_I32_REINTERPRET_F32(WASM_F32(31.5)))),
94 WASM_I32V(1), WASM_I32V(0)));
95 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
96 }
97
98 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Local) {
99 FLAG_wasm_simd_prototype = true;
100 WasmRunner<int32_t> r(kExecuteCompiled);
101 r.AllocateLocal(kWasmS128);
102 BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
103
104 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0)));
105 FOR_INT32_INPUTS(i) { CHECK_EQ(31, r.Call()); }
106 }
107
108 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Replace_Lane) {
109 FLAG_wasm_simd_prototype = true;
110 WasmRunner<int32_t> r(kExecuteCompiled);
111 r.AllocateLocal(kWasmS128);
112 BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
113 WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0),
114 WASM_I32V(53))),
115 WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(0)));
116 FOR_INT32_INPUTS(i) { CHECK_EQ(53, r.Call()); }
117 }
118
119 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) {
120 FLAG_wasm_simd_prototype = true;
121 WasmRunner<int32_t> r(kExecuteCompiled);
122 r.AllocateLocal(kWasmF32);
123 r.AllocateLocal(kWasmS128);
124 BUILD(r, WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))),
125 WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(1),
126 WASM_F32(65.25))),
127 WASM_SET_LOCAL(0, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1))),
128 WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(0), WASM_F32(65.25)),
129 WASM_RETURN1(WASM_I32V(1))),
130 WASM_I32V(0));
131 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
132 }
133
134 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat_From_Extract) {
135 FLAG_wasm_simd_prototype = true;
136 WasmRunner<int32_t> r(kExecuteCompiled);
137 r.AllocateLocal(kWasmI32);
138 r.AllocateLocal(kWasmS128);
139 BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE(
140 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))),
141 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
142 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)));
143 FOR_INT32_INPUTS(i) { CHECK_EQ(76, r.Call()); }
144 }
145
146 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) {
147 FLAG_wasm_simd_prototype = true;
148 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
149 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128);
150 *(global) = 0;
151 *(global + 1) = 1;
152 *(global + 2) = 2;
153 *(global + 3) = 3;
154 r.AllocateLocal(kWasmI32);
155 BUILD(
156 r, WASM_SET_LOCAL(1, WASM_I32V(1)),
157 WASM_IF(WASM_I32_NE(WASM_I32V(0),
158 WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
159 WASM_SET_LOCAL(1, WASM_I32V(0))),
160 WASM_IF(WASM_I32_NE(WASM_I32V(1),
161 WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
162 WASM_SET_LOCAL(1, WASM_I32V(0))),
163 WASM_IF(WASM_I32_NE(WASM_I32V(2),
164 WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(0))),
165 WASM_SET_LOCAL(1, WASM_I32V(0))),
166 WASM_IF(WASM_I32_NE(WASM_I32V(3),
167 WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(0))),
168 WASM_SET_LOCAL(1, WASM_I32V(0))),
169 WASM_GET_LOCAL(1));
170 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
171 }
172
173 WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) {
174 FLAG_wasm_simd_prototype = true;
175 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
176 int32_t* global = r.module().AddGlobal<int32_t>(kWasmS128);
177 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
178 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
179 WASM_I32V(34))),
180 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
181 WASM_I32V(45))),
182 WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
183 WASM_I32V(56))),
184 WASM_I32V(1));
185 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
186 CHECK_EQ(*global, 23);
187 CHECK_EQ(*(global + 1), 34);
188 CHECK_EQ(*(global + 2), 45);
189 CHECK_EQ(*(global + 3), 56);
190 }
191
192 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) {
193 FLAG_wasm_simd_prototype = true;
194 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
195 float* global = r.module().AddGlobal<float>(kWasmS128);
196 *(global) = 0.0;
197 *(global + 1) = 1.5;
198 *(global + 2) = 2.25;
199 *(global + 3) = 3.5;
200 r.AllocateLocal(kWasmI32);
201 BUILD(
202 r, WASM_SET_LOCAL(1, WASM_I32V(1)),
203 WASM_IF(WASM_F32_NE(WASM_F32(0.0),
204 WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
205 WASM_SET_LOCAL(1, WASM_I32V(0))),
206 WASM_IF(WASM_F32_NE(WASM_F32(1.5),
207 WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
208 WASM_SET_LOCAL(1, WASM_I32V(0))),
209 WASM_IF(WASM_F32_NE(WASM_F32(2.25),
210 WASM_SIMD_F32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(0))),
211 WASM_SET_LOCAL(1, WASM_I32V(0))),
212 WASM_IF(WASM_F32_NE(WASM_F32(3.5),
213 WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(0))),
214 WASM_SET_LOCAL(1, WASM_I32V(0))),
215 WASM_GET_LOCAL(1));
216 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
217 }
218
219 WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) {
220 FLAG_wasm_simd_prototype = true;
221 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
222 float* global = r.module().AddGlobal<float>(kWasmS128);
223 BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
224 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
225 WASM_F32(45.5))),
226 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
227 WASM_F32(32.25))),
228 WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
229 WASM_F32(65.0))),
230 WASM_I32V(1));
231 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(0)); }
232 CHECK_EQ(*global, 13.5);
233 CHECK_EQ(*(global + 1), 45.5);
234 CHECK_EQ(*(global + 2), 32.25);
235 CHECK_EQ(*(global + 3), 65.0);
236 }
237
238 WASM_EXEC_COMPILED_TEST(Simd_I32x4_For) {
239 FLAG_wasm_simd_prototype = true;
240 WasmRunner<int32_t> r(kExecuteCompiled);
241 r.AllocateLocal(kWasmI32);
242 r.AllocateLocal(kWasmS128);
243 BUILD(r,
244
245 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
246 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
247 WASM_I32V(53))),
248 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
249 WASM_I32V(23))),
250 WASM_SET_LOCAL(0, WASM_I32V(0)),
251 WASM_LOOP(
252 WASM_SET_LOCAL(
253 1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(1),
254 WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))),
255 WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)), WASM_BR(1))),
256 WASM_SET_LOCAL(0, WASM_I32V(1)),
257 WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
258 WASM_I32V(36)),
259 WASM_SET_LOCAL(0, WASM_I32V(0))),
260 WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)),
261 WASM_I32V(58)),
262 WASM_SET_LOCAL(0, WASM_I32V(0))),
263 WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)),
264 WASM_I32V(28)),
265 WASM_SET_LOCAL(0, WASM_I32V(0))),
266 WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
267 WASM_I32V(36)),
268 WASM_SET_LOCAL(0, WASM_I32V(0))),
269 WASM_GET_LOCAL(0));
270 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
271 }
272
273 WASM_EXEC_COMPILED_TEST(Simd_F32x4_For) {
274 FLAG_wasm_simd_prototype = true;
275 WasmRunner<int32_t> r(kExecuteCompiled);
276 r.AllocateLocal(kWasmI32);
277 r.AllocateLocal(kWasmS128);
278 BUILD(r, WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
279 WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(1),
280 WASM_F32(19.5))),
281 WASM_SET_LOCAL(0, WASM_I32V(0)),
282 WASM_LOOP(
283 WASM_SET_LOCAL(
284 1, WASM_SIMD_F32x4_ADD(WASM_GET_LOCAL(1),
285 WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))),
286 WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)), WASM_BR(1))),
287 WASM_SET_LOCAL(0, WASM_I32V(1)),
288 WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
289 WASM_F32(27.25)),
290 WASM_SET_LOCAL(0, WASM_I32V(0))),
291 WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
292 WASM_F32(25.5)),
293 WASM_SET_LOCAL(0, WASM_I32V(0))),
294 WASM_GET_LOCAL(0));
295 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
296 }
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-simd.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698