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

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: [wasm]implement simd lowering for F32x4 and I32x4 binops 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 void TestWasmSimdCommon::RunF32x4SplatTest() {
8 FLAG_wasm_simd_prototype = true;
9
10 WasmRunner<int32_t, float> r(kExecuteCompiled);
11 byte lane_val = 0;
12 byte simd = r.AllocateLocal(kWasmS128);
13 BUILD(r,
14 WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
15 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, lane_val), WASM_ONE);
16
17 FOR_FLOAT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
18 }
19
20 void TestWasmSimdCommon::RunF32x4ReplaceLaneTest() {
21 FLAG_wasm_simd_prototype = true;
22 WasmRunner<int32_t, float, float> r(kExecuteCompiled);
23 byte old_val = 0;
24 byte new_val = 1;
25 byte simd = r.AllocateLocal(kWasmS128);
26 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(old_val))),
27 WASM_SET_LOCAL(simd,
28 WASM_SIMD_F32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
29 WASM_GET_LOCAL(new_val))),
30 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, old_val, old_val, old_val),
31 WASM_SET_LOCAL(simd,
32 WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
33 WASM_GET_LOCAL(new_val))),
34 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, old_val, old_val),
35 WASM_SET_LOCAL(simd,
36 WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
37 WASM_GET_LOCAL(new_val))),
38 WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val),
39 WASM_SET_LOCAL(simd,
40 WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
41 WASM_GET_LOCAL(new_val))),
42 WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE);
43
44 CHECK_EQ(1, r.Call(3.14159f, -1.5f));
45 }
46
47 void TestWasmSimdCommon::RunF32x4BinOpTest(WasmOpcode simd_op,
48 FloatBinOp expected_op,
49 bool skip_zero_inputs) {
50 FLAG_wasm_simd_prototype = true;
51 WasmRunner<int32_t, float, float, float> r(kExecuteCompiled);
52 byte a = 0;
53 byte b = 1;
54 byte expected = 2;
55 byte simd0 = r.AllocateLocal(kWasmS128);
56 byte simd1 = r.AllocateLocal(kWasmS128);
57 BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
58 WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
59 WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
60 WASM_GET_LOCAL(simd1))),
61 WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd1, expected), WASM_ONE);
62
63 FOR_FLOAT32_INPUTS(i) {
64 if (std::isnan(*i)) continue;
65 FOR_FLOAT32_INPUTS(j) {
66 if (std::isnan(*j)) continue;
67 if (skip_zero_inputs && std::fpclassify(*i) == FP_ZERO &&
68 std::fpclassify(*j) == FP_ZERO)
69 continue;
70 float expected = expected_op(*i, *j);
71 // SIMD on some platforms may handle denormalized numbers differently.
72 // TODO(bbudge) On platforms that flush denorms to zero, test with
73 // expected == 0.
74 if (std::fpclassify(expected) == FP_SUBNORMAL) continue;
75 if (std::isnan(expected)) continue;
76 CHECK_EQ(1, r.Call(*i, *j, expected));
77 }
78 }
79 }
80
81 void TestWasmSimdCommon::RunI32x4SplatTest() {
82 FLAG_wasm_simd_prototype = true;
83
84 // Store SIMD value in a local variable, use extract lane to check lane values
85 // This test is not a test for ExtractLane as Splat does not create
86 // interesting SIMD values.
87 //
88 // SetLocal(1, I32x4Splat(Local(0)));
89 // For each lane index
90 // if(Local(0) != I32x4ExtractLane(Local(1), index)
91 // return 0
92 //
93 // return 1
94 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
95 byte lane_val = 0;
96 byte simd = r.AllocateLocal(kWasmS128);
97 BUILD(r,
98 WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
99 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), WASM_ONE);
100
101 FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
102 }
103
104 void TestWasmSimdCommon::RunI32x4ReplaceLaneTest() {
105 FLAG_wasm_simd_prototype = true;
106 WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
107 byte old_val = 0;
108 byte new_val = 1;
109 byte simd = r.AllocateLocal(kWasmS128);
110 BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
111 WASM_SET_LOCAL(simd,
112 WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
113 WASM_GET_LOCAL(new_val))),
114 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, old_val),
115 WASM_SET_LOCAL(simd,
116 WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
117 WASM_GET_LOCAL(new_val))),
118 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val, old_val),
119 WASM_SET_LOCAL(simd,
120 WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
121 WASM_GET_LOCAL(new_val))),
122 WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val),
123 WASM_SET_LOCAL(simd,
124 WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
125 WASM_GET_LOCAL(new_val))),
126 WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE);
127
128 CHECK_EQ(1, r.Call(1, 2));
129 }
130
131 void TestWasmSimdCommon::RunI32x4BinOpTest(WasmOpcode simd_op,
132 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 }
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