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

Unified Diff: test/cctest/wasm/test-run-wasm-64.cc

Issue 1804513002: [wasm] Int64Lowering of I64Div and I64Rem. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« src/compiler/wasm-compiler.cc ('K') | « test/cctest/wasm/test-run-wasm.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-run-wasm-64.cc
diff --git a/test/cctest/wasm/test-run-wasm-64.cc b/test/cctest/wasm/test-run-wasm-64.cc
index 6f879641e69c80232f23ed49a7476dac56a611d2..1ba12fc2c054085208a9168d6181d43810776d87 100644
--- a/test/cctest/wasm/test-run-wasm-64.cc
+++ b/test/cctest/wasm/test-run-wasm-64.cc
@@ -12,10 +12,15 @@
#include "test/cctest/compiler/value-helper.h"
#include "test/cctest/wasm/wasm-run-utils.h"
-// using namespace v8::base;
-// using namespace v8::internal;
-// using namespace v8::internal::compiler;
-// using namespace v8::internal::wasm;
+#define CHECK_TRAP32(x) \
+ CHECK_EQ(0xdeadbeef, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF)
+#define CHECK_TRAP64(x) \
+ CHECK_EQ(0xdeadbeefdeadbeef, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF)
+#define CHECK_TRAP(x) CHECK_TRAP32(x)
+
+#define asi64(x) static_cast<int64_t>(x)
+
+#define asu64(x) static_cast<uint64_t>(x)
// todo(ahaas): I added a list of missing instructions here to make merging
// easier when I do them one by one.
@@ -23,9 +28,134 @@
// kExprI64Sub:
// kExprI64Mul:
// kExprI64DivS:
+
+TEST(Run_WasmI64DivS) {
+ WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ FOR_INT64_INPUTS(i) {
+ FOR_INT64_INPUTS(j) {
+ if (*j == 0) {
+ CHECK_TRAP64(r.Call(*i, *j));
+ } else if (*j == -1 && *i == std::numeric_limits<int64_t>::min()) {
+ CHECK_TRAP64(r.Call(*i, *j));
+ } else {
+ CHECK_EQ(*i / *j, r.Call(*i, *j));
+ }
+ }
+ }
+}
+
+TEST(Run_WasmI64DivS_Trap) {
+ WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ CHECK_EQ(0, r.Call(asi64(0), asi64(100)));
+ CHECK_TRAP64(r.Call(asi64(100), asi64(0)));
+ CHECK_TRAP64(r.Call(asi64(-1001), asi64(0)));
+ CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(-1)));
+ CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0)));
+}
+
+TEST(Run_WasmI64DivS_Byzero_Const) {
+ for (int8_t denom = -2; denom < 8; denom++) {
+ WasmRunner<int64_t> r(MachineType::Int64());
+ BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
+ for (int64_t val = -7; val < 8; val++) {
+ if (denom == 0) {
+ CHECK_TRAP64(r.Call(val));
+ } else {
+ CHECK_EQ(val / denom, r.Call(val));
+ }
+ }
+ }
+}
// kExprI64DivU:
+
+TEST(Run_WasmI64DivU) {
+ WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ FOR_UINT64_INPUTS(i) {
+ FOR_UINT64_INPUTS(j) {
+ if (*j == 0) {
+ CHECK_TRAP64(r.Call(*i, *j));
+ } else {
+ CHECK_EQ(*i / *j, r.Call(*i, *j));
+ }
+ }
+ }
+}
+
+TEST(Run_WasmI64DivU_Trap) {
+ WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ CHECK_EQ(0, r.Call(asu64(0), asu64(100)));
+ CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
+ CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
+ CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
+}
+
+TEST(Run_WasmI64DivU_Byzero_Const) {
+ for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) {
+ WasmRunner<uint64_t> r(MachineType::Uint64());
+ BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
+
+ for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) {
+ if (denom == 0) {
+ CHECK_TRAP64(r.Call(val));
+ } else {
+ CHECK_EQ(val / denom, r.Call(val));
+ }
+ }
+ }
+}
// kExprI64RemS:
+TEST(Run_WasmI64RemS) {
+ WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ FOR_INT64_INPUTS(i) {
+ FOR_INT64_INPUTS(j) {
+ if (*j == 0) {
+ CHECK_TRAP64(r.Call(*i, *j));
+ } else {
+ CHECK_EQ(*i % *j, r.Call(*i, *j));
+ }
+ }
+ }
+}
+
+TEST(Run_WasmI64RemS_Trap) {
+ WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
+ BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ CHECK_EQ(33, r.Call(asi64(133), asi64(100)));
+ CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), asi64(-1)));
+ CHECK_TRAP64(r.Call(asi64(100), asi64(0)));
+ CHECK_TRAP64(r.Call(asi64(-1001), asi64(0)));
+ CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0)));
+}
+
// kExprI64RemU:
+TEST(Run_WasmI64RemU) {
+ WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ FOR_UINT64_INPUTS(i) {
+ FOR_UINT64_INPUTS(j) {
+ if (*j == 0) {
+ CHECK_TRAP64(r.Call(*i, *j));
+ } else {
+ CHECK_EQ(*i % *j, r.Call(*i, *j));
+ }
+ }
+ }
+}
+
+TEST(Run_Wasm_I64RemU_Trap) {
+ WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64());
+ BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ CHECK_EQ(17, r.Call(asu64(217), asu64(100)));
+ CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
+ CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
+ CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
+}
+
// kExprI64And:
TEST(Run_WasmI64And) {
WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
« src/compiler/wasm-compiler.cc ('K') | « test/cctest/wasm/test-run-wasm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698