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

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

Issue 2713613005: [wasm]implement simd lowering for F32x4 and I32x4 binops (Closed)
Patch Set: use namespace Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "test/cctest/wasm/test-wasm-simd-common.h"
6
7 namespace test_wasm_simd_common {
8
9 void RunF32x4SplatTest() {
10 FLAG_wasm_simd_prototype = true;
11
12 WasmRunner<int32_t, float> r(kExecuteCompiled);
13 byte lane_val = 0;
14 byte simd = r.AllocateLocal(kWasmS128);
15 BUILD(r,
16 WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
17 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, lane_val), WASM_ONE);
18
19 FOR_FLOAT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
20 }
21
22 void RunF32x4ReplaceLaneTest() {
23 FLAG_wasm_simd_prototype = true;
24 WasmRunner<int32_t, float, float> r(kExecuteCompiled);
25 byte old_val = 0;
26 byte new_val = 1;
27 byte simd = r.AllocateLocal(kWasmS128);
28 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(old_val))),
29 WASM_SET_LOCAL(simd,
30 WASM_SIMD_F32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
31 WASM_GET_LOCAL(new_val))),
32 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, old_val, old_val, old_val),
33 WASM_SET_LOCAL(simd,
34 WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
35 WASM_GET_LOCAL(new_val))),
36 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, old_val, old_val),
37 WASM_SET_LOCAL(simd,
38 WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
39 WASM_GET_LOCAL(new_val))),
40 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val),
41 WASM_SET_LOCAL(simd,
42 WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
43 WASM_GET_LOCAL(new_val))),
44 WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE);
45
46 CHECK_EQ(1, r.Call(3.14159f, -1.5f));
47 }
48
49 void RunF32x4BinOpTest(WasmOpcode simd_op, FloatBinOp expected_op,
50 bool skip_zero_inputs) {
51 FLAG_wasm_simd_prototype = true;
52 WasmRunner<int32_t, float, float, float> r(kExecuteCompiled);
53 byte a = 0;
54 byte b = 1;
55 byte expected = 2;
56 byte simd0 = r.AllocateLocal(kWasmS128);
57 byte simd1 = r.AllocateLocal(kWasmS128);
58 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
59 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
60 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
61 WASM_GET_LOCAL(simd1))),
62 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd1, expected), WASM_ONE);
63
64 FOR_FLOAT32_INPUTS(i) {
65 if (std::isnan(*i)) continue;
66 FOR_FLOAT32_INPUTS(j) {
67 if (std::isnan(*j)) continue;
68 if (skip_zero_inputs && std::fpclassify(*i) == FP_ZERO &&
69 std::fpclassify(*j) == FP_ZERO)
70 continue;
71 float expected = expected_op(*i, *j);
72 // SIMD on some platforms may handle denormalized numbers differently.
73 // TODO(bbudge) On platforms that flush denorms to zero, test with
74 // expected == 0.
75 if (std::fpclassify(expected) == FP_SUBNORMAL) continue;
76 if (std::isnan(expected)) continue;
77 CHECK_EQ(1, r.Call(*i, *j, expected));
78 }
79 }
80 }
81
82 void RunI32x4SplatTest() {
83 FLAG_wasm_simd_prototype = true;
84
85 // Store SIMD value in a local variable, use extract lane to check lane values
86 // This test is not a test for ExtractLane as Splat does not create
87 // interesting SIMD values.
88 //
89 // SetLocal(1, I32x4Splat(Local(0)));
90 // For each lane index
91 // if(Local(0) != I32x4ExtractLane(Local(1), index)
92 // return 0
93 //
94 // return 1
95 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
96 byte lane_val = 0;
97 byte simd = r.AllocateLocal(kWasmS128);
98 BUILD(r,
99 WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
100 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), WASM_ONE);
101
102 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
103 }
104
105 void RunI32x4ReplaceLaneTest() {
106 FLAG_wasm_simd_prototype = true;
107 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
108 byte old_val = 0;
109 byte new_val = 1;
110 byte simd = r.AllocateLocal(kWasmS128);
111 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
112 WASM_SET_LOCAL(simd,
113 WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
114 WASM_GET_LOCAL(new_val))),
115 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, old_val),
116 WASM_SET_LOCAL(simd,
117 WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
118 WASM_GET_LOCAL(new_val))),
119 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val, old_val),
120 WASM_SET_LOCAL(simd,
121 WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
122 WASM_GET_LOCAL(new_val))),
123 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val),
124 WASM_SET_LOCAL(simd,
125 WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
126 WASM_GET_LOCAL(new_val))),
127 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE);
128
129 CHECK_EQ(1, r.Call(1, 2));
130 }
131
132 void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) {
133 FLAG_wasm_simd_prototype = true;
134 WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
135 byte a = 0;
136 byte b = 1;
137 byte expected = 2;
138 byte simd0 = r.AllocateLocal(kWasmS128);
139 byte simd1 = r.AllocateLocal(kWasmS128);
140 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
141 WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
142 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
143 WASM_GET_LOCAL(simd1))),
144 WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
145
146 FOR_INT32_INPUTS(i) {
147 FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
148 }
149 }
150 } // namespace test_wasm_simd_common
OLDNEW
« test/cctest/wasm/test-wasm-simd-common.h ('K') | « test/cctest/wasm/test-wasm-simd-common.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698