Line data Source code
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 <type_traits>
6 :
7 : #include "src/assembler-inl.h"
8 : #include "src/base/bits.h"
9 : #include "src/base/overflowing-math.h"
10 : #include "test/cctest/cctest.h"
11 : #include "test/cctest/compiler/value-helper.h"
12 : #include "test/cctest/wasm/wasm-run-utils.h"
13 : #include "test/common/wasm/wasm-macro-gen.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 : namespace wasm {
18 : namespace test_run_wasm_simd {
19 :
20 : namespace {
21 :
22 : typedef float (*FloatUnOp)(float);
23 : typedef float (*FloatBinOp)(float, float);
24 : typedef int (*FloatCompareOp)(float, float);
25 : typedef int32_t (*Int32UnOp)(int32_t);
26 : typedef int32_t (*Int32BinOp)(int32_t, int32_t);
27 : typedef int (*Int32CompareOp)(int32_t, int32_t);
28 : typedef int32_t (*Int32ShiftOp)(int32_t, int);
29 : typedef int16_t (*Int16UnOp)(int16_t);
30 : typedef int16_t (*Int16BinOp)(int16_t, int16_t);
31 : typedef int (*Int16CompareOp)(int16_t, int16_t);
32 : typedef int16_t (*Int16ShiftOp)(int16_t, int);
33 : typedef int8_t (*Int8UnOp)(int8_t);
34 : typedef int8_t (*Int8BinOp)(int8_t, int8_t);
35 : typedef int (*Int8CompareOp)(int8_t, int8_t);
36 : typedef int8_t (*Int8ShiftOp)(int8_t, int);
37 :
38 : #define WASM_SIMD_TEST(name) \
39 : void RunWasm_##name##_Impl(LowerSimd lower_simd, \
40 : ExecutionTier execution_tier); \
41 : TEST(RunWasm_##name##_turbofan) { \
42 : EXPERIMENTAL_FLAG_SCOPE(simd); \
43 : RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kOptimized); \
44 : } \
45 : TEST(RunWasm_##name##_interpreter) { \
46 : EXPERIMENTAL_FLAG_SCOPE(simd); \
47 : RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kInterpreter); \
48 : } \
49 : TEST(RunWasm_##name##_simd_lowered) { \
50 : EXPERIMENTAL_FLAG_SCOPE(simd); \
51 : RunWasm_##name##_Impl(kLowerSimd, ExecutionTier::kOptimized); \
52 : } \
53 : void RunWasm_##name##_Impl(LowerSimd lower_simd, ExecutionTier execution_tier)
54 :
55 : // Generic expected value functions.
56 : template <typename T, typename = typename std::enable_if<
57 : std::is_floating_point<T>::value>::type>
58 1164 : T Negate(T a) {
59 1164 : return -a;
60 : }
61 :
62 : // For signed integral types, use base::AddWithWraparound.
63 : template <typename T, typename = typename std::enable_if<
64 : std::is_floating_point<T>::value>::type>
65 112908 : T Add(T a, T b) {
66 112908 : return a + b;
67 : }
68 :
69 : // For signed integral types, use base::SubWithWraparound.
70 : template <typename T, typename = typename std::enable_if<
71 : std::is_floating_point<T>::value>::type>
72 112908 : T Sub(T a, T b) {
73 112908 : return a - b;
74 : }
75 :
76 : // For signed integral types, use base::MulWithWraparound.
77 : template <typename T, typename = typename std::enable_if<
78 : std::is_floating_point<T>::value>::type>
79 112908 : T Mul(T a, T b) {
80 112908 : return a * b;
81 : }
82 :
83 : template <typename T>
84 42312 : T Minimum(T a, T b) {
85 42312 : return a <= b ? a : b;
86 : }
87 :
88 : template <typename T>
89 42312 : T Maximum(T a, T b) {
90 42312 : return a >= b ? a : b;
91 : }
92 :
93 : template <typename T>
94 42312 : T UnsignedMinimum(T a, T b) {
95 : using UnsignedT = typename std::make_unsigned<T>::type;
96 42312 : return static_cast<UnsignedT>(a) <= static_cast<UnsignedT>(b) ? a : b;
97 : }
98 :
99 : template <typename T>
100 42312 : T UnsignedMaximum(T a, T b) {
101 : using UnsignedT = typename std::make_unsigned<T>::type;
102 42312 : return static_cast<UnsignedT>(a) >= static_cast<UnsignedT>(b) ? a : b;
103 : }
104 :
105 : template <typename T>
106 150612 : int Equal(T a, T b) {
107 150612 : return a == b ? -1 : 0;
108 : }
109 :
110 : template <typename T>
111 150612 : int NotEqual(T a, T b) {
112 150612 : return a != b ? -1 : 0;
113 : }
114 :
115 : template <typename T>
116 150612 : int Less(T a, T b) {
117 150612 : return a < b ? -1 : 0;
118 : }
119 :
120 : template <typename T>
121 150612 : int LessEqual(T a, T b) {
122 150612 : return a <= b ? -1 : 0;
123 : }
124 :
125 : template <typename T>
126 150612 : int Greater(T a, T b) {
127 150612 : return a > b ? -1 : 0;
128 : }
129 :
130 : template <typename T>
131 150612 : int GreaterEqual(T a, T b) {
132 150612 : return a >= b ? -1 : 0;
133 : }
134 :
135 : template <typename T>
136 42312 : int UnsignedLess(T a, T b) {
137 : using UnsignedT = typename std::make_unsigned<T>::type;
138 42312 : return static_cast<UnsignedT>(a) < static_cast<UnsignedT>(b) ? -1 : 0;
139 : }
140 :
141 : template <typename T>
142 42312 : int UnsignedLessEqual(T a, T b) {
143 : using UnsignedT = typename std::make_unsigned<T>::type;
144 42312 : return static_cast<UnsignedT>(a) <= static_cast<UnsignedT>(b) ? -1 : 0;
145 : }
146 :
147 : template <typename T>
148 42312 : int UnsignedGreater(T a, T b) {
149 : using UnsignedT = typename std::make_unsigned<T>::type;
150 42312 : return static_cast<UnsignedT>(a) > static_cast<UnsignedT>(b) ? -1 : 0;
151 : }
152 :
153 : template <typename T>
154 42312 : int UnsignedGreaterEqual(T a, T b) {
155 : using UnsignedT = typename std::make_unsigned<T>::type;
156 42312 : return static_cast<UnsignedT>(a) >= static_cast<UnsignedT>(b) ? -1 : 0;
157 : }
158 :
159 : template <typename T>
160 23952 : T LogicalShiftLeft(T a, int shift) {
161 : using UnsignedT = typename std::make_unsigned<T>::type;
162 23952 : return static_cast<UnsignedT>(a) << shift;
163 : }
164 :
165 : template <typename T>
166 23952 : T LogicalShiftRight(T a, int shift) {
167 : using UnsignedT = typename std::make_unsigned<T>::type;
168 23952 : return static_cast<UnsignedT>(a) >> shift;
169 : }
170 :
171 : template <typename T>
172 : T Clamp(int64_t value) {
173 : static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
174 173136 : int64_t min = static_cast<int64_t>(std::numeric_limits<T>::min());
175 173136 : int64_t max = static_cast<int64_t>(std::numeric_limits<T>::max());
176 173136 : int64_t clamped = std::max(min, std::min(max, value));
177 90456 : return static_cast<T>(clamped);
178 : }
179 :
180 : template <typename T>
181 : int64_t Widen(T value) {
182 : static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
183 4104 : return static_cast<int64_t>(value);
184 : }
185 :
186 : template <typename T>
187 : int64_t UnsignedWiden(T value) {
188 : static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
189 : using UnsignedT = typename std::make_unsigned<T>::type;
190 4104 : return static_cast<int64_t>(static_cast<UnsignedT>(value));
191 : }
192 :
193 : template <typename T>
194 : T Narrow(int64_t value) {
195 : return Clamp<T>(value);
196 : }
197 :
198 : template <typename T>
199 : T UnsignedNarrow(int64_t value) {
200 : static_assert(sizeof(int64_t) > sizeof(T), "T must be int32_t or smaller");
201 : using UnsignedT = typename std::make_unsigned<T>::type;
202 165360 : return static_cast<T>(Clamp<UnsignedT>(value & 0xFFFFFFFFu));
203 : }
204 :
205 : template <typename T>
206 1944 : T AddSaturate(T a, T b) {
207 3888 : return Clamp<T>(Widen(a) + Widen(b));
208 : }
209 :
210 : template <typename T>
211 1944 : T SubSaturate(T a, T b) {
212 3888 : return Clamp<T>(Widen(a) - Widen(b));
213 : }
214 :
215 : template <typename T>
216 1944 : T UnsignedAddSaturate(T a, T b) {
217 : using UnsignedT = typename std::make_unsigned<T>::type;
218 3888 : return Clamp<UnsignedT>(UnsignedWiden(a) + UnsignedWiden(b));
219 : }
220 :
221 : template <typename T>
222 1944 : T UnsignedSubSaturate(T a, T b) {
223 : using UnsignedT = typename std::make_unsigned<T>::type;
224 3888 : return Clamp<UnsignedT>(UnsignedWiden(a) - UnsignedWiden(b));
225 : }
226 :
227 : template <typename T>
228 40368 : T And(T a, T b) {
229 40368 : return a & b;
230 : }
231 :
232 : template <typename T>
233 40368 : T Or(T a, T b) {
234 40368 : return a | b;
235 : }
236 :
237 : template <typename T>
238 40368 : T Xor(T a, T b) {
239 40368 : return a ^ b;
240 : }
241 :
242 : template <typename T>
243 696 : T Not(T a) {
244 696 : return ~a;
245 : }
246 :
247 : template <typename T>
248 : T LogicalNot(T a) {
249 : return a == 0 ? -1 : 0;
250 : }
251 :
252 : template <typename T>
253 : T Sqrt(T a) {
254 : return std::sqrt(a);
255 : }
256 :
257 : } // namespace
258 :
259 : #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \
260 : WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \
261 : WASM_SIMD_##TYPE##_EXTRACT_LANE( \
262 : lane_index, WASM_GET_LOCAL(value))), \
263 : WASM_RETURN1(WASM_ZERO))
264 :
265 : #define WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3) \
266 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \
267 : , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \
268 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \
269 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3)
270 :
271 : #define WASM_SIMD_CHECK_SPLAT4(TYPE, value, LANE_TYPE, lv) \
272 : WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv, lv, lv, lv)
273 :
274 : #define WASM_SIMD_CHECK8(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3, lv4, lv5, \
275 : lv6, lv7) \
276 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \
277 : , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \
278 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \
279 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3), \
280 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv4, 4), \
281 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv5, 5), \
282 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv6, 6), \
283 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv7, 7)
284 :
285 : #define WASM_SIMD_CHECK_SPLAT8(TYPE, value, LANE_TYPE, lv) \
286 : WASM_SIMD_CHECK8(TYPE, value, LANE_TYPE, lv, lv, lv, lv, lv, lv, lv, lv)
287 :
288 : #define WASM_SIMD_CHECK16(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3, lv4, \
289 : lv5, lv6, lv7, lv8, lv9, lv10, lv11, lv12, lv13, \
290 : lv14, lv15) \
291 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \
292 : , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \
293 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \
294 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3), \
295 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv4, 4), \
296 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv5, 5), \
297 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv6, 6), \
298 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv7, 7), \
299 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv8, 8), \
300 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv9, 9), \
301 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv10, 10), \
302 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv11, 11), \
303 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv12, 12), \
304 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv13, 13), \
305 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv14, 14), \
306 : WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv15, 15)
307 :
308 : #define WASM_SIMD_CHECK_SPLAT16(TYPE, value, LANE_TYPE, lv) \
309 : WASM_SIMD_CHECK16(TYPE, value, LANE_TYPE, lv, lv, lv, lv, lv, lv, lv, lv, \
310 : lv, lv, lv, lv, lv, lv, lv, lv)
311 :
312 : #define WASM_SIMD_CHECK_F32_LANE(value, lane_value, lane_index) \
313 : WASM_IF(WASM_F32_NE(WASM_GET_LOCAL(lane_value), \
314 : WASM_SIMD_F32x4_EXTRACT_LANE(lane_index, \
315 : WASM_GET_LOCAL(value))), \
316 : WASM_RETURN1(WASM_ZERO))
317 :
318 : #define WASM_SIMD_CHECK_F32x4(value, lv0, lv1, lv2, lv3) \
319 : WASM_SIMD_CHECK_F32_LANE(value, lv0, 0) \
320 : , WASM_SIMD_CHECK_F32_LANE(value, lv1, 1), \
321 : WASM_SIMD_CHECK_F32_LANE(value, lv2, 2), \
322 : WASM_SIMD_CHECK_F32_LANE(value, lv3, 3)
323 :
324 : #define WASM_SIMD_CHECK_SPLAT_F32x4(value, lv) \
325 : WASM_SIMD_CHECK_F32x4(value, lv, lv, lv, lv)
326 :
327 : #define WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, lane_index) \
328 : WASM_IF(WASM_F32_GT(WASM_GET_LOCAL(low), \
329 : WASM_SIMD_F32x4_EXTRACT_LANE(lane_index, \
330 : WASM_GET_LOCAL(value))), \
331 : WASM_RETURN1(WASM_ZERO)) \
332 : , WASM_IF(WASM_F32_LT(WASM_GET_LOCAL(high), \
333 : WASM_SIMD_F32x4_EXTRACT_LANE(lane_index, \
334 : WASM_GET_LOCAL(value))), \
335 : WASM_RETURN1(WASM_ZERO))
336 :
337 : #define WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE(value, low, high) \
338 : WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 0) \
339 : , WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 1), \
340 : WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 2), \
341 : WASM_SIMD_CHECK_F32_LANE_ESTIMATE(value, low, high, 3)
342 :
343 : #define TO_BYTE(val) static_cast<byte>(val)
344 : #define WASM_SIMD_OP(op) kSimdPrefix, TO_BYTE(op)
345 : #define WASM_SIMD_SPLAT(Type, x) x, WASM_SIMD_OP(kExpr##Type##Splat)
346 : #define WASM_SIMD_UNOP(op, x) x, WASM_SIMD_OP(op)
347 : #define WASM_SIMD_BINOP(op, x, y) x, y, WASM_SIMD_OP(op)
348 : #define WASM_SIMD_SHIFT_OP(op, shift, x) x, WASM_SIMD_OP(op), TO_BYTE(shift)
349 : #define WASM_SIMD_CONCAT_OP(op, bytes, x, y) \
350 : x, y, WASM_SIMD_OP(op), TO_BYTE(bytes)
351 : #define WASM_SIMD_SELECT(format, x, y, z) x, y, z, WASM_SIMD_OP(kExprS128Select)
352 : #define WASM_SIMD_F32x4_SPLAT(x) x, WASM_SIMD_OP(kExprF32x4Splat)
353 : #define WASM_SIMD_F32x4_EXTRACT_LANE(lane, x) \
354 : x, WASM_SIMD_OP(kExprF32x4ExtractLane), TO_BYTE(lane)
355 : #define WASM_SIMD_F32x4_REPLACE_LANE(lane, x, y) \
356 : x, y, WASM_SIMD_OP(kExprF32x4ReplaceLane), TO_BYTE(lane)
357 :
358 : #define WASM_SIMD_I32x4_SPLAT(x) x, WASM_SIMD_OP(kExprI32x4Splat)
359 : #define WASM_SIMD_I32x4_EXTRACT_LANE(lane, x) \
360 : x, WASM_SIMD_OP(kExprI32x4ExtractLane), TO_BYTE(lane)
361 : #define WASM_SIMD_I32x4_REPLACE_LANE(lane, x, y) \
362 : x, y, WASM_SIMD_OP(kExprI32x4ReplaceLane), TO_BYTE(lane)
363 :
364 : #define WASM_SIMD_I16x8_SPLAT(x) x, WASM_SIMD_OP(kExprI16x8Splat)
365 : #define WASM_SIMD_I16x8_EXTRACT_LANE(lane, x) \
366 : x, WASM_SIMD_OP(kExprI16x8ExtractLane), TO_BYTE(lane)
367 : #define WASM_SIMD_I16x8_REPLACE_LANE(lane, x, y) \
368 : x, y, WASM_SIMD_OP(kExprI16x8ReplaceLane), TO_BYTE(lane)
369 :
370 : #define WASM_SIMD_I8x16_SPLAT(x) x, WASM_SIMD_OP(kExprI8x16Splat)
371 : #define WASM_SIMD_I8x16_EXTRACT_LANE(lane, x) \
372 : x, WASM_SIMD_OP(kExprI8x16ExtractLane), TO_BYTE(lane)
373 : #define WASM_SIMD_I8x16_REPLACE_LANE(lane, x, y) \
374 : x, y, WASM_SIMD_OP(kExprI8x16ReplaceLane), TO_BYTE(lane)
375 :
376 : #define WASM_SIMD_S8x16_SHUFFLE_OP(opcode, m, x, y) \
377 : x, y, WASM_SIMD_OP(opcode), TO_BYTE(m[0]), TO_BYTE(m[1]), TO_BYTE(m[2]), \
378 : TO_BYTE(m[3]), TO_BYTE(m[4]), TO_BYTE(m[5]), TO_BYTE(m[6]), \
379 : TO_BYTE(m[7]), TO_BYTE(m[8]), TO_BYTE(m[9]), TO_BYTE(m[10]), \
380 : TO_BYTE(m[11]), TO_BYTE(m[12]), TO_BYTE(m[13]), TO_BYTE(m[14]), \
381 : TO_BYTE(m[15])
382 :
383 : #define WASM_SIMD_LOAD_MEM(index) \
384 : index, WASM_SIMD_OP(kExprS128LoadMem), ZERO_ALIGNMENT, ZERO_OFFSET
385 : #define WASM_SIMD_STORE_MEM(index, val) \
386 : index, val, WASM_SIMD_OP(kExprS128StoreMem), ZERO_ALIGNMENT, ZERO_OFFSET
387 :
388 : // Skip FP tests involving extremely large or extremely small values, which
389 : // may fail due to non-IEEE-754 SIMD arithmetic on some platforms.
390 0 : bool SkipFPValue(float x) {
391 : float abs_x = std::fabs(x);
392 : const float kSmallFloatThreshold = 1.0e-32f;
393 : const float kLargeFloatThreshold = 1.0e32f;
394 2691120 : return abs_x != 0.0f && // 0 or -0 are fine.
395 2592396 : (abs_x < kSmallFloatThreshold || abs_x > kLargeFloatThreshold);
396 : }
397 :
398 : // Skip tests where the expected value is a NaN, since our wasm test code
399 : // doesn't handle NaNs. Also skip extreme values.
400 2444604 : bool SkipFPExpectedValue(float x) { return std::isnan(x) || SkipFPValue(x); }
401 :
402 25923 : WASM_SIMD_TEST(F32x4Splat) {
403 : WasmRunner<int32_t, float> r(execution_tier, lower_simd);
404 : byte lane_val = 0;
405 : byte simd = r.AllocateLocal(kWasmS128);
406 12 : BUILD(r,
407 : WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
408 : WASM_SIMD_CHECK_SPLAT_F32x4(simd, lane_val), WASM_RETURN1(WASM_ONE));
409 :
410 1392 : FOR_FLOAT32_INPUTS(i) {
411 1380 : if (SkipFPExpectedValue(i)) continue;
412 1140 : CHECK_EQ(1, r.Call(i));
413 12 : }
414 12 : }
415 :
416 25923 : WASM_SIMD_TEST(F32x4ReplaceLane) {
417 : WasmRunner<int32_t, float, float> r(execution_tier, lower_simd);
418 : byte old_val = 0;
419 : byte new_val = 1;
420 : byte simd = r.AllocateLocal(kWasmS128);
421 12 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(old_val))),
422 : WASM_SET_LOCAL(simd,
423 : WASM_SIMD_F32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
424 : WASM_GET_LOCAL(new_val))),
425 : WASM_SIMD_CHECK_F32x4(simd, new_val, old_val, old_val, old_val),
426 : WASM_SET_LOCAL(simd,
427 : WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
428 : WASM_GET_LOCAL(new_val))),
429 : WASM_SIMD_CHECK_F32x4(simd, new_val, new_val, old_val, old_val),
430 : WASM_SET_LOCAL(simd,
431 : WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
432 : WASM_GET_LOCAL(new_val))),
433 : WASM_SIMD_CHECK_F32x4(simd, new_val, new_val, new_val, old_val),
434 : WASM_SET_LOCAL(simd,
435 : WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
436 : WASM_GET_LOCAL(new_val))),
437 : WASM_SIMD_CHECK_SPLAT_F32x4(simd, new_val), WASM_RETURN1(WASM_ONE));
438 :
439 12 : CHECK_EQ(1, r.Call(3.14159f, -1.5f));
440 12 : }
441 :
442 : // Runs tests of compiled code, using the interpreter as a reference.
443 : #define WASM_SIMD_COMPILED_TEST(name) \
444 : void RunWasm_##name##_Impl(LowerSimd lower_simd, \
445 : ExecutionTier execution_tier); \
446 : TEST(RunWasm_##name##_turbofan) { \
447 : EXPERIMENTAL_FLAG_SCOPE(simd); \
448 : RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kOptimized); \
449 : } \
450 : TEST(RunWasm_##name##_simd_lowered) { \
451 : EXPERIMENTAL_FLAG_SCOPE(simd); \
452 : RunWasm_##name##_Impl(kLowerSimd, ExecutionTier::kOptimized); \
453 : } \
454 : void RunWasm_##name##_Impl(LowerSimd lower_simd, ExecutionTier execution_tier)
455 :
456 : // The macro below disables tests lowering for certain nodes where the simd
457 : // lowering doesn't work correctly. Early return here if the CPU does not
458 : // support SIMD as the graph will be implicitly lowered in that case.
459 : #define WASM_SIMD_TEST_TURBOFAN(name) \
460 : void RunWasm_##name##_Impl(LowerSimd lower_simd, \
461 : ExecutionTier execution_tier); \
462 : TEST(RunWasm_##name##_turbofan) { \
463 : if (!CpuFeatures::SupportsWasmSimd128()) return; \
464 : EXPERIMENTAL_FLAG_SCOPE(simd); \
465 : RunWasm_##name##_Impl(kNoLowerSimd, ExecutionTier::kOptimized); \
466 : } \
467 : void RunWasm_##name##_Impl(LowerSimd lower_simd, ExecutionTier execution_tier)
468 :
469 : // Tests both signed and unsigned conversion.
470 : // v8:8425 tracks this test being enabled in the interpreter.
471 25907 : WASM_SIMD_COMPILED_TEST(F32x4ConvertI32x4) {
472 : WasmRunner<int32_t, int32_t, float, float> r(execution_tier, lower_simd);
473 : byte a = 0;
474 : byte expected_signed = 1;
475 : byte expected_unsigned = 2;
476 : byte simd0 = r.AllocateLocal(kWasmS128);
477 : byte simd1 = r.AllocateLocal(kWasmS128);
478 : byte simd2 = r.AllocateLocal(kWasmS128);
479 8 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
480 : WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprF32x4SConvertI32x4,
481 : WASM_GET_LOCAL(simd0))),
482 : WASM_SIMD_CHECK_SPLAT_F32x4(simd1, expected_signed),
483 : WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprF32x4UConvertI32x4,
484 : WASM_GET_LOCAL(simd0))),
485 : WASM_SIMD_CHECK_SPLAT_F32x4(simd2, expected_unsigned),
486 : WASM_RETURN1(WASM_ONE));
487 :
488 472 : FOR_INT32_INPUTS(i) {
489 464 : CHECK_EQ(1, r.Call(i, static_cast<float>(i),
490 : static_cast<float>(static_cast<uint32_t>(i))));
491 8 : }
492 8 : }
493 :
494 48 : void RunF32x4UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
495 : WasmOpcode simd_op, FloatUnOp expected_op,
496 : float error = 0.0f) {
497 : WasmRunner<int32_t, float, float, float> r(execution_tier, lower_simd);
498 : byte a = 0;
499 : byte low = 1;
500 : byte high = 2;
501 : byte simd = r.AllocateLocal(kWasmS128);
502 48 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
503 : WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
504 : WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE(simd, low, high),
505 : WASM_RETURN1(WASM_ONE));
506 :
507 5568 : FOR_FLOAT32_INPUTS(i) {
508 5520 : if (SkipFPValue(i)) continue;
509 4656 : float expected = expected_op(i);
510 4656 : if (SkipFPExpectedValue(expected)) continue;
511 3876 : float abs_error = std::abs(expected) * error;
512 3876 : CHECK_EQ(1, r.Call(i, expected - abs_error, expected + abs_error));
513 48 : }
514 48 : }
515 :
516 25899 : WASM_SIMD_TEST(F32x4Abs) {
517 12 : RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4Abs, std::abs);
518 0 : }
519 25899 : WASM_SIMD_TEST(F32x4Neg) {
520 12 : RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4Neg, Negate);
521 0 : }
522 :
523 : static const float kApproxError = 0.01f;
524 :
525 25899 : WASM_SIMD_TEST(F32x4RecipApprox) {
526 : RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4RecipApprox,
527 12 : base::Recip, kApproxError);
528 0 : }
529 :
530 25899 : WASM_SIMD_TEST(F32x4RecipSqrtApprox) {
531 : RunF32x4UnOpTest(execution_tier, lower_simd, kExprF32x4RecipSqrtApprox,
532 12 : base::RecipSqrt, kApproxError);
533 0 : }
534 :
535 60 : void RunF32x4BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
536 : WasmOpcode simd_op, FloatBinOp expected_op) {
537 : WasmRunner<int32_t, float, float, float> r(execution_tier, lower_simd);
538 : byte a = 0;
539 : byte b = 1;
540 : byte expected = 2;
541 : byte simd0 = r.AllocateLocal(kWasmS128);
542 : byte simd1 = r.AllocateLocal(kWasmS128);
543 60 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
544 : WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
545 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
546 : WASM_GET_LOCAL(simd1))),
547 : WASM_SIMD_CHECK_SPLAT_F32x4(simd1, expected), WASM_RETURN1(WASM_ONE));
548 :
549 6960 : FOR_FLOAT32_INPUTS(i) {
550 6900 : if (SkipFPValue(i)) continue;
551 1338600 : FOR_FLOAT32_INPUTS(j) {
552 669300 : if (SkipFPValue(j)) continue;
553 564540 : float expected = expected_op(i, j);
554 564540 : if (SkipFPExpectedValue(expected)) continue;
555 529872 : CHECK_EQ(1, r.Call(i, j, expected));
556 : }
557 60 : }
558 60 : }
559 :
560 25899 : WASM_SIMD_TEST(F32x4Add) {
561 12 : RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Add, Add);
562 0 : }
563 25899 : WASM_SIMD_TEST(F32x4Sub) {
564 12 : RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Sub, Sub);
565 0 : }
566 25899 : WASM_SIMD_TEST(F32x4Mul) {
567 12 : RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Mul, Mul);
568 0 : }
569 25899 : WASM_SIMD_TEST(F32x4_Min) {
570 12 : RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Min, JSMin);
571 0 : }
572 25899 : WASM_SIMD_TEST(F32x4_Max) {
573 12 : RunF32x4BinOpTest(execution_tier, lower_simd, kExprF32x4Max, JSMax);
574 0 : }
575 :
576 72 : void RunF32x4CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
577 : WasmOpcode simd_op, FloatCompareOp expected_op) {
578 : WasmRunner<int32_t, float, float, int32_t> r(execution_tier, lower_simd);
579 : byte a = 0;
580 : byte b = 1;
581 : byte expected = 2;
582 : byte simd0 = r.AllocateLocal(kWasmS128);
583 : byte simd1 = r.AllocateLocal(kWasmS128);
584 72 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
585 : WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
586 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
587 : WASM_GET_LOCAL(simd1))),
588 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
589 :
590 8352 : FOR_FLOAT32_INPUTS(i) {
591 8280 : if (SkipFPValue(i)) continue;
592 1606320 : FOR_FLOAT32_INPUTS(j) {
593 803160 : if (SkipFPValue(j)) continue;
594 677448 : float diff = i - j;
595 677448 : if (SkipFPExpectedValue(diff)) continue;
596 649800 : CHECK_EQ(1, r.Call(i, j, expected_op(i, j)));
597 : }
598 72 : }
599 72 : }
600 :
601 25899 : WASM_SIMD_TEST(F32x4Eq) {
602 12 : RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Eq, Equal);
603 0 : }
604 :
605 25899 : WASM_SIMD_TEST(F32x4Ne) {
606 12 : RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Ne, NotEqual);
607 0 : }
608 :
609 25899 : WASM_SIMD_TEST(F32x4Gt) {
610 12 : RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Gt, Greater);
611 0 : }
612 :
613 25899 : WASM_SIMD_TEST(F32x4Ge) {
614 12 : RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Ge, GreaterEqual);
615 0 : }
616 :
617 25899 : WASM_SIMD_TEST(F32x4Lt) {
618 12 : RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Lt, Less);
619 0 : }
620 :
621 25899 : WASM_SIMD_TEST(F32x4Le) {
622 12 : RunF32x4CompareOpTest(execution_tier, lower_simd, kExprF32x4Le, LessEqual);
623 0 : }
624 :
625 25923 : WASM_SIMD_TEST(I32x4Splat) {
626 : // Store SIMD value in a local variable, use extract lane to check lane values
627 : // This test is not a test for ExtractLane as Splat does not create
628 : // interesting SIMD values.
629 : //
630 : // SetLocal(1, I32x4Splat(Local(0)));
631 : // For each lane index
632 : // if(Local(0) != I32x4ExtractLane(Local(1), index)
633 : // return 0
634 : //
635 : // return 1
636 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
637 : byte lane_val = 0;
638 : byte simd = r.AllocateLocal(kWasmS128);
639 12 : BUILD(r,
640 : WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
641 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), WASM_ONE);
642 :
643 12 : FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(i)); }
644 12 : }
645 :
646 25923 : WASM_SIMD_TEST(I32x4ReplaceLane) {
647 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
648 : byte old_val = 0;
649 : byte new_val = 1;
650 : byte simd = r.AllocateLocal(kWasmS128);
651 12 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
652 : WASM_SET_LOCAL(simd,
653 : WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
654 : WASM_GET_LOCAL(new_val))),
655 : WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, old_val),
656 : WASM_SET_LOCAL(simd,
657 : WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
658 : WASM_GET_LOCAL(new_val))),
659 : WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val, old_val),
660 : WASM_SET_LOCAL(simd,
661 : WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
662 : WASM_GET_LOCAL(new_val))),
663 : WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val),
664 : WASM_SET_LOCAL(simd,
665 : WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
666 : WASM_GET_LOCAL(new_val))),
667 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE);
668 :
669 12 : CHECK_EQ(1, r.Call(1, 2));
670 12 : }
671 :
672 25923 : WASM_SIMD_TEST(I16x8Splat) {
673 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
674 : byte lane_val = 0;
675 : byte simd = r.AllocateLocal(kWasmS128);
676 12 : BUILD(r,
677 : WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(lane_val))),
678 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, lane_val), WASM_ONE);
679 :
680 12 : FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(i)); }
681 12 : }
682 :
683 25923 : WASM_SIMD_TEST(I16x8ReplaceLane) {
684 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
685 : byte old_val = 0;
686 : byte new_val = 1;
687 : byte simd = r.AllocateLocal(kWasmS128);
688 12 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(old_val))),
689 : WASM_SET_LOCAL(simd,
690 : WASM_SIMD_I16x8_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
691 : WASM_GET_LOCAL(new_val))),
692 : WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, old_val, old_val, old_val,
693 : old_val, old_val, old_val, old_val),
694 : WASM_SET_LOCAL(simd,
695 : WASM_SIMD_I16x8_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
696 : WASM_GET_LOCAL(new_val))),
697 : WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, old_val, old_val,
698 : old_val, old_val, old_val, old_val),
699 : WASM_SET_LOCAL(simd,
700 : WASM_SIMD_I16x8_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
701 : WASM_GET_LOCAL(new_val))),
702 : WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, old_val,
703 : old_val, old_val, old_val, old_val),
704 : WASM_SET_LOCAL(simd,
705 : WASM_SIMD_I16x8_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
706 : WASM_GET_LOCAL(new_val))),
707 : WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
708 : old_val, old_val, old_val, old_val),
709 : WASM_SET_LOCAL(simd,
710 : WASM_SIMD_I16x8_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
711 : WASM_GET_LOCAL(new_val))),
712 : WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
713 : new_val, old_val, old_val, old_val),
714 : WASM_SET_LOCAL(simd,
715 : WASM_SIMD_I16x8_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
716 : WASM_GET_LOCAL(new_val))),
717 : WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
718 : new_val, new_val, old_val, old_val),
719 : WASM_SET_LOCAL(simd,
720 : WASM_SIMD_I16x8_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
721 : WASM_GET_LOCAL(new_val))),
722 : WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val, new_val,
723 : new_val, new_val, new_val, old_val),
724 : WASM_SET_LOCAL(simd,
725 : WASM_SIMD_I16x8_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
726 : WASM_GET_LOCAL(new_val))),
727 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, new_val), WASM_ONE);
728 :
729 12 : CHECK_EQ(1, r.Call(1, 2));
730 12 : }
731 :
732 25923 : WASM_SIMD_TEST(I8x16Splat) {
733 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
734 : byte lane_val = 0;
735 : byte simd = r.AllocateLocal(kWasmS128);
736 12 : BUILD(r,
737 : WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(lane_val))),
738 : WASM_SIMD_CHECK_SPLAT8(I8x16, simd, I32, lane_val), WASM_ONE);
739 :
740 12 : FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(i)); }
741 12 : }
742 :
743 25923 : WASM_SIMD_TEST(I8x16ReplaceLane) {
744 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
745 : byte old_val = 0;
746 : byte new_val = 1;
747 : byte simd = r.AllocateLocal(kWasmS128);
748 12 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(old_val))),
749 : WASM_SET_LOCAL(simd,
750 : WASM_SIMD_I8x16_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
751 : WASM_GET_LOCAL(new_val))),
752 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, old_val, old_val, old_val,
753 : old_val, old_val, old_val, old_val, old_val, old_val,
754 : old_val, old_val, old_val, old_val, old_val, old_val),
755 : WASM_SET_LOCAL(simd,
756 : WASM_SIMD_I8x16_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
757 : WASM_GET_LOCAL(new_val))),
758 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, old_val, old_val,
759 : old_val, old_val, old_val, old_val, old_val, old_val,
760 : old_val, old_val, old_val, old_val, old_val, old_val),
761 : WASM_SET_LOCAL(simd,
762 : WASM_SIMD_I8x16_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
763 : WASM_GET_LOCAL(new_val))),
764 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, old_val,
765 : old_val, old_val, old_val, old_val, old_val, old_val,
766 : old_val, old_val, old_val, old_val, old_val, old_val),
767 : WASM_SET_LOCAL(simd,
768 : WASM_SIMD_I8x16_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
769 : WASM_GET_LOCAL(new_val))),
770 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
771 : old_val, old_val, old_val, old_val, old_val, old_val,
772 : old_val, old_val, old_val, old_val, old_val, old_val),
773 : WASM_SET_LOCAL(simd,
774 : WASM_SIMD_I8x16_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
775 : WASM_GET_LOCAL(new_val))),
776 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
777 : new_val, old_val, old_val, old_val, old_val, old_val,
778 : old_val, old_val, old_val, old_val, old_val, old_val),
779 : WASM_SET_LOCAL(simd,
780 : WASM_SIMD_I8x16_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
781 : WASM_GET_LOCAL(new_val))),
782 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
783 : new_val, new_val, old_val, old_val, old_val, old_val,
784 : old_val, old_val, old_val, old_val, old_val, old_val),
785 : WASM_SET_LOCAL(simd,
786 : WASM_SIMD_I8x16_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
787 : WASM_GET_LOCAL(new_val))),
788 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
789 : new_val, new_val, new_val, old_val, old_val, old_val,
790 : old_val, old_val, old_val, old_val, old_val, old_val),
791 : WASM_SET_LOCAL(simd,
792 : WASM_SIMD_I8x16_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
793 : WASM_GET_LOCAL(new_val))),
794 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
795 : new_val, new_val, new_val, new_val, old_val, old_val,
796 : old_val, old_val, old_val, old_val, old_val, old_val),
797 : WASM_SET_LOCAL(simd,
798 : WASM_SIMD_I8x16_REPLACE_LANE(8, WASM_GET_LOCAL(simd),
799 : WASM_GET_LOCAL(new_val))),
800 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
801 : new_val, new_val, new_val, new_val, new_val, old_val,
802 : old_val, old_val, old_val, old_val, old_val, old_val),
803 : WASM_SET_LOCAL(simd,
804 : WASM_SIMD_I8x16_REPLACE_LANE(9, WASM_GET_LOCAL(simd),
805 : WASM_GET_LOCAL(new_val))),
806 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
807 : new_val, new_val, new_val, new_val, new_val, new_val,
808 : old_val, old_val, old_val, old_val, old_val, old_val),
809 : WASM_SET_LOCAL(simd,
810 : WASM_SIMD_I8x16_REPLACE_LANE(10, WASM_GET_LOCAL(simd),
811 : WASM_GET_LOCAL(new_val))),
812 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
813 : new_val, new_val, new_val, new_val, new_val, new_val,
814 : new_val, old_val, old_val, old_val, old_val, old_val),
815 : WASM_SET_LOCAL(simd,
816 : WASM_SIMD_I8x16_REPLACE_LANE(11, WASM_GET_LOCAL(simd),
817 : WASM_GET_LOCAL(new_val))),
818 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
819 : new_val, new_val, new_val, new_val, new_val, new_val,
820 : new_val, new_val, old_val, old_val, old_val, old_val),
821 : WASM_SET_LOCAL(simd,
822 : WASM_SIMD_I8x16_REPLACE_LANE(12, WASM_GET_LOCAL(simd),
823 : WASM_GET_LOCAL(new_val))),
824 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
825 : new_val, new_val, new_val, new_val, new_val, new_val,
826 : new_val, new_val, new_val, old_val, old_val, old_val),
827 : WASM_SET_LOCAL(simd,
828 : WASM_SIMD_I8x16_REPLACE_LANE(13, WASM_GET_LOCAL(simd),
829 : WASM_GET_LOCAL(new_val))),
830 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
831 : new_val, new_val, new_val, new_val, new_val, new_val,
832 : new_val, new_val, new_val, new_val, old_val, old_val),
833 : WASM_SET_LOCAL(simd,
834 : WASM_SIMD_I8x16_REPLACE_LANE(14, WASM_GET_LOCAL(simd),
835 : WASM_GET_LOCAL(new_val))),
836 : WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val, new_val,
837 : new_val, new_val, new_val, new_val, new_val, new_val,
838 : new_val, new_val, new_val, new_val, new_val, old_val),
839 : WASM_SET_LOCAL(simd,
840 : WASM_SIMD_I8x16_REPLACE_LANE(15, WASM_GET_LOCAL(simd),
841 : WASM_GET_LOCAL(new_val))),
842 : WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, new_val), WASM_ONE);
843 :
844 12 : CHECK_EQ(1, r.Call(1, 2));
845 12 : }
846 :
847 0 : int32_t ConvertToInt(double val, bool unsigned_integer) {
848 2328 : if (std::isnan(val)) return 0;
849 0 : if (unsigned_integer) {
850 1140 : if (val < 0) return 0;
851 504 : if (val > kMaxUInt32) return kMaxUInt32;
852 336 : return static_cast<uint32_t>(val);
853 : } else {
854 1140 : if (val < kMinInt) return kMinInt;
855 984 : if (val > kMaxInt) return kMaxInt;
856 804 : return static_cast<int>(val);
857 : }
858 : }
859 :
860 : // Tests both signed and unsigned conversion.
861 25923 : WASM_SIMD_TEST(I32x4ConvertF32x4) {
862 : WasmRunner<int32_t, float, int32_t, int32_t> r(execution_tier, lower_simd);
863 : byte a = 0;
864 : byte expected_signed = 1;
865 : byte expected_unsigned = 2;
866 : byte simd0 = r.AllocateLocal(kWasmS128);
867 : byte simd1 = r.AllocateLocal(kWasmS128);
868 : byte simd2 = r.AllocateLocal(kWasmS128);
869 12 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
870 : WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprI32x4SConvertF32x4,
871 : WASM_GET_LOCAL(simd0))),
872 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected_signed),
873 : WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprI32x4UConvertF32x4,
874 : WASM_GET_LOCAL(simd0))),
875 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), WASM_ONE);
876 :
877 1392 : FOR_FLOAT32_INPUTS(i) {
878 1380 : if (SkipFPValue(i)) continue;
879 1164 : int32_t signed_value = ConvertToInt(i, false);
880 : int32_t unsigned_value = ConvertToInt(i, true);
881 1164 : CHECK_EQ(1, r.Call(i, signed_value, unsigned_value));
882 12 : }
883 12 : }
884 :
885 : // Tests both signed and unsigned conversion from I16x8 (unpacking).
886 25923 : WASM_SIMD_TEST(I32x4ConvertI16x8) {
887 : WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t> r(execution_tier,
888 : lower_simd);
889 : byte a = 0;
890 : byte unpacked_signed = 1;
891 : byte unpacked_unsigned = 2;
892 : byte zero_value = 3;
893 : byte simd0 = r.AllocateLocal(kWasmS128);
894 : byte simd1 = r.AllocateLocal(kWasmS128);
895 : byte simd2 = r.AllocateLocal(kWasmS128);
896 : byte simd3 = r.AllocateLocal(kWasmS128);
897 : byte simd4 = r.AllocateLocal(kWasmS128);
898 12 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
899 : WASM_SET_LOCAL(
900 : simd0, WASM_SIMD_I16x8_REPLACE_LANE(0, WASM_GET_LOCAL(simd0),
901 : WASM_GET_LOCAL(zero_value))),
902 : WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprI32x4SConvertI16x8High,
903 : WASM_GET_LOCAL(simd0))),
904 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, unpacked_signed),
905 : WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprI32x4UConvertI16x8High,
906 : WASM_GET_LOCAL(simd0))),
907 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, unpacked_unsigned),
908 : WASM_SET_LOCAL(simd3, WASM_SIMD_UNOP(kExprI32x4SConvertI16x8Low,
909 : WASM_GET_LOCAL(simd0))),
910 : WASM_SIMD_CHECK4(I32x4, simd3, I32, zero_value, unpacked_signed,
911 : unpacked_signed, unpacked_signed),
912 : WASM_SET_LOCAL(simd4, WASM_SIMD_UNOP(kExprI32x4UConvertI16x8Low,
913 : WASM_GET_LOCAL(simd0))),
914 : WASM_SIMD_CHECK4(I32x4, simd4, I32, zero_value, unpacked_unsigned,
915 : unpacked_unsigned, unpacked_unsigned),
916 : WASM_ONE);
917 :
918 120 : FOR_INT16_INPUTS(i) {
919 108 : int32_t unpacked_signed = static_cast<int32_t>(Widen<int16_t>(i));
920 108 : int32_t unpacked_unsigned = static_cast<int32_t>(UnsignedWiden<int16_t>(i));
921 108 : CHECK_EQ(1, r.Call(i, unpacked_signed, unpacked_unsigned, 0));
922 12 : }
923 12 : }
924 :
925 24 : void RunI32x4UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
926 : WasmOpcode simd_op, Int32UnOp expected_op) {
927 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
928 : byte a = 0;
929 : byte expected = 1;
930 : byte simd = r.AllocateLocal(kWasmS128);
931 24 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
932 : WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
933 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
934 :
935 24 : FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(i, expected_op(i))); }
936 24 : }
937 :
938 25899 : WASM_SIMD_TEST(I32x4Neg) {
939 : RunI32x4UnOpTest(execution_tier, lower_simd, kExprI32x4Neg,
940 12 : base::NegateWithWraparound);
941 0 : }
942 :
943 25899 : WASM_SIMD_TEST(S128Not) {
944 12 : RunI32x4UnOpTest(execution_tier, lower_simd, kExprS128Not, Not);
945 0 : }
946 :
947 120 : void RunI32x4BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
948 : WasmOpcode simd_op, Int32BinOp expected_op) {
949 : WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
950 : byte a = 0;
951 : byte b = 1;
952 : byte expected = 2;
953 : byte simd0 = r.AllocateLocal(kWasmS128);
954 : byte simd1 = r.AllocateLocal(kWasmS128);
955 120 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
956 : WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
957 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
958 : WASM_GET_LOCAL(simd1))),
959 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
960 :
961 7080 : FOR_INT32_INPUTS(i) {
962 6960 : FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); }
963 120 : }
964 120 : }
965 :
966 25899 : WASM_SIMD_TEST(I32x4Add) {
967 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4Add,
968 12 : base::AddWithWraparound);
969 0 : }
970 :
971 25899 : WASM_SIMD_TEST(I32x4Sub) {
972 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4Sub,
973 12 : base::SubWithWraparound);
974 0 : }
975 :
976 25899 : WASM_SIMD_TEST(I32x4Mul) {
977 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4Mul,
978 12 : base::MulWithWraparound);
979 0 : }
980 :
981 25899 : WASM_SIMD_TEST(I32x4MinS) {
982 12 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MinS, Minimum);
983 0 : }
984 :
985 25899 : WASM_SIMD_TEST(I32x4MaxS) {
986 12 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MaxS, Maximum);
987 0 : }
988 :
989 25899 : WASM_SIMD_TEST(I32x4MinU) {
990 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MinU,
991 12 : UnsignedMinimum);
992 0 : }
993 25899 : WASM_SIMD_TEST(I32x4MaxU) {
994 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprI32x4MaxU,
995 :
996 12 : UnsignedMaximum);
997 0 : }
998 :
999 25899 : WASM_SIMD_TEST(S128And) {
1000 12 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprS128And, And);
1001 0 : }
1002 :
1003 25899 : WASM_SIMD_TEST(S128Or) {
1004 12 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprS128Or, Or);
1005 0 : }
1006 :
1007 25899 : WASM_SIMD_TEST(S128Xor) {
1008 12 : RunI32x4BinOpTest(execution_tier, lower_simd, kExprS128Xor, Xor);
1009 0 : }
1010 :
1011 120 : void RunI32x4CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1012 : WasmOpcode simd_op, Int32CompareOp expected_op) {
1013 : WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1014 : byte a = 0;
1015 : byte b = 1;
1016 : byte expected = 2;
1017 : byte simd0 = r.AllocateLocal(kWasmS128);
1018 : byte simd1 = r.AllocateLocal(kWasmS128);
1019 120 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
1020 : WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
1021 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
1022 : WASM_GET_LOCAL(simd1))),
1023 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
1024 :
1025 7080 : FOR_INT32_INPUTS(i) {
1026 6960 : FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); }
1027 120 : }
1028 120 : }
1029 :
1030 25899 : WASM_SIMD_TEST(I32x4Eq) {
1031 12 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4Eq, Equal);
1032 0 : }
1033 :
1034 25899 : WASM_SIMD_TEST(I32x4Ne) {
1035 12 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4Ne, NotEqual);
1036 0 : }
1037 :
1038 25899 : WASM_SIMD_TEST(I32x4LtS) {
1039 12 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LtS, Less);
1040 0 : }
1041 :
1042 25899 : WASM_SIMD_TEST(I32x4LeS) {
1043 12 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LeS, LessEqual);
1044 0 : }
1045 :
1046 25899 : WASM_SIMD_TEST(I32x4GtS) {
1047 12 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GtS, Greater);
1048 0 : }
1049 :
1050 25899 : WASM_SIMD_TEST(I32x4GeS) {
1051 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GeS,
1052 12 : GreaterEqual);
1053 0 : }
1054 :
1055 25899 : WASM_SIMD_TEST(I32x4LtU) {
1056 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LtU,
1057 12 : UnsignedLess);
1058 0 : }
1059 :
1060 25899 : WASM_SIMD_TEST(I32x4LeU) {
1061 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4LeU,
1062 12 : UnsignedLessEqual);
1063 0 : }
1064 :
1065 25899 : WASM_SIMD_TEST(I32x4GtU) {
1066 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GtU,
1067 12 : UnsignedGreater);
1068 0 : }
1069 :
1070 25899 : WASM_SIMD_TEST(I32x4GeU) {
1071 : RunI32x4CompareOpTest(execution_tier, lower_simd, kExprI32x4GeU,
1072 12 : UnsignedGreaterEqual);
1073 0 : }
1074 :
1075 36 : void RunI32x4ShiftOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1076 : WasmOpcode simd_op, Int32ShiftOp expected_op) {
1077 1152 : for (int shift = 1; shift < 32; ++shift) {
1078 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1079 : byte a = 0;
1080 : byte expected = 1;
1081 : byte simd = r.AllocateLocal(kWasmS128);
1082 1116 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
1083 : WASM_SET_LOCAL(
1084 : simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
1085 : WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected), WASM_ONE);
1086 :
1087 1116 : FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(i, expected_op(i, shift))); }
1088 1116 : }
1089 36 : }
1090 :
1091 25899 : WASM_SIMD_TEST(I32x4Shl) {
1092 : RunI32x4ShiftOpTest(execution_tier, lower_simd, kExprI32x4Shl,
1093 12 : LogicalShiftLeft);
1094 0 : }
1095 :
1096 25899 : WASM_SIMD_TEST(I32x4ShrS) {
1097 : RunI32x4ShiftOpTest(execution_tier, lower_simd, kExprI32x4ShrS,
1098 12 : ArithmeticShiftRight);
1099 0 : }
1100 :
1101 25899 : WASM_SIMD_TEST(I32x4ShrU) {
1102 : RunI32x4ShiftOpTest(execution_tier, lower_simd, kExprI32x4ShrU,
1103 12 : LogicalShiftRight);
1104 0 : }
1105 :
1106 : // Tests both signed and unsigned conversion from I8x16 (unpacking).
1107 25923 : WASM_SIMD_TEST(I16x8ConvertI8x16) {
1108 : WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t> r(execution_tier,
1109 : lower_simd);
1110 : byte a = 0;
1111 : byte unpacked_signed = 1;
1112 : byte unpacked_unsigned = 2;
1113 : byte zero_value = 3;
1114 : byte simd0 = r.AllocateLocal(kWasmS128);
1115 : byte simd1 = r.AllocateLocal(kWasmS128);
1116 : byte simd2 = r.AllocateLocal(kWasmS128);
1117 : byte simd3 = r.AllocateLocal(kWasmS128);
1118 : byte simd4 = r.AllocateLocal(kWasmS128);
1119 12 : BUILD(
1120 : r, WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
1121 : WASM_SET_LOCAL(simd0,
1122 : WASM_SIMD_I8x16_REPLACE_LANE(0, WASM_GET_LOCAL(simd0),
1123 : WASM_GET_LOCAL(zero_value))),
1124 : WASM_SET_LOCAL(simd1, WASM_SIMD_UNOP(kExprI16x8SConvertI8x16High,
1125 : WASM_GET_LOCAL(simd0))),
1126 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, unpacked_signed),
1127 : WASM_SET_LOCAL(simd2, WASM_SIMD_UNOP(kExprI16x8UConvertI8x16High,
1128 : WASM_GET_LOCAL(simd0))),
1129 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd2, I32, unpacked_unsigned),
1130 : WASM_SET_LOCAL(simd3, WASM_SIMD_UNOP(kExprI16x8SConvertI8x16Low,
1131 : WASM_GET_LOCAL(simd0))),
1132 : WASM_SIMD_CHECK8(I16x8, simd3, I32, zero_value, unpacked_signed,
1133 : unpacked_signed, unpacked_signed, unpacked_signed,
1134 : unpacked_signed, unpacked_signed, unpacked_signed),
1135 : WASM_SET_LOCAL(simd4, WASM_SIMD_UNOP(kExprI16x8UConvertI8x16Low,
1136 : WASM_GET_LOCAL(simd0))),
1137 : WASM_SIMD_CHECK8(I16x8, simd4, I32, zero_value, unpacked_unsigned,
1138 : unpacked_unsigned, unpacked_unsigned, unpacked_unsigned,
1139 : unpacked_unsigned, unpacked_unsigned, unpacked_unsigned),
1140 : WASM_ONE);
1141 :
1142 120 : FOR_INT8_INPUTS(i) {
1143 108 : int32_t unpacked_signed = static_cast<int32_t>(Widen<int8_t>(i));
1144 108 : int32_t unpacked_unsigned = static_cast<int32_t>(UnsignedWiden<int8_t>(i));
1145 108 : CHECK_EQ(1, r.Call(i, unpacked_signed, unpacked_unsigned, 0));
1146 12 : }
1147 12 : }
1148 :
1149 12 : void RunI16x8UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1150 : WasmOpcode simd_op, Int16UnOp expected_op) {
1151 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1152 : byte a = 0;
1153 : byte expected = 1;
1154 : byte simd = r.AllocateLocal(kWasmS128);
1155 12 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
1156 : WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
1157 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE);
1158 :
1159 12 : FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(i, expected_op(i))); }
1160 12 : }
1161 :
1162 25899 : WASM_SIMD_TEST(I16x8Neg) {
1163 : RunI16x8UnOpTest(execution_tier, lower_simd, kExprI16x8Neg,
1164 12 : base::NegateWithWraparound);
1165 0 : }
1166 :
1167 : // Tests both signed and unsigned conversion from I32x4 (packing).
1168 25923 : WASM_SIMD_TEST(I16x8ConvertI32x4) {
1169 : WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t> r(
1170 : execution_tier, lower_simd);
1171 : byte a = 0;
1172 : byte b = 1;
1173 : // indices for packed signed params
1174 : byte ps_a = 2;
1175 : byte ps_b = 3;
1176 : // indices for packed unsigned params
1177 : byte pu_a = 4;
1178 : byte pu_b = 5;
1179 : byte simd0 = r.AllocateLocal(kWasmS128);
1180 : byte simd1 = r.AllocateLocal(kWasmS128);
1181 : byte simd2 = r.AllocateLocal(kWasmS128);
1182 12 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
1183 : WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
1184 : WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI16x8SConvertI32x4,
1185 : WASM_GET_LOCAL(simd0),
1186 : WASM_GET_LOCAL(simd1))),
1187 : WASM_SIMD_CHECK8(I16x8, simd2, I32, ps_a, ps_a, ps_a, ps_a, ps_b, ps_b,
1188 : ps_b, ps_b),
1189 : WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI16x8UConvertI32x4,
1190 : WASM_GET_LOCAL(simd0),
1191 : WASM_GET_LOCAL(simd1))),
1192 : WASM_SIMD_CHECK8(I16x8, simd2, I32, pu_a, pu_a, pu_a, pu_a, pu_b, pu_b,
1193 : pu_b, pu_b),
1194 : WASM_ONE);
1195 :
1196 708 : FOR_INT32_INPUTS(i) {
1197 41064 : FOR_INT32_INPUTS(j) {
1198 : // packed signed values
1199 80736 : int32_t ps_a = Narrow<int16_t>(i);
1200 80736 : int32_t ps_b = Narrow<int16_t>(j);
1201 : // packed unsigned values
1202 40368 : int32_t pu_a = UnsignedNarrow<int16_t>(i);
1203 40368 : int32_t pu_b = UnsignedNarrow<int16_t>(j);
1204 : // Sign-extend here, since ExtractLane sign extends.
1205 40368 : if (pu_a & 0x8000) pu_a |= 0xFFFF0000;
1206 40368 : if (pu_b & 0x8000) pu_b |= 0xFFFF0000;
1207 40368 : CHECK_EQ(1, r.Call(i, j, ps_a, ps_b, pu_a, pu_b));
1208 : }
1209 12 : }
1210 12 : }
1211 :
1212 132 : void RunI16x8BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1213 : WasmOpcode simd_op, Int16BinOp expected_op) {
1214 : WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1215 : byte a = 0;
1216 : byte b = 1;
1217 : byte expected = 2;
1218 : byte simd0 = r.AllocateLocal(kWasmS128);
1219 : byte simd1 = r.AllocateLocal(kWasmS128);
1220 132 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
1221 : WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
1222 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
1223 : WASM_GET_LOCAL(simd1))),
1224 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, expected), WASM_ONE);
1225 :
1226 1320 : FOR_INT16_INPUTS(i) {
1227 1188 : FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); }
1228 132 : }
1229 132 : }
1230 :
1231 25899 : WASM_SIMD_TEST(I16x8Add) {
1232 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8Add,
1233 12 : base::AddWithWraparound);
1234 0 : }
1235 :
1236 25899 : WASM_SIMD_TEST(I16x8AddSaturateS) {
1237 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8AddSaturateS,
1238 12 : AddSaturate);
1239 0 : }
1240 :
1241 25899 : WASM_SIMD_TEST(I16x8Sub) {
1242 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8Sub,
1243 12 : base::SubWithWraparound);
1244 0 : }
1245 :
1246 25899 : WASM_SIMD_TEST(I16x8SubSaturateS) {
1247 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8SubSaturateS,
1248 12 : SubSaturate);
1249 0 : }
1250 :
1251 25899 : WASM_SIMD_TEST(I16x8Mul) {
1252 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8Mul,
1253 12 : base::MulWithWraparound);
1254 0 : }
1255 :
1256 25899 : WASM_SIMD_TEST(I16x8MinS) {
1257 12 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MinS, Minimum);
1258 0 : }
1259 :
1260 25899 : WASM_SIMD_TEST(I16x8MaxS) {
1261 12 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MaxS, Maximum);
1262 0 : }
1263 :
1264 25899 : WASM_SIMD_TEST(I16x8AddSaturateU) {
1265 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8AddSaturateU,
1266 12 : UnsignedAddSaturate);
1267 0 : }
1268 :
1269 25899 : WASM_SIMD_TEST(I16x8SubSaturateU) {
1270 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8SubSaturateU,
1271 12 : UnsignedSubSaturate);
1272 0 : }
1273 :
1274 25899 : WASM_SIMD_TEST(I16x8MinU) {
1275 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MinU,
1276 12 : UnsignedMinimum);
1277 0 : }
1278 :
1279 25899 : WASM_SIMD_TEST(I16x8MaxU) {
1280 : RunI16x8BinOpTest(execution_tier, lower_simd, kExprI16x8MaxU,
1281 12 : UnsignedMaximum);
1282 0 : }
1283 :
1284 120 : void RunI16x8CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1285 : WasmOpcode simd_op, Int16CompareOp expected_op) {
1286 : WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1287 : byte a = 0;
1288 : byte b = 1;
1289 : byte expected = 2;
1290 : byte simd0 = r.AllocateLocal(kWasmS128);
1291 : byte simd1 = r.AllocateLocal(kWasmS128);
1292 120 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
1293 : WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
1294 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
1295 : WASM_GET_LOCAL(simd1))),
1296 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, expected), WASM_ONE);
1297 :
1298 1200 : FOR_INT16_INPUTS(i) {
1299 1080 : FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); }
1300 120 : }
1301 120 : }
1302 :
1303 25899 : WASM_SIMD_TEST(I16x8Eq) {
1304 12 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8Eq, Equal);
1305 0 : }
1306 :
1307 25899 : WASM_SIMD_TEST(I16x8Ne) {
1308 12 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8Ne, NotEqual);
1309 0 : }
1310 :
1311 25899 : WASM_SIMD_TEST(I16x8LtS) {
1312 12 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LtS, Less);
1313 0 : }
1314 :
1315 25899 : WASM_SIMD_TEST(I16x8LeS) {
1316 12 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LeS, LessEqual);
1317 0 : }
1318 :
1319 25899 : WASM_SIMD_TEST(I16x8GtS) {
1320 12 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GtS, Greater);
1321 0 : }
1322 :
1323 25899 : WASM_SIMD_TEST(I16x8GeS) {
1324 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GeS,
1325 12 : GreaterEqual);
1326 0 : }
1327 :
1328 25899 : WASM_SIMD_TEST(I16x8GtU) {
1329 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GtU,
1330 12 : UnsignedGreater);
1331 0 : }
1332 :
1333 25899 : WASM_SIMD_TEST(I16x8GeU) {
1334 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8GeU,
1335 12 : UnsignedGreaterEqual);
1336 0 : }
1337 :
1338 25899 : WASM_SIMD_TEST(I16x8LtU) {
1339 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LtU,
1340 12 : UnsignedLess);
1341 0 : }
1342 :
1343 25899 : WASM_SIMD_TEST(I16x8LeU) {
1344 : RunI16x8CompareOpTest(execution_tier, lower_simd, kExprI16x8LeU,
1345 12 : UnsignedLessEqual);
1346 0 : }
1347 :
1348 36 : void RunI16x8ShiftOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1349 : WasmOpcode simd_op, Int16ShiftOp expected_op) {
1350 576 : for (int shift = 1; shift < 16; ++shift) {
1351 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1352 : byte a = 0;
1353 : byte expected = 1;
1354 : byte simd = r.AllocateLocal(kWasmS128);
1355 540 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
1356 : WASM_SET_LOCAL(
1357 : simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
1358 : WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected), WASM_ONE);
1359 :
1360 540 : FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(i, expected_op(i, shift))); }
1361 540 : }
1362 36 : }
1363 :
1364 25899 : WASM_SIMD_TEST(I16x8Shl) {
1365 : RunI16x8ShiftOpTest(execution_tier, lower_simd, kExprI16x8Shl,
1366 12 : LogicalShiftLeft);
1367 0 : }
1368 :
1369 25899 : WASM_SIMD_TEST(I16x8ShrS) {
1370 : RunI16x8ShiftOpTest(execution_tier, lower_simd, kExprI16x8ShrS,
1371 12 : ArithmeticShiftRight);
1372 0 : }
1373 :
1374 25899 : WASM_SIMD_TEST(I16x8ShrU) {
1375 : RunI16x8ShiftOpTest(execution_tier, lower_simd, kExprI16x8ShrU,
1376 12 : LogicalShiftRight);
1377 0 : }
1378 :
1379 12 : void RunI8x16UnOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1380 : WasmOpcode simd_op, Int8UnOp expected_op) {
1381 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1382 : byte a = 0;
1383 : byte expected = 1;
1384 : byte simd = r.AllocateLocal(kWasmS128);
1385 12 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
1386 : WASM_SET_LOCAL(simd, WASM_SIMD_UNOP(simd_op, WASM_GET_LOCAL(simd))),
1387 : WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE);
1388 :
1389 12 : FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(i, expected_op(i))); }
1390 12 : }
1391 :
1392 25899 : WASM_SIMD_TEST(I8x16Neg) {
1393 : RunI8x16UnOpTest(execution_tier, lower_simd, kExprI8x16Neg,
1394 12 : base::NegateWithWraparound);
1395 0 : }
1396 :
1397 : // Tests both signed and unsigned conversion from I16x8 (packing).
1398 25923 : WASM_SIMD_TEST(I8x16ConvertI16x8) {
1399 : WasmRunner<int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t> r(
1400 : execution_tier, lower_simd);
1401 : byte a = 0;
1402 : byte b = 1;
1403 : // indices for packed signed params
1404 : byte ps_a = 2;
1405 : byte ps_b = 3;
1406 : // indices for packed unsigned params
1407 : byte pu_a = 4;
1408 : byte pu_b = 5;
1409 : byte simd0 = r.AllocateLocal(kWasmS128);
1410 : byte simd1 = r.AllocateLocal(kWasmS128);
1411 : byte simd2 = r.AllocateLocal(kWasmS128);
1412 12 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
1413 : WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
1414 : WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI8x16SConvertI16x8,
1415 : WASM_GET_LOCAL(simd0),
1416 : WASM_GET_LOCAL(simd1))),
1417 : WASM_SIMD_CHECK16(I8x16, simd2, I32, ps_a, ps_a, ps_a, ps_a, ps_a, ps_a,
1418 : ps_a, ps_a, ps_b, ps_b, ps_b, ps_b, ps_b, ps_b, ps_b,
1419 : ps_b),
1420 : WASM_SET_LOCAL(simd2, WASM_SIMD_BINOP(kExprI8x16UConvertI16x8,
1421 : WASM_GET_LOCAL(simd0),
1422 : WASM_GET_LOCAL(simd1))),
1423 : WASM_SIMD_CHECK16(I8x16, simd2, I32, pu_a, pu_a, pu_a, pu_a, pu_a, pu_a,
1424 : pu_a, pu_a, pu_b, pu_b, pu_b, pu_b, pu_b, pu_b, pu_b,
1425 : pu_b),
1426 : WASM_ONE);
1427 :
1428 120 : FOR_INT16_INPUTS(i) {
1429 1080 : FOR_INT16_INPUTS(j) {
1430 : // packed signed values
1431 1944 : int32_t ps_a = Narrow<int8_t>(i);
1432 1944 : int32_t ps_b = Narrow<int8_t>(j);
1433 : // packed unsigned values
1434 972 : int32_t pu_a = UnsignedNarrow<int8_t>(i);
1435 972 : int32_t pu_b = UnsignedNarrow<int8_t>(j);
1436 : // Sign-extend here, since ExtractLane sign extends.
1437 972 : if (pu_a & 0x80) pu_a |= 0xFFFFFF00;
1438 972 : if (pu_b & 0x80) pu_b |= 0xFFFFFF00;
1439 972 : CHECK_EQ(1, r.Call(i, j, ps_a, ps_b, pu_a, pu_b));
1440 : }
1441 12 : }
1442 12 : }
1443 :
1444 132 : void RunI8x16BinOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1445 : WasmOpcode simd_op, Int8BinOp expected_op) {
1446 : WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1447 : byte a = 0;
1448 : byte b = 1;
1449 : byte expected = 2;
1450 : byte simd0 = r.AllocateLocal(kWasmS128);
1451 : byte simd1 = r.AllocateLocal(kWasmS128);
1452 132 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
1453 : WASM_SET_LOCAL(simd1, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(b))),
1454 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
1455 : WASM_GET_LOCAL(simd1))),
1456 : WASM_SIMD_CHECK_SPLAT16(I8x16, simd1, I32, expected), WASM_ONE);
1457 :
1458 1320 : FOR_INT8_INPUTS(i) {
1459 1188 : FOR_INT8_INPUTS(j) { CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); }
1460 132 : }
1461 132 : }
1462 :
1463 25899 : WASM_SIMD_TEST(I8x16Add) {
1464 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16Add,
1465 12 : base::AddWithWraparound);
1466 0 : }
1467 :
1468 25899 : WASM_SIMD_TEST(I8x16AddSaturateS) {
1469 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16AddSaturateS,
1470 12 : AddSaturate);
1471 0 : }
1472 :
1473 25899 : WASM_SIMD_TEST(I8x16Sub) {
1474 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16Sub,
1475 12 : base::SubWithWraparound);
1476 0 : }
1477 :
1478 25899 : WASM_SIMD_TEST(I8x16SubSaturateS) {
1479 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16SubSaturateS,
1480 12 : SubSaturate);
1481 0 : }
1482 :
1483 25899 : WASM_SIMD_TEST(I8x16MinS) {
1484 12 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MinS, Minimum);
1485 0 : }
1486 :
1487 25899 : WASM_SIMD_TEST(I8x16MaxS) {
1488 12 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MaxS, Maximum);
1489 0 : }
1490 :
1491 25899 : WASM_SIMD_TEST(I8x16AddSaturateU) {
1492 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16AddSaturateU,
1493 12 : UnsignedAddSaturate);
1494 0 : }
1495 :
1496 25899 : WASM_SIMD_TEST(I8x16SubSaturateU) {
1497 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16SubSaturateU,
1498 12 : UnsignedSubSaturate);
1499 0 : }
1500 :
1501 25899 : WASM_SIMD_TEST(I8x16MinU) {
1502 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MinU,
1503 12 : UnsignedMinimum);
1504 0 : }
1505 :
1506 25899 : WASM_SIMD_TEST(I8x16MaxU) {
1507 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16MaxU,
1508 12 : UnsignedMaximum);
1509 0 : }
1510 :
1511 120 : void RunI8x16CompareOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1512 : WasmOpcode simd_op, Int8CompareOp expected_op) {
1513 : WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1514 : byte a = 0;
1515 : byte b = 1;
1516 : byte expected = 2;
1517 : byte simd0 = r.AllocateLocal(kWasmS128);
1518 : byte simd1 = r.AllocateLocal(kWasmS128);
1519 120 : BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
1520 : WASM_SET_LOCAL(simd1, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(b))),
1521 : WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
1522 : WASM_GET_LOCAL(simd1))),
1523 : WASM_SIMD_CHECK_SPLAT16(I8x16, simd1, I32, expected), WASM_ONE);
1524 :
1525 1200 : FOR_INT8_INPUTS(i) {
1526 1080 : FOR_INT8_INPUTS(j) { CHECK_EQ(1, r.Call(i, j, expected_op(i, j))); }
1527 120 : }
1528 120 : }
1529 :
1530 25899 : WASM_SIMD_TEST(I8x16Eq) {
1531 12 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16Eq, Equal);
1532 0 : }
1533 :
1534 25899 : WASM_SIMD_TEST(I8x16Ne) {
1535 12 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16Ne, NotEqual);
1536 0 : }
1537 :
1538 25899 : WASM_SIMD_TEST(I8x16GtS) {
1539 12 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GtS, Greater);
1540 0 : }
1541 :
1542 25899 : WASM_SIMD_TEST(I8x16GeS) {
1543 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GeS,
1544 12 : GreaterEqual);
1545 0 : }
1546 :
1547 25899 : WASM_SIMD_TEST(I8x16LtS) {
1548 12 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LtS, Less);
1549 0 : }
1550 :
1551 25899 : WASM_SIMD_TEST(I8x16LeS) {
1552 12 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LeS, LessEqual);
1553 0 : }
1554 :
1555 25899 : WASM_SIMD_TEST(I8x16GtU) {
1556 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GtU,
1557 12 : UnsignedGreater);
1558 0 : }
1559 :
1560 25899 : WASM_SIMD_TEST(I8x16GeU) {
1561 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16GeU,
1562 12 : UnsignedGreaterEqual);
1563 0 : }
1564 :
1565 25899 : WASM_SIMD_TEST(I8x16LtU) {
1566 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LtU,
1567 12 : UnsignedLess);
1568 0 : }
1569 :
1570 25899 : WASM_SIMD_TEST(I8x16LeU) {
1571 : RunI8x16CompareOpTest(execution_tier, lower_simd, kExprI8x16LeU,
1572 12 : UnsignedLessEqual);
1573 0 : }
1574 :
1575 25899 : WASM_SIMD_TEST(I8x16Mul) {
1576 : RunI8x16BinOpTest(execution_tier, lower_simd, kExprI8x16Mul,
1577 12 : base::MulWithWraparound);
1578 0 : }
1579 :
1580 36 : void RunI8x16ShiftOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1581 : WasmOpcode simd_op, Int8ShiftOp expected_op) {
1582 288 : for (int shift = 1; shift < 8; ++shift) {
1583 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd);
1584 : byte a = 0;
1585 : byte expected = 1;
1586 : byte simd = r.AllocateLocal(kWasmS128);
1587 252 : BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
1588 : WASM_SET_LOCAL(
1589 : simd, WASM_SIMD_SHIFT_OP(simd_op, shift, WASM_GET_LOCAL(simd))),
1590 : WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected), WASM_ONE);
1591 :
1592 252 : FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(i, expected_op(i, shift))); }
1593 252 : }
1594 36 : }
1595 :
1596 25899 : WASM_SIMD_TEST(I8x16Shl) {
1597 : RunI8x16ShiftOpTest(execution_tier, lower_simd, kExprI8x16Shl,
1598 12 : LogicalShiftLeft);
1599 0 : }
1600 :
1601 25899 : WASM_SIMD_TEST(I8x16ShrS) {
1602 : RunI8x16ShiftOpTest(execution_tier, lower_simd, kExprI8x16ShrS,
1603 12 : ArithmeticShiftRight);
1604 0 : }
1605 :
1606 25899 : WASM_SIMD_TEST(I8x16ShrU) {
1607 : RunI8x16ShiftOpTest(execution_tier, lower_simd, kExprI8x16ShrU,
1608 12 : LogicalShiftRight);
1609 0 : }
1610 :
1611 : // Test Select by making a mask where the 0th and 3rd lanes are true and the
1612 : // rest false, and comparing for non-equality with zero to convert to a boolean
1613 : // vector.
1614 : #define WASM_SIMD_SELECT_TEST(format) \
1615 : WASM_SIMD_TEST_TURBOFAN(S##format##Select) { \
1616 : WasmRunner<int32_t, int32_t, int32_t> r(execution_tier, lower_simd); \
1617 : byte val1 = 0; \
1618 : byte val2 = 1; \
1619 : byte src1 = r.AllocateLocal(kWasmS128); \
1620 : byte src2 = r.AllocateLocal(kWasmS128); \
1621 : byte zero = r.AllocateLocal(kWasmS128); \
1622 : byte mask = r.AllocateLocal(kWasmS128); \
1623 : BUILD(r, \
1624 : WASM_SET_LOCAL(src1, \
1625 : WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \
1626 : WASM_SET_LOCAL(src2, \
1627 : WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \
1628 : WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
1629 : WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
1630 : 1, WASM_GET_LOCAL(zero), WASM_I32V(-1))), \
1631 : WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
1632 : 2, WASM_GET_LOCAL(mask), WASM_I32V(-1))), \
1633 : WASM_SET_LOCAL( \
1634 : mask, \
1635 : WASM_SIMD_SELECT( \
1636 : format, WASM_GET_LOCAL(src1), WASM_GET_LOCAL(src2), \
1637 : WASM_SIMD_BINOP(kExprI##format##Ne, WASM_GET_LOCAL(mask), \
1638 : WASM_GET_LOCAL(zero)))), \
1639 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \
1640 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 1), \
1641 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, val1, 2), \
1642 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \
1643 : \
1644 : CHECK_EQ(1, r.Call(0x12, 0x34)); \
1645 : }
1646 :
1647 25899 : WASM_SIMD_SELECT_TEST(32x4)
1648 25899 : WASM_SIMD_SELECT_TEST(16x8)
1649 25899 : WASM_SIMD_SELECT_TEST(8x16)
1650 :
1651 : // Test Select by making a mask where the 0th and 3rd lanes are non-zero and the
1652 : // rest 0. The mask is not the result of a comparison op.
1653 : #define WASM_SIMD_NON_CANONICAL_SELECT_TEST(format) \
1654 : WASM_SIMD_TEST_TURBOFAN(S##format##NonCanonicalSelect) { \
1655 : WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_tier, \
1656 : lower_simd); \
1657 : byte val1 = 0; \
1658 : byte val2 = 1; \
1659 : byte combined = 2; \
1660 : byte src1 = r.AllocateLocal(kWasmS128); \
1661 : byte src2 = r.AllocateLocal(kWasmS128); \
1662 : byte zero = r.AllocateLocal(kWasmS128); \
1663 : byte mask = r.AllocateLocal(kWasmS128); \
1664 : BUILD(r, \
1665 : WASM_SET_LOCAL(src1, \
1666 : WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val1))), \
1667 : WASM_SET_LOCAL(src2, \
1668 : WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(val2))), \
1669 : WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
1670 : WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
1671 : 1, WASM_GET_LOCAL(zero), WASM_I32V(0xF))), \
1672 : WASM_SET_LOCAL(mask, WASM_SIMD_I##format##_REPLACE_LANE( \
1673 : 2, WASM_GET_LOCAL(mask), WASM_I32V(0xF))), \
1674 : WASM_SET_LOCAL(mask, WASM_SIMD_SELECT(format, WASM_GET_LOCAL(src1), \
1675 : WASM_GET_LOCAL(src2), \
1676 : WASM_GET_LOCAL(mask))), \
1677 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 0), \
1678 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, combined, 1), \
1679 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, combined, 2), \
1680 : WASM_SIMD_CHECK_LANE(I##format, mask, I32, val2, 3), WASM_ONE); \
1681 : \
1682 : CHECK_EQ(1, r.Call(0x12, 0x34, 0x32)); \
1683 : }
1684 :
1685 25899 : WASM_SIMD_NON_CANONICAL_SELECT_TEST(32x4)
1686 25899 : WASM_SIMD_NON_CANONICAL_SELECT_TEST(16x8)
1687 25899 : WASM_SIMD_NON_CANONICAL_SELECT_TEST(8x16)
1688 :
1689 : // Test binary ops with two lane test patterns, all lanes distinct.
1690 : template <typename T>
1691 7764 : void RunBinaryLaneOpTest(
1692 : ExecutionTier execution_tier, LowerSimd lower_simd, WasmOpcode simd_op,
1693 : const std::array<T, kSimd128Size / sizeof(T)>& expected) {
1694 : WasmRunner<int32_t> r(execution_tier, lower_simd);
1695 : // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7].
1696 7764 : T* src0 = r.builder().AddGlobal<T>(kWasmS128);
1697 7764 : T* src1 = r.builder().AddGlobal<T>(kWasmS128);
1698 : static const int kElems = kSimd128Size / sizeof(T);
1699 131604 : for (int i = 0; i < kElems; i++) {
1700 123840 : WriteLittleEndianValue<T>(&src0[i], i);
1701 123840 : WriteLittleEndianValue<T>(&src1[i], kElems + i);
1702 : }
1703 7764 : if (simd_op == kExprS8x16Shuffle) {
1704 7728 : BUILD(r,
1705 : WASM_SET_GLOBAL(0, WASM_SIMD_S8x16_SHUFFLE_OP(simd_op, expected,
1706 : WASM_GET_GLOBAL(0),
1707 : WASM_GET_GLOBAL(1))),
1708 : WASM_ONE);
1709 : } else {
1710 36 : BUILD(r,
1711 : WASM_SET_GLOBAL(0, WASM_SIMD_BINOP(simd_op, WASM_GET_GLOBAL(0),
1712 : WASM_GET_GLOBAL(1))),
1713 : WASM_ONE);
1714 : }
1715 :
1716 7764 : CHECK_EQ(1, r.Call());
1717 123840 : for (size_t i = 0; i < expected.size(); i++) {
1718 123840 : CHECK_EQ(ReadLittleEndianValue<T>(&src0[i]), expected[i]);
1719 7764 : }
1720 7764 : }
1721 :
1722 25923 : WASM_SIMD_TEST(I32x4AddHoriz) {
1723 : // Inputs are [0 1 2 3] and [4 5 6 7].
1724 : RunBinaryLaneOpTest<int32_t>(execution_tier, lower_simd, kExprI32x4AddHoriz,
1725 12 : {{1, 5, 9, 13}});
1726 12 : }
1727 :
1728 25923 : WASM_SIMD_TEST(I16x8AddHoriz) {
1729 : // Inputs are [0 1 2 3 4 5 6 7] and [8 9 10 11 12 13 14 15].
1730 : RunBinaryLaneOpTest<int16_t>(execution_tier, lower_simd, kExprI16x8AddHoriz,
1731 12 : {{1, 5, 9, 13, 17, 21, 25, 29}});
1732 12 : }
1733 :
1734 25923 : WASM_SIMD_TEST(F32x4AddHoriz) {
1735 : // Inputs are [0.0f 1.0f 2.0f 3.0f] and [4.0f 5.0f 6.0f 7.0f].
1736 : RunBinaryLaneOpTest<float>(execution_tier, lower_simd, kExprF32x4AddHoriz,
1737 12 : {{1.0f, 5.0f, 9.0f, 13.0f}});
1738 12 : }
1739 :
1740 : // Test shuffle ops.
1741 1932 : void RunShuffleOpTest(ExecutionTier execution_tier, LowerSimd lower_simd,
1742 : WasmOpcode simd_op,
1743 : const std::array<int8_t, kSimd128Size>& shuffle) {
1744 : // Test the original shuffle.
1745 1932 : RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op, shuffle);
1746 :
1747 : // Test a non-canonical (inputs reversed) version of the shuffle.
1748 1932 : std::array<int8_t, kSimd128Size> other_shuffle(shuffle);
1749 1932 : for (size_t i = 0; i < shuffle.size(); ++i) other_shuffle[i] ^= kSimd128Size;
1750 : RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op,
1751 1932 : other_shuffle);
1752 :
1753 : // Test the swizzle (one-operand) version of the shuffle.
1754 1932 : std::array<int8_t, kSimd128Size> swizzle(shuffle);
1755 1932 : for (size_t i = 0; i < shuffle.size(); ++i) swizzle[i] &= (kSimd128Size - 1);
1756 1932 : RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op, swizzle);
1757 :
1758 : // Test the non-canonical swizzle (one-operand) version of the shuffle.
1759 1932 : std::array<int8_t, kSimd128Size> other_swizzle(shuffle);
1760 1932 : for (size_t i = 0; i < shuffle.size(); ++i) other_swizzle[i] |= kSimd128Size;
1761 : RunBinaryLaneOpTest<int8_t>(execution_tier, lower_simd, simd_op,
1762 1932 : other_swizzle);
1763 1932 : }
1764 :
1765 : #define SHUFFLE_LIST(V) \
1766 : V(S128Identity) \
1767 : V(S32x4Dup) \
1768 : V(S32x4ZipLeft) \
1769 : V(S32x4ZipRight) \
1770 : V(S32x4UnzipLeft) \
1771 : V(S32x4UnzipRight) \
1772 : V(S32x4TransposeLeft) \
1773 : V(S32x4TransposeRight) \
1774 : V(S32x2Reverse) \
1775 : V(S32x4Irregular) \
1776 : V(S16x8Dup) \
1777 : V(S16x8ZipLeft) \
1778 : V(S16x8ZipRight) \
1779 : V(S16x8UnzipLeft) \
1780 : V(S16x8UnzipRight) \
1781 : V(S16x8TransposeLeft) \
1782 : V(S16x8TransposeRight) \
1783 : V(S16x4Reverse) \
1784 : V(S16x2Reverse) \
1785 : V(S16x8Irregular) \
1786 : V(S8x16Dup) \
1787 : V(S8x16ZipLeft) \
1788 : V(S8x16ZipRight) \
1789 : V(S8x16UnzipLeft) \
1790 : V(S8x16UnzipRight) \
1791 : V(S8x16TransposeLeft) \
1792 : V(S8x16TransposeRight) \
1793 : V(S8x8Reverse) \
1794 : V(S8x4Reverse) \
1795 : V(S8x2Reverse) \
1796 : V(S8x16Irregular)
1797 :
1798 : enum ShuffleKey {
1799 : #define SHUFFLE_ENUM_VALUE(Name) k##Name,
1800 : SHUFFLE_LIST(SHUFFLE_ENUM_VALUE)
1801 : #undef SHUFFLE_ENUM_VALUE
1802 : kNumShuffleKeys
1803 : };
1804 :
1805 : using Shuffle = std::array<int8_t, kSimd128Size>;
1806 : using ShuffleMap = std::map<ShuffleKey, const Shuffle>;
1807 :
1808 25875 : ShuffleMap test_shuffles = {
1809 : {kS128Identity,
1810 : {{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}}},
1811 : {kS32x4Dup,
1812 : {{16, 17, 18, 19, 16, 17, 18, 19, 16, 17, 18, 19, 16, 17, 18, 19}}},
1813 : {kS32x4ZipLeft, {{0, 1, 2, 3, 16, 17, 18, 19, 4, 5, 6, 7, 20, 21, 22, 23}}},
1814 : {kS32x4ZipRight,
1815 : {{8, 9, 10, 11, 24, 25, 26, 27, 12, 13, 14, 15, 28, 29, 30, 31}}},
1816 : {kS32x4UnzipLeft,
1817 : {{0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27}}},
1818 : {kS32x4UnzipRight,
1819 : {{4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31}}},
1820 : {kS32x4TransposeLeft,
1821 : {{0, 1, 2, 3, 16, 17, 18, 19, 8, 9, 10, 11, 24, 25, 26, 27}}},
1822 : {kS32x4TransposeRight,
1823 : {{4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31}}},
1824 : {kS32x2Reverse, // swizzle only
1825 : {{4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}}},
1826 : {kS32x4Irregular,
1827 : {{0, 1, 2, 3, 16, 17, 18, 19, 16, 17, 18, 19, 20, 21, 22, 23}}},
1828 : {kS16x8Dup,
1829 : {{18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19, 18, 19}}},
1830 : {kS16x8ZipLeft, {{0, 1, 16, 17, 2, 3, 18, 19, 4, 5, 20, 21, 6, 7, 22, 23}}},
1831 : {kS16x8ZipRight,
1832 : {{8, 9, 24, 25, 10, 11, 26, 27, 12, 13, 28, 29, 14, 15, 30, 31}}},
1833 : {kS16x8UnzipLeft,
1834 : {{0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29}}},
1835 : {kS16x8UnzipRight,
1836 : {{2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31}}},
1837 : {kS16x8TransposeLeft,
1838 : {{0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29}}},
1839 : {kS16x8TransposeRight,
1840 : {{2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31}}},
1841 : {kS16x4Reverse, // swizzle only
1842 : {{6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9}}},
1843 : {kS16x2Reverse, // swizzle only
1844 : {{2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13}}},
1845 : {kS16x8Irregular,
1846 : {{0, 1, 16, 17, 16, 17, 0, 1, 4, 5, 20, 21, 6, 7, 22, 23}}},
1847 : {kS8x16Dup,
1848 : {{19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19}}},
1849 : {kS8x16ZipLeft, {{0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}},
1850 : {kS8x16ZipRight,
1851 : {{8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31}}},
1852 : {kS8x16UnzipLeft,
1853 : {{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30}}},
1854 : {kS8x16UnzipRight,
1855 : {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}}},
1856 : {kS8x16TransposeLeft,
1857 : {{0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30}}},
1858 : {kS8x16TransposeRight,
1859 : {{1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31}}},
1860 : {kS8x8Reverse, // swizzle only
1861 : {{7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8}}},
1862 : {kS8x4Reverse, // swizzle only
1863 : {{3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12}}},
1864 : {kS8x2Reverse, // swizzle only
1865 : {{1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14}}},
1866 : {kS8x16Irregular,
1867 : {{0, 16, 0, 16, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}}},
1868 : };
1869 :
1870 : #define SHUFFLE_TEST(Name) \
1871 : WASM_SIMD_TEST(Name) { \
1872 : ShuffleMap::const_iterator it = test_shuffles.find(k##Name); \
1873 : DCHECK_NE(it, test_shuffles.end()); \
1874 : RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, \
1875 : it->second); \
1876 : }
1877 27735 : SHUFFLE_LIST(SHUFFLE_TEST)
1878 : #undef SHUFFLE_TEST
1879 : #undef SHUFFLE_LIST
1880 :
1881 : // Test shuffles that blend the two vectors (elements remain in their lanes.)
1882 25923 : WASM_SIMD_TEST(S8x16Blend) {
1883 : std::array<int8_t, kSimd128Size> expected;
1884 192 : for (int bias = 1; bias < kSimd128Size; bias++) {
1885 1440 : for (int i = 0; i < bias; i++) expected[i] = i;
1886 1440 : for (int i = bias; i < kSimd128Size; i++) expected[i] = i + kSimd128Size;
1887 180 : RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, expected);
1888 : }
1889 12 : }
1890 :
1891 : // Test shuffles that concatenate the two vectors.
1892 25923 : WASM_SIMD_TEST(S8x16Concat) {
1893 : std::array<int8_t, kSimd128Size> expected;
1894 : // n is offset or bias of concatenation.
1895 192 : for (int n = 1; n < kSimd128Size; ++n) {
1896 : int i = 0;
1897 : // last kLanes - n bytes of first vector.
1898 1440 : for (int j = n; j < kSimd128Size; ++j) {
1899 1440 : expected[i++] = j;
1900 : }
1901 : // first n bytes of second vector
1902 1440 : for (int j = 0; j < n; ++j) {
1903 1440 : expected[i++] = j + kSimd128Size;
1904 : }
1905 180 : RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, expected);
1906 : }
1907 12 : }
1908 :
1909 : // Combine 3 shuffles a, b, and c by applying both a and b and then applying c
1910 : // to those two results.
1911 0 : Shuffle Combine(const Shuffle& a, const Shuffle& b, const Shuffle& c) {
1912 : Shuffle result;
1913 19200 : for (int i = 0; i < kSimd128Size; ++i) {
1914 19200 : result[i] = c[i] < kSimd128Size ? a[c[i]] : b[c[i] - kSimd128Size];
1915 : }
1916 1200 : return result;
1917 : }
1918 :
1919 12992 : const Shuffle& GetRandomTestShuffle(v8::base::RandomNumberGenerator* rng) {
1920 12992 : return test_shuffles[static_cast<ShuffleKey>(rng->NextInt(kNumShuffleKeys))];
1921 : }
1922 :
1923 : // Test shuffles that are random combinations of 3 test shuffles. Completely
1924 : // random shuffles almost always generate the slow general shuffle code, so
1925 : // don't exercise as many code paths.
1926 25923 : WASM_SIMD_TEST(S8x16ShuffleFuzz) {
1927 12 : v8::base::RandomNumberGenerator* rng = CcTest::random_number_generator();
1928 : static const int kTests = 100;
1929 1212 : for (int i = 0; i < kTests; ++i) {
1930 1200 : auto shuffle = Combine(GetRandomTestShuffle(rng), GetRandomTestShuffle(rng),
1931 2400 : GetRandomTestShuffle(rng));
1932 1200 : RunShuffleOpTest(execution_tier, lower_simd, kExprS8x16Shuffle, shuffle);
1933 : }
1934 12 : }
1935 :
1936 9392 : void AppendShuffle(const Shuffle& shuffle, std::vector<byte>* buffer) {
1937 9392 : byte opcode[] = {WASM_SIMD_OP(kExprS8x16Shuffle)};
1938 9392 : for (size_t i = 0; i < arraysize(opcode); ++i) buffer->push_back(opcode[i]);
1939 300544 : for (size_t i = 0; i < kSimd128Size; ++i) buffer->push_back((shuffle[i]));
1940 9392 : }
1941 :
1942 16088 : void BuildShuffle(std::vector<Shuffle>& shuffles, std::vector<byte>* buffer) {
1943 : // Perform the leaf shuffles on globals 0 and 1.
1944 800 : size_t row_index = (shuffles.size() - 1) / 2;
1945 11792 : for (size_t i = row_index; i < shuffles.size(); ++i) {
1946 5096 : byte operands[] = {WASM_GET_GLOBAL(0), WASM_GET_GLOBAL(1)};
1947 25480 : for (size_t j = 0; j < arraysize(operands); ++j)
1948 20384 : buffer->push_back(operands[j]);
1949 5096 : AppendShuffle(shuffles[i], buffer);
1950 : }
1951 : // Now perform inner shuffles in the correct order on operands on the stack.
1952 2296 : do {
1953 6592 : for (size_t i = row_index / 2; i < row_index; ++i) {
1954 4296 : AppendShuffle(shuffles[i], buffer);
1955 : }
1956 : row_index /= 2;
1957 : } while (row_index != 0);
1958 800 : byte epilog[] = {kExprSetGlobal, static_cast<byte>(0), WASM_ONE};
1959 800 : for (size_t j = 0; j < arraysize(epilog); ++j) buffer->push_back(epilog[j]);
1960 800 : }
1961 :
1962 1600 : void RunWasmCode(ExecutionTier execution_tier, LowerSimd lower_simd,
1963 1600 : const std::vector<byte>& code,
1964 : std::array<int8_t, kSimd128Size>* result) {
1965 : WasmRunner<int32_t> r(execution_tier, lower_simd);
1966 : // Set up two test patterns as globals, e.g. [0, 1, 2, 3] and [4, 5, 6, 7].
1967 1600 : int8_t* src0 = r.builder().AddGlobal<int8_t>(kWasmS128);
1968 1600 : int8_t* src1 = r.builder().AddGlobal<int8_t>(kWasmS128);
1969 27200 : for (int i = 0; i < kSimd128Size; ++i) {
1970 25600 : WriteLittleEndianValue<int8_t>(&src0[i], i);
1971 25600 : WriteLittleEndianValue<int8_t>(&src1[i], kSimd128Size + i);
1972 : }
1973 1600 : r.Build(code.data(), code.data() + code.size());
1974 1600 : CHECK_EQ(1, r.Call());
1975 25600 : for (size_t i = 0; i < kSimd128Size; i++) {
1976 25600 : (*result)[i] = ReadLittleEndianValue<int8_t>(&src0[i]);
1977 1600 : }
1978 1600 : }
1979 :
1980 : // Test multiple shuffles executed in sequence.
1981 25907 : WASM_SIMD_COMPILED_TEST(S8x16MultiShuffleFuzz) {
1982 8 : v8::base::RandomNumberGenerator* rng = CcTest::random_number_generator();
1983 : static const int kShuffles = 100;
1984 808 : for (int i = 0; i < kShuffles; ++i) {
1985 : // Create an odd number in [3..23] of random test shuffles so we can build
1986 : // a complete binary tree (stored as a heap) of shuffle operations. The leaf
1987 : // shuffles operate on the test pattern inputs, while the interior shuffles
1988 : // operate on the results of the two child shuffles.
1989 800 : int num_shuffles = rng->NextInt(10) * 2 + 3;
1990 : std::vector<Shuffle> shuffles;
1991 10192 : for (int j = 0; j < num_shuffles; ++j) {
1992 9392 : shuffles.push_back(GetRandomTestShuffle(rng));
1993 : }
1994 : // Generate the code for the shuffle expression.
1995 : std::vector<byte> buffer;
1996 800 : BuildShuffle(shuffles, &buffer);
1997 :
1998 : // Run the code using the interpreter to get the expected result.
1999 : std::array<int8_t, kSimd128Size> expected;
2000 800 : RunWasmCode(ExecutionTier::kInterpreter, kNoLowerSimd, buffer, &expected);
2001 : // Run the SIMD or scalar lowered compiled code and compare results.
2002 : std::array<int8_t, kSimd128Size> result;
2003 800 : RunWasmCode(execution_tier, lower_simd, buffer, &result);
2004 13600 : for (size_t i = 0; i < kSimd128Size; ++i) {
2005 12800 : CHECK_EQ(result[i], expected[i]);
2006 : }
2007 : }
2008 8 : }
2009 :
2010 : // Boolean unary operations are 'AllTrue' and 'AnyTrue', which return an integer
2011 : // result. Use relational ops on numeric vectors to create the boolean vector
2012 : // test inputs. Test inputs with all true, all false, one true, and one false.
2013 : #define WASM_SIMD_BOOL_REDUCTION_TEST(format, lanes) \
2014 : WASM_SIMD_TEST(ReductionTest##lanes) { \
2015 : WasmRunner<int32_t> r(execution_tier, lower_simd); \
2016 : byte zero = r.AllocateLocal(kWasmS128); \
2017 : byte one_one = r.AllocateLocal(kWasmS128); \
2018 : byte reduced = r.AllocateLocal(kWasmI32); \
2019 : BUILD(r, WASM_SET_LOCAL(zero, WASM_SIMD_I##format##_SPLAT(WASM_ZERO)), \
2020 : WASM_SET_LOCAL( \
2021 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
2022 : WASM_SIMD_BINOP(kExprI##format##Eq, \
2023 : WASM_GET_LOCAL(zero), \
2024 : WASM_GET_LOCAL(zero)))), \
2025 : WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2026 : WASM_RETURN1(WASM_ZERO)), \
2027 : WASM_SET_LOCAL( \
2028 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
2029 : WASM_SIMD_BINOP(kExprI##format##Ne, \
2030 : WASM_GET_LOCAL(zero), \
2031 : WASM_GET_LOCAL(zero)))), \
2032 : WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2033 : WASM_RETURN1(WASM_ZERO)), \
2034 : WASM_SET_LOCAL( \
2035 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
2036 : WASM_SIMD_BINOP(kExprI##format##Eq, \
2037 : WASM_GET_LOCAL(zero), \
2038 : WASM_GET_LOCAL(zero)))), \
2039 : WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2040 : WASM_RETURN1(WASM_ZERO)), \
2041 : WASM_SET_LOCAL( \
2042 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
2043 : WASM_SIMD_BINOP(kExprI##format##Ne, \
2044 : WASM_GET_LOCAL(zero), \
2045 : WASM_GET_LOCAL(zero)))), \
2046 : WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2047 : WASM_RETURN1(WASM_ZERO)), \
2048 : WASM_SET_LOCAL(one_one, \
2049 : WASM_SIMD_I##format##_REPLACE_LANE( \
2050 : lanes - 1, WASM_GET_LOCAL(zero), WASM_ONE)), \
2051 : WASM_SET_LOCAL( \
2052 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
2053 : WASM_SIMD_BINOP(kExprI##format##Eq, \
2054 : WASM_GET_LOCAL(one_one), \
2055 : WASM_GET_LOCAL(zero)))), \
2056 : WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2057 : WASM_RETURN1(WASM_ZERO)), \
2058 : WASM_SET_LOCAL( \
2059 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, \
2060 : WASM_SIMD_BINOP(kExprI##format##Ne, \
2061 : WASM_GET_LOCAL(one_one), \
2062 : WASM_GET_LOCAL(zero)))), \
2063 : WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2064 : WASM_RETURN1(WASM_ZERO)), \
2065 : WASM_SET_LOCAL( \
2066 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
2067 : WASM_SIMD_BINOP(kExprI##format##Eq, \
2068 : WASM_GET_LOCAL(one_one), \
2069 : WASM_GET_LOCAL(zero)))), \
2070 : WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2071 : WASM_RETURN1(WASM_ZERO)), \
2072 : WASM_SET_LOCAL( \
2073 : reduced, WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, \
2074 : WASM_SIMD_BINOP(kExprI##format##Ne, \
2075 : WASM_GET_LOCAL(one_one), \
2076 : WASM_GET_LOCAL(zero)))), \
2077 : WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(reduced), WASM_ZERO), \
2078 : WASM_RETURN1(WASM_ZERO)), \
2079 : WASM_ONE); \
2080 : CHECK_EQ(1, r.Call()); \
2081 : }
2082 :
2083 25935 : WASM_SIMD_BOOL_REDUCTION_TEST(32x4, 4)
2084 25935 : WASM_SIMD_BOOL_REDUCTION_TEST(16x8, 8)
2085 25935 : WASM_SIMD_BOOL_REDUCTION_TEST(8x16, 16)
2086 :
2087 25923 : WASM_SIMD_TEST(SimdI32x4ExtractWithF32x4) {
2088 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2089 12 : BUILD(r, WASM_IF_ELSE_I(
2090 : WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
2091 : 0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
2092 : WASM_I32_REINTERPRET_F32(WASM_F32(30.5))),
2093 : WASM_I32V(1), WASM_I32V(0)));
2094 12 : CHECK_EQ(1, r.Call());
2095 12 : }
2096 :
2097 25923 : WASM_SIMD_TEST(SimdF32x4ExtractWithI32x4) {
2098 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2099 12 : BUILD(r,
2100 : WASM_IF_ELSE_I(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
2101 : 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))),
2102 : WASM_F32_REINTERPRET_I32(WASM_I32V(15))),
2103 : WASM_I32V(1), WASM_I32V(0)));
2104 12 : CHECK_EQ(1, r.Call());
2105 12 : }
2106 :
2107 25923 : WASM_SIMD_TEST(SimdF32x4AddWithI32x4) {
2108 : // Choose two floating point values whose sum is normal and exactly
2109 : // representable as a float.
2110 : const int kOne = 0x3F800000;
2111 : const int kTwo = 0x40000000;
2112 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2113 12 : BUILD(r,
2114 : WASM_IF_ELSE_I(
2115 : WASM_F32_EQ(
2116 : WASM_SIMD_F32x4_EXTRACT_LANE(
2117 : 0, WASM_SIMD_BINOP(kExprF32x4Add,
2118 : WASM_SIMD_I32x4_SPLAT(WASM_I32V(kOne)),
2119 : WASM_SIMD_I32x4_SPLAT(WASM_I32V(kTwo)))),
2120 : WASM_F32_ADD(WASM_F32_REINTERPRET_I32(WASM_I32V(kOne)),
2121 : WASM_F32_REINTERPRET_I32(WASM_I32V(kTwo)))),
2122 : WASM_I32V(1), WASM_I32V(0)));
2123 12 : CHECK_EQ(1, r.Call());
2124 12 : }
2125 :
2126 25923 : WASM_SIMD_TEST(SimdI32x4AddWithF32x4) {
2127 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2128 12 : BUILD(r,
2129 : WASM_IF_ELSE_I(
2130 : WASM_I32_EQ(
2131 : WASM_SIMD_I32x4_EXTRACT_LANE(
2132 : 0, WASM_SIMD_BINOP(kExprI32x4Add,
2133 : WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25)),
2134 : WASM_SIMD_F32x4_SPLAT(WASM_F32(31.5)))),
2135 : WASM_I32_ADD(WASM_I32_REINTERPRET_F32(WASM_F32(21.25)),
2136 : WASM_I32_REINTERPRET_F32(WASM_F32(31.5)))),
2137 : WASM_I32V(1), WASM_I32V(0)));
2138 12 : CHECK_EQ(1, r.Call());
2139 12 : }
2140 :
2141 25923 : WASM_SIMD_TEST(SimdI32x4Local) {
2142 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2143 : r.AllocateLocal(kWasmS128);
2144 12 : BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
2145 :
2146 : WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0)));
2147 12 : CHECK_EQ(31, r.Call());
2148 12 : }
2149 :
2150 25923 : WASM_SIMD_TEST(SimdI32x4SplatFromExtract) {
2151 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2152 : r.AllocateLocal(kWasmI32);
2153 : r.AllocateLocal(kWasmS128);
2154 12 : BUILD(r, WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE(
2155 : 0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))),
2156 : WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
2157 : WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)));
2158 12 : CHECK_EQ(76, r.Call());
2159 12 : }
2160 :
2161 25923 : WASM_SIMD_TEST(SimdI32x4For) {
2162 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2163 : r.AllocateLocal(kWasmI32);
2164 : r.AllocateLocal(kWasmS128);
2165 12 : BUILD(r,
2166 :
2167 : WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
2168 : WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
2169 : WASM_I32V(53))),
2170 : WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
2171 : WASM_I32V(23))),
2172 : WASM_SET_LOCAL(0, WASM_I32V(0)),
2173 : WASM_LOOP(
2174 : WASM_SET_LOCAL(
2175 : 1, WASM_SIMD_BINOP(kExprI32x4Add, WASM_GET_LOCAL(1),
2176 : WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))),
2177 : WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)), WASM_BR(1))),
2178 : WASM_SET_LOCAL(0, WASM_I32V(1)),
2179 : WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
2180 : WASM_I32V(36)),
2181 : WASM_SET_LOCAL(0, WASM_I32V(0))),
2182 : WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)),
2183 : WASM_I32V(58)),
2184 : WASM_SET_LOCAL(0, WASM_I32V(0))),
2185 : WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)),
2186 : WASM_I32V(28)),
2187 : WASM_SET_LOCAL(0, WASM_I32V(0))),
2188 : WASM_IF(WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
2189 : WASM_I32V(36)),
2190 : WASM_SET_LOCAL(0, WASM_I32V(0))),
2191 : WASM_GET_LOCAL(0));
2192 12 : CHECK_EQ(1, r.Call());
2193 12 : }
2194 :
2195 25923 : WASM_SIMD_TEST(SimdF32x4For) {
2196 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2197 : r.AllocateLocal(kWasmI32);
2198 : r.AllocateLocal(kWasmS128);
2199 12 : BUILD(r, WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
2200 : WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(1),
2201 : WASM_F32(19.5))),
2202 : WASM_SET_LOCAL(0, WASM_I32V(0)),
2203 : WASM_LOOP(
2204 : WASM_SET_LOCAL(
2205 : 1, WASM_SIMD_BINOP(kExprF32x4Add, WASM_GET_LOCAL(1),
2206 : WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))),
2207 : WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)), WASM_BR(1))),
2208 : WASM_SET_LOCAL(0, WASM_I32V(1)),
2209 : WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
2210 : WASM_F32(27.25)),
2211 : WASM_SET_LOCAL(0, WASM_I32V(0))),
2212 : WASM_IF(WASM_F32_NE(WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
2213 : WASM_F32(25.5)),
2214 : WASM_SET_LOCAL(0, WASM_I32V(0))),
2215 : WASM_GET_LOCAL(0));
2216 12 : CHECK_EQ(1, r.Call());
2217 12 : }
2218 :
2219 : template <typename T, int numLanes = 4>
2220 24 : void SetVectorByLanes(T* v, const std::array<T, numLanes>& arr) {
2221 120 : for (int lane = 0; lane < numLanes; lane++) {
2222 96 : WriteLittleEndianValue<T>(&v[lane], arr[lane]);
2223 : }
2224 24 : }
2225 :
2226 : template <typename T>
2227 : const T GetScalar(T* v, int lane) {
2228 : constexpr int kElems = kSimd128Size / sizeof(T);
2229 : const int index = lane;
2230 : USE(kElems);
2231 : DCHECK(index >= 0 && index < kElems);
2232 96 : return ReadLittleEndianValue<T>(&v[index]);
2233 : }
2234 :
2235 25923 : WASM_SIMD_TEST(SimdI32x4GetGlobal) {
2236 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
2237 : // Pad the globals with a few unused slots to get a non-zero offset.
2238 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2239 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2240 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2241 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2242 12 : int32_t* global = r.builder().AddGlobal<int32_t>(kWasmS128);
2243 12 : SetVectorByLanes(global, {{0, 1, 2, 3}});
2244 : r.AllocateLocal(kWasmI32);
2245 12 : BUILD(
2246 : r, WASM_SET_LOCAL(1, WASM_I32V(1)),
2247 : WASM_IF(WASM_I32_NE(WASM_I32V(0),
2248 : WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(4))),
2249 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2250 : WASM_IF(WASM_I32_NE(WASM_I32V(1),
2251 : WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(4))),
2252 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2253 : WASM_IF(WASM_I32_NE(WASM_I32V(2),
2254 : WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(4))),
2255 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2256 : WASM_IF(WASM_I32_NE(WASM_I32V(3),
2257 : WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(4))),
2258 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2259 : WASM_GET_LOCAL(1));
2260 12 : CHECK_EQ(1, r.Call(0));
2261 12 : }
2262 :
2263 25923 : WASM_SIMD_TEST(SimdI32x4SetGlobal) {
2264 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
2265 : // Pad the globals with a few unused slots to get a non-zero offset.
2266 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2267 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2268 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2269 : r.builder().AddGlobal<int32_t>(kWasmI32); // purposefully unused
2270 12 : int32_t* global = r.builder().AddGlobal<int32_t>(kWasmS128);
2271 12 : BUILD(r, WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
2272 : WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(4),
2273 : WASM_I32V(34))),
2274 : WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(4),
2275 : WASM_I32V(45))),
2276 : WASM_SET_GLOBAL(4, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(4),
2277 : WASM_I32V(56))),
2278 : WASM_I32V(1));
2279 12 : CHECK_EQ(1, r.Call(0));
2280 12 : CHECK_EQ(GetScalar(global, 0), 23);
2281 12 : CHECK_EQ(GetScalar(global, 1), 34);
2282 12 : CHECK_EQ(GetScalar(global, 2), 45);
2283 12 : CHECK_EQ(GetScalar(global, 3), 56);
2284 12 : }
2285 :
2286 25923 : WASM_SIMD_TEST(SimdF32x4GetGlobal) {
2287 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
2288 12 : float* global = r.builder().AddGlobal<float>(kWasmS128);
2289 12 : SetVectorByLanes<float>(global, {{0.0, 1.5, 2.25, 3.5}});
2290 : r.AllocateLocal(kWasmI32);
2291 12 : BUILD(
2292 : r, WASM_SET_LOCAL(1, WASM_I32V(1)),
2293 : WASM_IF(WASM_F32_NE(WASM_F32(0.0),
2294 : WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_GLOBAL(0))),
2295 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2296 : WASM_IF(WASM_F32_NE(WASM_F32(1.5),
2297 : WASM_SIMD_F32x4_EXTRACT_LANE(1, WASM_GET_GLOBAL(0))),
2298 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2299 : WASM_IF(WASM_F32_NE(WASM_F32(2.25),
2300 : WASM_SIMD_F32x4_EXTRACT_LANE(2, WASM_GET_GLOBAL(0))),
2301 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2302 : WASM_IF(WASM_F32_NE(WASM_F32(3.5),
2303 : WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_GLOBAL(0))),
2304 : WASM_SET_LOCAL(1, WASM_I32V(0))),
2305 : WASM_GET_LOCAL(1));
2306 12 : CHECK_EQ(1, r.Call(0));
2307 12 : }
2308 :
2309 25923 : WASM_SIMD_TEST(SimdF32x4SetGlobal) {
2310 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
2311 12 : float* global = r.builder().AddGlobal<float>(kWasmS128);
2312 12 : BUILD(r, WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
2313 : WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_GLOBAL(0),
2314 : WASM_F32(45.5))),
2315 : WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_GLOBAL(0),
2316 : WASM_F32(32.25))),
2317 : WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_GLOBAL(0),
2318 : WASM_F32(65.0))),
2319 : WASM_I32V(1));
2320 12 : CHECK_EQ(1, r.Call(0));
2321 12 : CHECK_EQ(GetScalar(global, 0), 13.5f);
2322 12 : CHECK_EQ(GetScalar(global, 1), 45.5f);
2323 12 : CHECK_EQ(GetScalar(global, 2), 32.25f);
2324 12 : CHECK_EQ(GetScalar(global, 3), 65.0f);
2325 12 : }
2326 :
2327 25907 : WASM_SIMD_COMPILED_TEST(SimdLoadStoreLoad) {
2328 : WasmRunner<int32_t> r(execution_tier, lower_simd);
2329 : int32_t* memory =
2330 : r.builder().AddMemoryElems<int32_t>(kWasmPageSize / sizeof(int32_t));
2331 : // Load memory, store it, then reload it and extract the first lane. Use a
2332 : // non-zero offset into the memory of 1 lane (4 bytes) to test indexing.
2333 8 : BUILD(r, WASM_SIMD_STORE_MEM(WASM_I32V(4), WASM_SIMD_LOAD_MEM(WASM_I32V(4))),
2334 : WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_SIMD_LOAD_MEM(WASM_I32V(4))));
2335 :
2336 472 : FOR_INT32_INPUTS(i) {
2337 : int32_t expected = i;
2338 464 : r.builder().WriteMemory(&memory[1], expected);
2339 464 : CHECK_EQ(expected, r.Call());
2340 8 : }
2341 8 : }
2342 :
2343 : #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
2344 : // V8:8665 - Tracking bug to enable reduction tests in the interpreter,
2345 : // and for SIMD lowering.
2346 : // TODO(gdeepti): Enable these tests for ARM/ARM64
2347 : #define WASM_SIMD_ANYTRUE_TEST(format, lanes, max) \
2348 : WASM_SIMD_TEST_TURBOFAN(S##format##AnyTrue) { \
2349 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd); \
2350 : byte simd = r.AllocateLocal(kWasmS128); \
2351 : BUILD( \
2352 : r, \
2353 : WASM_SET_LOCAL(simd, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(0))), \
2354 : WASM_SIMD_UNOP(kExprS1x##lanes##AnyTrue, WASM_GET_LOCAL(simd))); \
2355 : DCHECK_EQ(1, r.Call(max)); \
2356 : DCHECK_EQ(1, r.Call(5)); \
2357 : DCHECK_EQ(0, r.Call(0)); \
2358 : }
2359 25899 : WASM_SIMD_ANYTRUE_TEST(32x4, 4, 0xffffffff)
2360 25899 : WASM_SIMD_ANYTRUE_TEST(16x8, 8, 0xffff)
2361 25899 : WASM_SIMD_ANYTRUE_TEST(8x16, 16, 0xff)
2362 :
2363 : #define WASM_SIMD_ALLTRUE_TEST(format, lanes, max) \
2364 : WASM_SIMD_TEST_TURBOFAN(S##format##AllTrue) { \
2365 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd); \
2366 : byte simd = r.AllocateLocal(kWasmS128); \
2367 : BUILD( \
2368 : r, \
2369 : WASM_SET_LOCAL(simd, WASM_SIMD_I##format##_SPLAT(WASM_GET_LOCAL(0))), \
2370 : WASM_SIMD_UNOP(kExprS1x##lanes##AllTrue, WASM_GET_LOCAL(simd))); \
2371 : DCHECK_EQ(1, r.Call(max)); \
2372 : DCHECK_EQ(0, r.Call(21)); \
2373 : DCHECK_EQ(0, r.Call(0)); \
2374 : }
2375 25899 : WASM_SIMD_ALLTRUE_TEST(32x4, 4, 0xffffffff)
2376 25899 : WASM_SIMD_ALLTRUE_TEST(16x8, 8, 0xffff)
2377 25899 : WASM_SIMD_ALLTRUE_TEST(8x16, 16, 0xff)
2378 : #endif // V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
2379 :
2380 25895 : WASM_SIMD_TEST_TURBOFAN(BitSelect) {
2381 : WasmRunner<int32_t, int32_t> r(execution_tier, lower_simd);
2382 : byte simd = r.AllocateLocal(kWasmS128);
2383 4 : BUILD(r,
2384 : WASM_SET_LOCAL(
2385 : simd,
2386 : WASM_SIMD_SELECT(32x4, WASM_SIMD_I32x4_SPLAT(WASM_I32V(0x01020304)),
2387 : WASM_SIMD_I32x4_SPLAT(WASM_I32V(0)),
2388 : WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0)))),
2389 : WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(simd)));
2390 4 : DCHECK_EQ(0x01020304, r.Call(0xFFFFFFFF));
2391 4 : }
2392 :
2393 : #undef WASM_SIMD_TEST
2394 : #undef WASM_SIMD_CHECK_LANE
2395 : #undef WASM_SIMD_CHECK4
2396 : #undef WASM_SIMD_CHECK_SPLAT4
2397 : #undef WASM_SIMD_CHECK8
2398 : #undef WASM_SIMD_CHECK_SPLAT8
2399 : #undef WASM_SIMD_CHECK16
2400 : #undef WASM_SIMD_CHECK_SPLAT16
2401 : #undef WASM_SIMD_CHECK_F32_LANE
2402 : #undef WASM_SIMD_CHECK_F32x4
2403 : #undef WASM_SIMD_CHECK_SPLAT_F32x4
2404 : #undef WASM_SIMD_CHECK_F32_LANE_ESTIMATE
2405 : #undef WASM_SIMD_CHECK_SPLAT_F32x4_ESTIMATE
2406 : #undef TO_BYTE
2407 : #undef WASM_SIMD_OP
2408 : #undef WASM_SIMD_SPLAT
2409 : #undef WASM_SIMD_UNOP
2410 : #undef WASM_SIMD_BINOP
2411 : #undef WASM_SIMD_SHIFT_OP
2412 : #undef WASM_SIMD_CONCAT_OP
2413 : #undef WASM_SIMD_SELECT
2414 : #undef WASM_SIMD_F32x4_SPLAT
2415 : #undef WASM_SIMD_F32x4_EXTRACT_LANE
2416 : #undef WASM_SIMD_F32x4_REPLACE_LANE
2417 : #undef WASM_SIMD_I32x4_SPLAT
2418 : #undef WASM_SIMD_I32x4_EXTRACT_LANE
2419 : #undef WASM_SIMD_I32x4_REPLACE_LANE
2420 : #undef WASM_SIMD_I16x8_SPLAT
2421 : #undef WASM_SIMD_I16x8_EXTRACT_LANE
2422 : #undef WASM_SIMD_I16x8_REPLACE_LANE
2423 : #undef WASM_SIMD_I8x16_SPLAT
2424 : #undef WASM_SIMD_I8x16_EXTRACT_LANE
2425 : #undef WASM_SIMD_I8x16_REPLACE_LANE
2426 : #undef WASM_SIMD_S8x16_SHUFFLE_OP
2427 : #undef WASM_SIMD_LOAD_MEM
2428 : #undef WASM_SIMD_STORE_MEM
2429 : #undef WASM_SIMD_SELECT_TEST
2430 : #undef WASM_SIMD_NON_CANONICAL_SELECT_TEST
2431 : #undef WASM_SIMD_COMPILED_TEST
2432 : #undef WASM_SIMD_BOOL_REDUCTION_TEST
2433 : #undef WASM_SIMD_TEST_TURBOFAN
2434 : #undef WASM_SIMD_ANYTRUE_TEST
2435 : #undef WASM_SIMD_ALLTRUE_TEST
2436 :
2437 : } // namespace test_run_wasm_simd
2438 : } // namespace wasm
2439 : } // namespace internal
2440 77625 : } // namespace v8
|