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

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

Issue 2385393002: [wasm] Implement I32x4ReplaceLane, I32x4Add, I32x4Sub. (Closed)
Patch Set: Bill's review Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-macro-gen.h" 5 #include "src/wasm/wasm-macro-gen.h"
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 #include "test/cctest/compiler/value-helper.h" 8 #include "test/cctest/compiler/value-helper.h"
9 #include "test/cctest/wasm/wasm-run-utils.h" 9 #include "test/cctest/wasm/wasm-run-utils.h"
10 10
11 using namespace v8::base; 11 using namespace v8::base;
12 using namespace v8::internal; 12 using namespace v8::internal;
13 using namespace v8::internal::compiler; 13 using namespace v8::internal::compiler;
14 using namespace v8::internal::wasm; 14 using namespace v8::internal::wasm;
15 15
16 WASM_EXEC_TEST(Splat) { 16 // TODO(gdeepti): These are tests using sample values to verify functional
17 // correctness of opcodes, add more tests for a range of values and macroize
18 // tests.
19
20 #define WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lane_value, lane_index) \
21 WASM_IF(WASM_##LANE_TYPE##_NE(WASM_GET_LOCAL(lane_value), \
22 WASM_SIMD_##TYPE##_EXTRACT_LANE( \
23 lane_index, WASM_GET_LOCAL(value))), \
24 WASM_RETURN1(WASM_ZERO))
25
26 #define WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv0, lv1, lv2, lv3) \
27 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv0, 0) \
28 , WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv1, 1), \
29 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv2, 2), \
30 WASM_SIMD_CHECK_LANE(TYPE, value, LANE_TYPE, lv3, 3)
31
32 #define WASM_SIMD_CHECK_SPLAT4(TYPE, value, LANE_TYPE, lv) \
33 WASM_SIMD_CHECK4(TYPE, value, LANE_TYPE, lv, lv, lv, lv)
34
35 WASM_EXEC_TEST(I32x4Splat) {
17 FLAG_wasm_simd_prototype = true; 36 FLAG_wasm_simd_prototype = true;
18 37
19 // Store SIMD value in a local variable, use extract lane to check lane values 38 // Store SIMD value in a local variable, use extract lane to check lane values
20 // This test is not a test for ExtractLane as Splat does not create 39 // This test is not a test for ExtractLane as Splat does not create
21 // interesting SIMD values. 40 // interesting SIMD values.
22 // 41 //
23 // SetLocal(1, I32x4Splat(Local(0))); 42 // SetLocal(1, I32x4Splat(Local(0)));
24 // For each lane index 43 // For each lane index
25 // if(Local(0) != I32x4ExtractLane(Local(1), index) 44 // if(Local(0) != I32x4ExtractLane(Local(1), index)
26 // return 0 45 // return 0
27 // 46 //
28 // return 1 47 // return 1
29 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32()); 48 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
30 r.AllocateLocal(kAstS128); 49 byte lane_val = 0;
31 BUILD(r, 50 byte simd = r.AllocateLocal(kAstS128);
32 WASM_BLOCK( 51 BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(
33 WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))), 52 WASM_GET_LOCAL(lane_val))),
34 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE( 53 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val),
35 0, WASM_GET_LOCAL(1))), 54 WASM_RETURN1(WASM_ONE)));
36 WASM_RETURN1(WASM_ZERO)),
37 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
38 1, WASM_GET_LOCAL(1))),
39 WASM_RETURN1(WASM_ZERO)),
40 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
41 2, WASM_GET_LOCAL(1))),
42 WASM_RETURN1(WASM_ZERO)),
43 WASM_IF(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_SIMD_I32x4_EXTRACT_LANE(
44 3, WASM_GET_LOCAL(1))),
45 WASM_RETURN1(WASM_ZERO)),
46 WASM_RETURN1(WASM_ONE)));
47 55
48 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); } 56 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
49 } 57 }
58
59 WASM_EXEC_TEST(I32x4ReplaceLane) {
60 FLAG_wasm_simd_prototype = true;
61 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
62 MachineType::Int32());
63 byte old_val = 0;
64 byte new_val = 1;
65 byte simd = r.AllocateLocal(kAstS128);
66 BUILD(r, WASM_BLOCK(
titzer 2016/11/28 09:28:37 I think it'd be better if we made this test into a
gdeepti 2016/12/02 00:43:45 So i tried putting this in a loop, and not sure if
67 WASM_SET_LOCAL(simd,
68 WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
69 WASM_SET_LOCAL(
70 simd, WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
71 WASM_GET_LOCAL(new_val))),
72 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val,
73 old_val),
74 WASM_SET_LOCAL(
75 simd, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
76 WASM_GET_LOCAL(new_val))),
77 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val,
78 old_val),
79 WASM_SET_LOCAL(
80 simd, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
81 WASM_GET_LOCAL(new_val))),
82 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val,
83 old_val),
84 WASM_SET_LOCAL(
85 simd, WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
86 WASM_GET_LOCAL(new_val))),
87 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val),
88 WASM_RETURN1(WASM_ONE)));
89
90 CHECK_EQ(1, r.Call(1, 2));
91 }
92
93 WASM_EXEC_TEST(I32x4Add) {
94 FLAG_wasm_simd_prototype = true;
95 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
96 MachineType::Int32(), MachineType::Int32());
97 byte a = 0;
98 byte b = 1;
99 byte expected = 2;
100 byte simd0 = r.AllocateLocal(kAstS128);
101 byte simd1 = r.AllocateLocal(kAstS128);
102 BUILD(r,
103 WASM_BLOCK(
104 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
105 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
106 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_ADD(WASM_GET_LOCAL(simd0),
107 WASM_GET_LOCAL(simd1))),
108 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected),
109 WASM_RETURN1(WASM_ONE)));
110
111 FOR_INT32_INPUTS(i) {
112 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i + *j)); }
113 }
114 }
115
116 WASM_EXEC_TEST(I32x4Sub) {
117 FLAG_wasm_simd_prototype = true;
118 WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
119 MachineType::Int32(), MachineType::Int32());
120 byte a = 0;
121 byte b = 1;
122 byte expected = 2;
123 byte simd0 = r.AllocateLocal(kAstS128);
124 byte simd1 = r.AllocateLocal(kAstS128);
125 BUILD(r,
126 WASM_BLOCK(
127 WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
128 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
129 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SUB(WASM_GET_LOCAL(simd0),
130 WASM_GET_LOCAL(simd1))),
131 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected),
132 WASM_RETURN1(WASM_ONE)));
133
134 FOR_INT32_INPUTS(i) {
135 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, *i - *j)); }
136 }
137 }
OLDNEW
« src/compiler/x64/instruction-selector-x64.cc ('K') | « src/wasm/wasm-opcodes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698