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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: test/cctest/wasm/test-wasm-simd-common.cc
diff --git a/test/cctest/wasm/test-wasm-simd-common.cc b/test/cctest/wasm/test-wasm-simd-common.cc
new file mode 100644
index 0000000000000000000000000000000000000000..77a0910b1daed78409fde6bfba649c8ca7550d1a
--- /dev/null
+++ b/test/cctest/wasm/test-wasm-simd-common.cc
@@ -0,0 +1,150 @@
+// Copyright 2017 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "test/cctest/wasm/test-wasm-simd-common.h"
+
+namespace test_wasm_simd_common {
+
+void RunF32x4SplatTest() {
+ FLAG_wasm_simd_prototype = true;
+
+ WasmRunner<int32_t, float> r(kExecuteCompiled);
+ byte lane_val = 0;
+ byte simd = r.AllocateLocal(kWasmS128);
+ BUILD(r,
+ WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
+ WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd, lane_val), WASM_ONE);
+
+ FOR_FLOAT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
+}
+
+void RunF32x4ReplaceLaneTest() {
+ FLAG_wasm_simd_prototype = true;
+ WasmRunner<int32_t, float, float> r(kExecuteCompiled);
+ byte old_val = 0;
+ byte new_val = 1;
+ byte simd = r.AllocateLocal(kWasmS128);
+ BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(old_val))),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_F32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, old_val, old_val, old_val),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_F32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, old_val, old_val),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_F32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK4(F32x4, simd, F32, new_val, new_val, new_val, old_val),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_F32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK_SPLAT4(F32x4, simd, F32, new_val), WASM_ONE);
+
+ CHECK_EQ(1, r.Call(3.14159f, -1.5f));
+}
+
+void RunF32x4BinOpTest(WasmOpcode simd_op, FloatBinOp expected_op,
+ bool skip_zero_inputs) {
+ FLAG_wasm_simd_prototype = true;
+ WasmRunner<int32_t, float, float, float> r(kExecuteCompiled);
+ byte a = 0;
+ byte b = 1;
+ byte expected = 2;
+ byte simd0 = r.AllocateLocal(kWasmS128);
+ byte simd1 = r.AllocateLocal(kWasmS128);
+ BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(a))),
+ WASM_SET_LOCAL(simd1, WASM_SIMD_F32x4_SPLAT(WASM_GET_LOCAL(b))),
+ WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
+ WASM_GET_LOCAL(simd1))),
+ WASM_SIMD_CHECK_SPLAT4_F32(F32x4, simd1, expected), WASM_ONE);
+
+ FOR_FLOAT32_INPUTS(i) {
+ if (std::isnan(*i)) continue;
+ FOR_FLOAT32_INPUTS(j) {
+ if (std::isnan(*j)) continue;
+ if (skip_zero_inputs && std::fpclassify(*i) == FP_ZERO &&
+ std::fpclassify(*j) == FP_ZERO)
+ continue;
+ float expected = expected_op(*i, *j);
+ // SIMD on some platforms may handle denormalized numbers differently.
+ // TODO(bbudge) On platforms that flush denorms to zero, test with
+ // expected == 0.
+ if (std::fpclassify(expected) == FP_SUBNORMAL) continue;
+ if (std::isnan(expected)) continue;
+ CHECK_EQ(1, r.Call(*i, *j, expected));
+ }
+ }
+}
+
+void RunI32x4SplatTest() {
+ FLAG_wasm_simd_prototype = true;
+
+ // Store SIMD value in a local variable, use extract lane to check lane values
+ // This test is not a test for ExtractLane as Splat does not create
+ // interesting SIMD values.
+ //
+ // SetLocal(1, I32x4Splat(Local(0)));
+ // For each lane index
+ // if(Local(0) != I32x4ExtractLane(Local(1), index)
+ // return 0
+ //
+ // return 1
+ WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
+ byte lane_val = 0;
+ byte simd = r.AllocateLocal(kWasmS128);
+ BUILD(r,
+ WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(lane_val))),
+ WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, lane_val), WASM_ONE);
+
+ FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call(*i)); }
+}
+
+void RunI32x4ReplaceLaneTest() {
+ FLAG_wasm_simd_prototype = true;
+ WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
+ byte old_val = 0;
+ byte new_val = 1;
+ byte simd = r.AllocateLocal(kWasmS128);
+ BUILD(r, WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(old_val))),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_I32x4_REPLACE_LANE(0, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, old_val, old_val, old_val),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, old_val, old_val),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK4(I32x4, simd, I32, new_val, new_val, new_val, old_val),
+ WASM_SET_LOCAL(simd,
+ WASM_SIMD_I32x4_REPLACE_LANE(3, WASM_GET_LOCAL(simd),
+ WASM_GET_LOCAL(new_val))),
+ WASM_SIMD_CHECK_SPLAT4(I32x4, simd, I32, new_val), WASM_ONE);
+
+ CHECK_EQ(1, r.Call(1, 2));
+}
+
+void RunI32x4BinOpTest(WasmOpcode simd_op, Int32BinOp expected_op) {
+ FLAG_wasm_simd_prototype = true;
+ WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
+ byte a = 0;
+ byte b = 1;
+ byte expected = 2;
+ byte simd0 = r.AllocateLocal(kWasmS128);
+ byte simd1 = r.AllocateLocal(kWasmS128);
+ BUILD(r, WASM_SET_LOCAL(simd0, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(a))),
+ WASM_SET_LOCAL(simd1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(b))),
+ WASM_SET_LOCAL(simd1, WASM_SIMD_BINOP(simd_op, WASM_GET_LOCAL(simd0),
+ WASM_GET_LOCAL(simd1))),
+ WASM_SIMD_CHECK_SPLAT4(I32x4, simd1, I32, expected), WASM_ONE);
+
+ FOR_INT32_INPUTS(i) {
+ FOR_INT32_INPUTS(j) { CHECK_EQ(1, r.Call(*i, *j, expected_op(*i, *j))); }
+ }
+}
+} // namespace test_wasm_simd_common
« 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