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

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

Issue 2638133002: [Turbofan] Add other integer SIMD types, add more integer ops. (Closed)
Patch Set: Fix name of static fields. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/compiler/value-helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-macro-gen.h" 5 #include "src/wasm/wasm-macro-gen.h"
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 #include "test/cctest/compiler/value-helper.h" 8 #include "test/cctest/compiler/value-helper.h"
9 #include "test/cctest/wasm/wasm-run-utils.h" 9 #include "test/cctest/wasm/wasm-run-utils.h"
10 10
11 using namespace v8::base; 11 using namespace v8::base;
12 using namespace v8::internal; 12 using namespace v8::internal;
13 using namespace v8::internal::compiler; 13 using namespace v8::internal::compiler;
14 using namespace v8::internal::wasm; 14 using namespace v8::internal::wasm;
15 15
16 namespace { 16 namespace {
17 17
18 typedef float (*FloatUnOp)(float); 18 typedef float (*FloatUnOp)(float);
19 typedef float (*FloatBinOp)(float, float); 19 typedef float (*FloatBinOp)(float, float);
20 typedef int32_t (*FloatCompareOp)(float, float); 20 typedef int32_t (*FloatCompareOp)(float, float);
21 typedef int32_t (*Int32UnOp)(int32_t);
21 typedef int32_t (*Int32BinOp)(int32_t, int32_t); 22 typedef int32_t (*Int32BinOp)(int32_t, int32_t);
23 typedef int16_t (*Int16UnOp)(int16_t);
24 typedef int16_t (*Int16BinOp)(int16_t, int16_t);
25 typedef int8_t (*Int8UnOp)(int8_t);
26 typedef int8_t (*Int8BinOp)(int8_t, int8_t);
22 27
28 #if V8_TARGET_ARCH_ARM
29 // Floating point specific value functions.
30 int32_t Equal(float a, float b) { return a == b ? -1 : 0; }
31
32 int32_t NotEqual(float a, float b) { return a != b ? -1 : 0; }
33 #endif // V8_TARGET_ARCH_ARM
34
35 // Generic expected value functions.
23 template <typename T> 36 template <typename T>
24 T Negate(T a) { 37 T Negate(T a) {
25 return -a; 38 return -a;
26 } 39 }
27 40
28 template <typename T> 41 template <typename T>
29 T Add(T a, T b) { 42 T Add(T a, T b) {
30 return a + b; 43 return a + b;
31 } 44 }
32 45
33 template <typename T> 46 template <typename T>
34 T Sub(T a, T b) { 47 T Sub(T a, T b) {
35 return a - b; 48 return a - b;
36 } 49 }
37 50
38 template <typename T> 51 template <typename T>
39 int32_t Equal(T a, T b) { 52 T Mul(T a, T b) {
40 return a == b ? 0xFFFFFFFF : 0; 53 return a * b;
41 } 54 }
42 55
43 template <typename T> 56 template <typename T>
44 int32_t NotEqual(T a, T b) { 57 T Equal(T a, T b) {
45 return a != b ? 0xFFFFFFFF : 0; 58 return a == b ? -1 : 0;
46 } 59 }
47 60
48 #if V8_TARGET_ARCH_ARM 61 template <typename T>
49 int32_t Equal(float a, float b) { return a == b ? 0xFFFFFFFF : 0; } 62 T NotEqual(T a, T b) {
63 return a != b ? -1 : 0;
64 }
50 65
51 int32_t NotEqual(float a, float b) { return a != b ? 0xFFFFFFFF : 0; } 66 template <typename T>
52 #endif // V8_TARGET_ARCH_ARM 67 T Greater(T a, T b) {
68 return a > b ? -1 : 0;
69 }
70
71 template <typename T>
72 T GreaterEqual(T a, T b) {
73 return a >= b ? -1 : 0;
74 }
75
76 template <typename T>
77 T Less(T a, T b) {
78 return a < b ? -1 : 0;
79 }
80
81 template <typename T>
82 T LessEqual(T a, T b) {
83 return a <= b ? -1 : 0;
84 }
85
86 template <typename T>
87 T UnsignedGreater(T a, T b) {
88 using UnsignedT = typename std::make_unsigned<T>::type;
89 return static_cast<UnsignedT>(a) > static_cast<UnsignedT>(b) ? -1 : 0;
90 }
91
92 template <typename T>
93 T UnsignedGreaterEqual(T a, T b) {
94 using UnsignedT = typename std::make_unsigned<T>::type;
95 return static_cast<UnsignedT>(a) >= static_cast<UnsignedT>(b) ? -1 : 0;
96 }
97
98 template <typename T>
99 T UnsignedLess(T a, T b) {
100 using UnsignedT = typename std::make_unsigned<T>::type;
101 return static_cast<UnsignedT>(a) < static_cast<UnsignedT>(b) ? -1 : 0;
102 }
103
104 template <typename T>
105 T UnsignedLessEqual(T a, T b) {
106 using UnsignedT = typename std::make_unsigned<T>::type;
107 return static_cast<UnsignedT>(a) <= static_cast<UnsignedT>(b) ? -1 : 0;
108 }
53 109
54 } // namespace 110 } // namespace
55 111
56 // TODO(gdeepti): These are tests using sample values to verify functional 112 // TODO(gdeepti): These are tests using sample values to verify functional
57 // correctness of opcodes, add more tests for a range of values and macroize 113 // correctness of opcodes, add more tests for a range of values and macroize
58 // tests. 114 // tests.
59 115
60 // TODO(bbudge) Figure out how to compare floats in Wasm code that can handle 116 // TODO(bbudge) Figure out how to compare floats in Wasm code that can handle
61 // NaNs. For now, our tests avoid using NaNs. 117 // NaNs. For now, our tests avoid using NaNs.
62 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \ 118 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \
63 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \ 119 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \
64 WASM_SIMD_##TYPE##_EXTRACT_LANE( \ 120 WASM_SIMD_##TYPE##_EXTRACT_LANE( \
65 lane_index, WASM_GET_LOCAL(value))), \ 121 lane_index, WASM_GET_LOCAL(value))), \
66 WASM_RETURN1(WASM_ZERO)) 122 WASM_RETURN1(WASM_ZERO))
67 123
68 #define WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3) \ 124 #define WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3) \
69 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \ 125 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \
70 , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \ 126 , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \
71 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \ 127 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \
72 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3) 128 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3)
73 129
74 #define WASM_SIMD_CHECK_SPLAT4(TYPE, value, LANE_TYPE, lv) \ 130 #define WASM_SIMD_CHECK_SPLAT4(TYPE, value, LANE_TYPE, lv) \
75 WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv, lv, lv, lv) 131 WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv, lv, lv, lv)
76 132
133 #define WASM_SIMD_CHECK8(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3, lv4, lv5, \
134 lv6, lv7) \
135 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \
136 , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \
137 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \
138 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3), \
139 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv4, 4), \
140 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv5, 5), \
141 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv6, 6), \
142 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv7, 7)
143
144 #define WASM_SIMD_CHECK_SPLAT8(TYPE, value, LANE_TYPE, lv) \
145 WASM_SIMD_CHECK8(TYPE, value, LANE_TYPE, lv, lv, lv, lv, lv, lv, lv, lv)
146
147 #define WASM_SIMD_CHECK16(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3, lv4, \
148 lv5, lv6, lv7, lv8, lv9, lv10, lv11, lv12, lv13, \
149 lv14, lv15) \
150 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \
151 , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \
152 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \
153 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3), \
154 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv4, 4), \
155 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv5, 5), \
156 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv6, 6), \
157 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv7, 7), \
158 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv8, 8), \
159 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv9, 9), \
160 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv10, 10), \
161 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv11, 11), \
162 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv12, 12), \
163 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv13, 13), \
164 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv14, 14), \
165 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv15, 15)
166
167 #define WASM_SIMD_CHECK_SPLAT16(TYPE, value, LANE_TYPE, lv) \
168 WASM_SIMD_CHECK16(TYPE, value, LANE_TYPE, lv, lv, lv, lv, lv, lv, lv, lv, \
169 lv, lv, lv, lv, lv, lv, lv, lv)
170
77 #define WASM_SIMD_CHECK_F32_LANE(TYPE, value, lane_value, lane_index) \ 171 #define WASM_SIMD_CHECK_F32_LANE(TYPE, value, lane_value, lane_index) \
78 WASM_IF( \ 172 WASM_IF( \
79 WASM_I32_NE(WASM_I32_REINTERPRET_F32(WASM_GET_LOCAL(lane_value)), \ 173 WASM_I32_NE(WASM_I32_REINTERPRET_F32(WASM_GET_LOCAL(lane_value)), \
80 WASM_I32_REINTERPRET_F32(WASM_SIMD_##TYPE##_EXTRACT_LANE( \ 174 WASM_I32_REINTERPRET_F32(WASM_SIMD_##TYPE##_EXTRACT_LANE( \
81 lane_index, WASM_GET_LOCAL(value)))), \ 175 lane_index, WASM_GET_LOCAL(value)))), \
82 WASM_RETURN1(WASM_ZERO)) 176 WASM_RETURN1(WASM_ZERO))
83 177
84 #define WASM_SIMD_CHECK4_F32(TYPE, value, lv0, lv1, lv2, lv3) \ 178 #define WASM_SIMD_CHECK4_F32(TYPE, value, lv0, lv1, lv2, lv3) \
85 WASM_SIMD_CHECK_F32_LANE(TYPE, value, lv0, 0) \ 179 WASM_SIMD_CHECK_F32_LANE(TYPE, value, lv0, 0) \
86 , WASM_SIMD_CHECK_F32_LANE(TYPE, value, lv1, 1), \ 180 , WASM_SIMD_CHECK_F32_LANE(TYPE, value, lv1, 1), \
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd), 428 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
335 WASM_GET_LOCAL(new_val))), 429 WASM_GET_LOCAL(new_val))),
336 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), 430 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val),
337 WASM_RETURN1(WASM_ONE))); 431 WASM_RETURN1(WASM_ONE)));
338 432
339 CHECK_EQ(1, r.Call(1, 2)); 433 CHECK_EQ(1, r.Call(1, 2));
340 } 434 }
341 435
342 #if V8_TARGET_ARCH_ARM 436 #if V8_TARGET_ARCH_ARM
343 437
438 WASM_EXEC_TEST(I16x8Splat) {
439 FLAG_wasm_simd_prototype = true;
440
441 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
442 byte lane_val = 0;
443 byte simd = r.AllocateLocal(kWasmS128);
444 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(
445 WASM_GET_LOCAL(lane_val))),
446 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, lane_val),
447 WASM_RETURN1(WASM_ONE)));
448
449 FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
450 }
451
452 WASM_EXEC_TEST(I16x8ReplaceLane) {
453 FLAG_wasm_simd_prototype = true;
454 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
455 byte old_val = 0;
456 byte new_val = 1;
457 byte simd = r.AllocateLocal(kWasmS128);
458 BUILD(r, WASM_BLOCK(
459 WASM_SET_LOCAL(simd,
460 WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(old_val))),
461 WASM_SET_LOCAL(
462 simd, WASM_SIMD_I16x8_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
463 WASM_GET_LOCAL(new_val))),
464 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, old_val, old_val,
465 old_val, old_val, old_val, old_val, old_val),
466 WASM_SET_LOCAL(
467 simd, WASM_SIMD_I16x8_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
468 WASM_GET_LOCAL(new_val))),
469 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, old_val,
470 old_val, old_val, old_val, old_val, old_val),
471 WASM_SET_LOCAL(
472 simd, WASM_SIMD_I16x8_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
473 WASM_GET_LOCAL(new_val))),
474 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
475 old_val, old_val, old_val, old_val, old_val),
476 WASM_SET_LOCAL(
477 simd, WASM_SIMD_I16x8_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
478 WASM_GET_LOCAL(new_val))),
479 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
480 new_val, old_val, old_val, old_val, old_val),
481 WASM_SET_LOCAL(
482 simd, WASM_SIMD_I16x8_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
483 WASM_GET_LOCAL(new_val))),
484 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
485 new_val, new_val, old_val, old_val, old_val),
486 WASM_SET_LOCAL(
487 simd, WASM_SIMD_I16x8_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
488 WASM_GET_LOCAL(new_val))),
489 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
490 new_val, new_val, new_val, old_val, old_val),
491 WASM_SET_LOCAL(
492 simd, WASM_SIMD_I16x8_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
493 WASM_GET_LOCAL(new_val))),
494 WASM_SIMD_CHECK8(I16x8, simd, I32, new_val, new_val, new_val,
495 new_val, new_val, new_val, new_val, old_val),
496 WASM_SET_LOCAL(
497 simd, WASM_SIMD_I16x8_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
498 WASM_GET_LOCAL(new_val))),
499 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, new_val),
500 WASM_RETURN1(WASM_ONE)));
501
502 CHECK_EQ(1, r.Call(1, 2));
503 }
504
505 WASM_EXEC_TEST(I8x16Splat) {
506 FLAG_wasm_simd_prototype = true;
507
508 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
509 byte lane_val = 0;
510 byte simd = r.AllocateLocal(kWasmS128);
511 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(
512 WASM_GET_LOCAL(lane_val))),
513 WASM_SIMD_CHECK_SPLAT8(I8x16, simd, I32, lane_val),
514 WASM_RETURN1(WASM_ONE)));
515
516 FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
517 }
518
519 WASM_EXEC_TEST(I8x16ReplaceLane) {
520 FLAG_wasm_simd_prototype = true;
521 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
522 byte old_val = 0;
523 byte new_val = 1;
524 byte simd = r.AllocateLocal(kWasmS128);
525 BUILD(r, WASM_BLOCK(
526 WASM_SET_LOCAL(simd,
527 WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(old_val))),
528 WASM_SET_LOCAL(
529 simd, WASM_SIMD_I8x16_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
530 WASM_GET_LOCAL(new_val))),
531 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, old_val, old_val,
532 old_val, old_val, old_val, old_val, old_val,
533 old_val, old_val, old_val, old_val, old_val,
534 old_val, old_val, old_val),
535 WASM_SET_LOCAL(
536 simd, WASM_SIMD_I8x16_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
537 WASM_GET_LOCAL(new_val))),
538 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, old_val,
539 old_val, old_val, old_val, old_val, old_val,
540 old_val, old_val, old_val, old_val, old_val,
541 old_val, old_val, old_val),
542 WASM_SET_LOCAL(
543 simd, WASM_SIMD_I8x16_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
544 WASM_GET_LOCAL(new_val))),
545 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
546 old_val, old_val, old_val, old_val, old_val,
547 old_val, old_val, old_val, old_val, old_val,
548 old_val, old_val, old_val),
549 WASM_SET_LOCAL(
550 simd, WASM_SIMD_I8x16_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
551 WASM_GET_LOCAL(new_val))),
552 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
553 new_val, old_val, old_val, old_val, old_val,
554 old_val, old_val, old_val, old_val, old_val,
555 old_val, old_val, old_val),
556 WASM_SET_LOCAL(
557 simd, WASM_SIMD_I8x16_REPLACE_LANE(4, WASM_GET_LOCAL(simd),
558 WASM_GET_LOCAL(new_val))),
559 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
560 new_val, new_val, old_val, old_val, old_val,
561 old_val, old_val, old_val, old_val, old_val,
562 old_val, old_val, old_val),
563 WASM_SET_LOCAL(
564 simd, WASM_SIMD_I8x16_REPLACE_LANE(5, WASM_GET_LOCAL(simd),
565 WASM_GET_LOCAL(new_val))),
566 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
567 new_val, new_val, new_val, old_val, old_val,
568 old_val, old_val, old_val, old_val, old_val,
569 old_val, old_val, old_val),
570 WASM_SET_LOCAL(
571 simd, WASM_SIMD_I8x16_REPLACE_LANE(6, WASM_GET_LOCAL(simd),
572 WASM_GET_LOCAL(new_val))),
573 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
574 new_val, new_val, new_val, new_val, old_val,
575 old_val, old_val, old_val, old_val, old_val,
576 old_val, old_val, old_val),
577 WASM_SET_LOCAL(
578 simd, WASM_SIMD_I8x16_REPLACE_LANE(7, WASM_GET_LOCAL(simd),
579 WASM_GET_LOCAL(new_val))),
580 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
581 new_val, new_val, new_val, new_val, new_val,
582 old_val, old_val, old_val, old_val, old_val,
583 old_val, old_val, old_val),
584 WASM_SET_LOCAL(
585 simd, WASM_SIMD_I8x16_REPLACE_LANE(8, WASM_GET_LOCAL(simd),
586 WASM_GET_LOCAL(new_val))),
587 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
588 new_val, new_val, new_val, new_val, new_val,
589 new_val, old_val, old_val, old_val, old_val,
590 old_val, old_val, old_val),
591 WASM_SET_LOCAL(
592 simd, WASM_SIMD_I8x16_REPLACE_LANE(9, WASM_GET_LOCAL(simd),
593 WASM_GET_LOCAL(new_val))),
594 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
595 new_val, new_val, new_val, new_val, new_val,
596 new_val, new_val, old_val, old_val, old_val,
597 old_val, old_val, old_val),
598 WASM_SET_LOCAL(
599 simd, WASM_SIMD_I8x16_REPLACE_LANE(10, WASM_GET_LOCAL(simd),
600 WASM_GET_LOCAL(new_val))),
601 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
602 new_val, new_val, new_val, new_val, new_val,
603 new_val, new_val, new_val, old_val, old_val,
604 old_val, old_val, old_val),
605 WASM_SET_LOCAL(
606 simd, WASM_SIMD_I8x16_REPLACE_LANE(11, WASM_GET_LOCAL(simd),
607 WASM_GET_LOCAL(new_val))),
608 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
609 new_val, new_val, new_val, new_val, new_val,
610 new_val, new_val, new_val, new_val, old_val,
611 old_val, old_val, old_val),
612 WASM_SET_LOCAL(
613 simd, WASM_SIMD_I8x16_REPLACE_LANE(12, WASM_GET_LOCAL(simd),
614 WASM_GET_LOCAL(new_val))),
615 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
616 new_val, new_val, new_val, new_val, new_val,
617 new_val, new_val, new_val, new_val, new_val,
618 old_val, old_val, old_val),
619 WASM_SET_LOCAL(
620 simd, WASM_SIMD_I8x16_REPLACE_LANE(13, WASM_GET_LOCAL(simd),
621 WASM_GET_LOCAL(new_val))),
622 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
623 new_val, new_val, new_val, new_val, new_val,
624 new_val, new_val, new_val, new_val, new_val,
625 new_val, old_val, old_val),
626 WASM_SET_LOCAL(
627 simd, WASM_SIMD_I8x16_REPLACE_LANE(14, WASM_GET_LOCAL(simd),
628 WASM_GET_LOCAL(new_val))),
629 WASM_SIMD_CHECK16(I8x16, simd, I32, new_val, new_val, new_val,
630 new_val, new_val, new_val, new_val, new_val,
631 new_val, new_val, new_val, new_val, new_val,
632 new_val, new_val, old_val),
633 WASM_SET_LOCAL(
634 simd, WASM_SIMD_I8x16_REPLACE_LANE(15, WASM_GET_LOCAL(simd),
635 WASM_GET_LOCAL(new_val))),
636 WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, new_val),
637 WASM_RETURN1(WASM_ONE)));
638
639 CHECK_EQ(1, r.Call(1, 2));
640 }
641
344 // Determines if conversion from float to int will be valid. 642 // Determines if conversion from float to int will be valid.
345 bool CanRoundToZeroAndConvert(double val, bool unsigned_integer) { 643 bool CanRoundToZeroAndConvert(double val, bool unsigned_integer) {
346 const double max_uint = static_cast<double>(0xffffffffu); 644 const double max_uint = static_cast<double>(0xffffffffu);
347 const double max_int = static_cast<double>(kMaxInt); 645 const double max_int = static_cast<double>(kMaxInt);
348 const double min_int = static_cast<double>(kMinInt); 646 const double min_int = static_cast<double>(kMinInt);
349 647
350 // Check for NaN. 648 // Check for NaN.
351 if (val != val) { 649 if (val != val) {
352 return false; 650 return false;
353 } 651 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))), 698 simd2, WASM_SIMD_U32x4_FROM_F32x4(WASM_GET_LOCAL(simd0))),
401 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned), 699 WASM_SIMD_CHECK_SPLAT4(I32x4, simd2, I32, expected_unsigned),
402 WASM_RETURN1(WASM_ONE))); 700 WASM_RETURN1(WASM_ONE)));
403 701
404 FOR_FLOAT32_INPUTS(i) { 702 FOR_FLOAT32_INPUTS(i) {
405 int32_t signed_value = ConvertToInt(*i, false); 703 int32_t signed_value = ConvertToInt(*i, false);
406 int32_t unsigned_value = ConvertToInt(*i, true); 704 int32_t unsigned_value = ConvertToInt(*i, true);
407 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value)); 705 CHECK_EQ(1, r.Call(*i, signed_value, unsigned_value));
408 } 706 }
409 } 707 }
708
709 void RunI32x4UnOpTest(WasmOpcode simd_op, Int32UnOp expected_op) {
710 FLAG_wasm_simd_prototype = true;
711 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
712 byte a = 0;
713 byte expected = 1;
714 byte simd = r.AllocateLocal(kWasmS128);
715 BUILD(r, WASM_BLOCK(
716 WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
717 WASM_SET_LOCAL(
718 simd, WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
719 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, expected),
720 WASM_RETURN1(WASM_ONE)));
721
722 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
723 }
724
725 WASM_EXEC_TEST(I32x4Neg) { RunI32x4UnOpTest(kExprI32x4Neg, Negate); }
410 #endif // V8_TARGET_ARCH_ARM 726 #endif // V8_TARGET_ARCH_ARM
411 727
412 void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) { 728 void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) {
413 FLAG_wasm_simd_prototype = true; 729 FLAG_wasm_simd_prototype = true;
414 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); 730 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
415 byte a = 0; 731 byte a = 0;
416 byte b = 1; 732 byte b = 1;
417 byte expected = 2; 733 byte expected = 2;
418 byte simd0 = r.AllocateLocal(kWasmS128); 734 byte simd0 = r.AllocateLocal(kWasmS128);
419 byte simd1 = r.AllocateLocal(kWasmS128); 735 byte simd1 = r.AllocateLocal(kWasmS128);
420 BUILD(r, WASM_BLOCK( 736 BUILD(r, WASM_BLOCK(
421 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))), 737 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
422 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))), 738 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
423 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu, 739 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
424 WASM_GET_LOCAL(simd0), 740 WASM_GET_LOCAL(simd0),
425 WASM_GET_LOCAL(simd1))), 741 WASM_GET_LOCAL(simd1))),
426 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), 742 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected),
427 WASM_RETURN1(WASM_ONE))); 743 WASM_RETURN1(WASM_ONE)));
428 744
429 FOR_INT32_INPUTS(i) { 745 FOR_INT32_INPUTS(i) {
430 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); } 746 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
431 } 747 }
432 } 748 }
433 749
434 WASM_EXEC_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); } 750 WASM_EXEC_TEST(I32x4Add) { RunI32x4BinOpTest(kExprI32x4Add, Add); }
435 751
436 WASM_EXEC_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); } 752 WASM_EXEC_TEST(I32x4Sub) { RunI32x4BinOpTest(kExprI32x4Sub, Sub); }
437 753
438 #if V8_TARGET_ARCH_ARM 754 #if V8_TARGET_ARCH_ARM
755 WASM_EXEC_TEST(I32x4Mul) { RunI32x4BinOpTest(kExprI32x4Mul, Mul); }
756
439 WASM_EXEC_TEST(I32x4Equal) { RunI32x4BinOpTest(kExprI32x4Eq, Equal); } 757 WASM_EXEC_TEST(I32x4Equal) { RunI32x4BinOpTest(kExprI32x4Eq, Equal); }
440 758
441 WASM_EXEC_TEST(I32x4NotEqual) { RunI32x4BinOpTest(kExprI32x4Ne, NotEqual); } 759 WASM_EXEC_TEST(I32x4NotEqual) { RunI32x4BinOpTest(kExprI32x4Ne, NotEqual); }
760
761 WASM_EXEC_TEST(I32x4Greater) { RunI32x4BinOpTest(kExprI32x4GtS, Greater); }
762
763 WASM_EXEC_TEST(I32x4GreaterEqual) {
764 RunI32x4BinOpTest(kExprI32x4GeS, GreaterEqual);
765 }
766
767 WASM_EXEC_TEST(I32x4Less) { RunI32x4BinOpTest(kExprI32x4LtS, Less); }
768
769 WASM_EXEC_TEST(I32x4LessEqual) { RunI32x4BinOpTest(kExprI32x4LeS, LessEqual); }
770
771 WASM_EXEC_TEST(Ui32x4Greater) {
772 RunI32x4BinOpTest(kExprI32x4GtU, UnsignedGreater);
773 }
774
775 WASM_EXEC_TEST(Ui32x4GreaterEqual) {
776 RunI32x4BinOpTest(kExprI32x4GeU, UnsignedGreaterEqual);
777 }
778
779 WASM_EXEC_TEST(Ui32x4Less) { RunI32x4BinOpTest(kExprI32x4LtU, UnsignedLess); }
780
781 WASM_EXEC_TEST(Ui32x4LessEqual) {
782 RunI32x4BinOpTest(kExprI32x4LeU, UnsignedLessEqual);
783 }
784
785 void RunI16x8UnOpTest(WasmOpcode simd_op, Int16UnOp expected_op) {
786 FLAG_wasm_simd_prototype = true;
787 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
788 byte a = 0;
789 byte expected = 1;
790 byte simd = r.AllocateLocal(kWasmS128);
791 BUILD(r, WASM_BLOCK(
792 WASM_SET_LOCAL(simd, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
793 WASM_SET_LOCAL(
794 simd, WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
795 WASM_SIMD_CHECK_SPLAT8(I16x8, simd, I32, expected),
796 WASM_RETURN1(WASM_ONE)));
797
798 FOR_INT16_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
799 }
800
801 WASM_EXEC_TEST(I16x8Neg) { RunI16x8UnOpTest(kExprI16x8Neg, Negate); }
802
803 void RunI16x8BinOpTest(WasmOpcode simd_op, Int16BinOp expected_op) {
804 FLAG_wasm_simd_prototype = true;
805 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
806 byte a = 0;
807 byte b = 1;
808 byte expected = 2;
809 byte simd0 = r.AllocateLocal(kWasmS128);
810 byte simd1 = r.AllocateLocal(kWasmS128);
811 BUILD(r, WASM_BLOCK(
812 WASM_SET_LOCAL(simd0, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(a))),
813 WASM_SET_LOCAL(simd1, WASM_SIMD_I16x8_SPLAT(WASM_GET_LOCAL(b))),
814 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
815 WASM_GET_LOCAL(simd0),
816 WASM_GET_LOCAL(simd1))),
817 WASM_SIMD_CHECK_SPLAT8(I16x8, simd1, I32, expected),
818 WASM_RETURN1(WASM_ONE)));
819
820 FOR_INT16_INPUTS(i) {
821 FOR_INT16_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
822 }
823 }
824
825 WASM_EXEC_TEST(I16x8Add) { RunI16x8BinOpTest(kExprI16x8Add, Add); }
826
827 WASM_EXEC_TEST(I16x8Sub) { RunI16x8BinOpTest(kExprI16x8Sub, Sub); }
828
829 WASM_EXEC_TEST(I16x8Mul) { RunI16x8BinOpTest(kExprI16x8Mul, Mul); }
830
831 WASM_EXEC_TEST(I16x8Equal) { RunI16x8BinOpTest(kExprI16x8Eq, Equal); }
832
833 WASM_EXEC_TEST(I16x8NotEqual) { RunI16x8BinOpTest(kExprI16x8Ne, NotEqual); }
834
835 WASM_EXEC_TEST(I16x8Greater) { RunI16x8BinOpTest(kExprI16x8GtS, Greater); }
836
837 WASM_EXEC_TEST(I16x8GreaterEqual) {
838 RunI16x8BinOpTest(kExprI16x8GeS, GreaterEqual);
839 }
840
841 WASM_EXEC_TEST(I16x8Less) { RunI16x8BinOpTest(kExprI16x8LtS, Less); }
842
843 WASM_EXEC_TEST(I16x8LessEqual) { RunI16x8BinOpTest(kExprI16x8LeS, LessEqual); }
844
845 WASM_EXEC_TEST(Ui16x8Greater) {
846 RunI16x8BinOpTest(kExprI16x8GtU, UnsignedGreater);
847 }
848
849 WASM_EXEC_TEST(Ui16x8GreaterEqual) {
850 RunI16x8BinOpTest(kExprI16x8GeU, UnsignedGreaterEqual);
851 }
852
853 WASM_EXEC_TEST(Ui16x8Less) { RunI16x8BinOpTest(kExprI16x8LtU, UnsignedLess); }
854
855 WASM_EXEC_TEST(Ui16x8LessEqual) {
856 RunI16x8BinOpTest(kExprI16x8LeU, UnsignedLessEqual);
857 }
858
859 void RunI8x16UnOpTest(WasmOpcode simd_op, Int8UnOp expected_op) {
860 FLAG_wasm_simd_prototype = true;
861 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
862 byte a = 0;
863 byte expected = 1;
864 byte simd = r.AllocateLocal(kWasmS128);
865 BUILD(r, WASM_BLOCK(
866 WASM_SET_LOCAL(simd, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
867 WASM_SET_LOCAL(
868 simd, WASM_SIMD_UNOP(simd_op & 0xffu, WASM_GET_LOCAL(simd))),
869 WASM_SIMD_CHECK_SPLAT16(I8x16, simd, I32, expected),
870 WASM_RETURN1(WASM_ONE)));
871
872 FOR_INT8_INPUTS(i) { CHECK_EQ(1, r.Call(*i, expected_op(*i))); }
873 }
874
875 WASM_EXEC_TEST(I8x16Neg) { RunI8x16UnOpTest(kExprI8x16Neg, Negate); }
876
877 void RunI8x16BinOpTest(WasmOpcode simd_op, Int8BinOp expected_op) {
878 FLAG_wasm_simd_prototype = true;
879 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
880 byte a = 0;
881 byte b = 1;
882 byte expected = 2;
883 byte simd0 = r.AllocateLocal(kWasmS128);
884 byte simd1 = r.AllocateLocal(kWasmS128);
885 BUILD(r, WASM_BLOCK(
886 WASM_SET_LOCAL(simd0, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(a))),
887 WASM_SET_LOCAL(simd1, WASM_SIMD_I8x16_SPLAT(WASM_GET_LOCAL(b))),
888 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op & 0xffu,
889 WASM_GET_LOCAL(simd0),
890 WASM_GET_LOCAL(simd1))),
891 WASM_SIMD_CHECK_SPLAT16(I8x16, simd1, I32, expected),
892 WASM_RETURN1(WASM_ONE)));
893
894 FOR_INT8_INPUTS(i) {
895 FOR_INT8_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
896 }
897 }
898
899 WASM_EXEC_TEST(I8x16Add) { RunI8x16BinOpTest(kExprI8x16Add, Add); }
900
901 WASM_EXEC_TEST(I8x16Sub) { RunI8x16BinOpTest(kExprI8x16Sub, Sub); }
902
903 WASM_EXEC_TEST(I8x16Mul) { RunI8x16BinOpTest(kExprI8x16Mul, Mul); }
904
905 WASM_EXEC_TEST(I8x16Equal) { RunI8x16BinOpTest(kExprI8x16Eq, Equal); }
906
907 WASM_EXEC_TEST(I8x16NotEqual) { RunI8x16BinOpTest(kExprI8x16Ne, NotEqual); }
908
909 WASM_EXEC_TEST(I8x16Greater) { RunI8x16BinOpTest(kExprI8x16GtS, Greater); }
910
911 WASM_EXEC_TEST(I8x16GreaterEqual) {
912 RunI8x16BinOpTest(kExprI8x16GeS, GreaterEqual);
913 }
914
915 WASM_EXEC_TEST(I8x16Less) { RunI8x16BinOpTest(kExprI8x16LtS, Less); }
916
917 WASM_EXEC_TEST(I8x16LessEqual) { RunI8x16BinOpTest(kExprI8x16LeS, LessEqual); }
918
919 WASM_EXEC_TEST(Ui8x16Greater) {
920 RunI8x16BinOpTest(kExprI8x16GtU, UnsignedGreater);
921 }
922
923 WASM_EXEC_TEST(Ui8x16GreaterEqual) {
924 RunI8x16BinOpTest(kExprI8x16GeU, UnsignedGreaterEqual);
925 }
926
927 WASM_EXEC_TEST(Ui8x16Less) { RunI8x16BinOpTest(kExprI8x16LtU, UnsignedLess); }
928
929 WASM_EXEC_TEST(Ui8x16LessEqual) {
930 RunI8x16BinOpTest(kExprI8x16LeU, UnsignedLessEqual);
931 }
442 #endif // V8_TARGET_ARCH_ARM 932 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « test/cctest/compiler/value-helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698