Commit 2769a7c4 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Test binary operations for more inputs

Instead of hard-coding one or two inputs per binary operation, use all
inputs provided by FOR_INT32_INPUTS.

R=ahaas@chromium.org

Change-Id: I534227f93068f52d69ea0ff0fcf686a9af034bad
Reviewed-on: https://chromium-review.googlesource.com/753484
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49136}
parent 12eb3e97
...@@ -158,54 +158,68 @@ WASM_EXEC_TEST(Float64Add) { ...@@ -158,54 +158,68 @@ WASM_EXEC_TEST(Float64Add) {
CHECK_EQ(57, r.Call()); CHECK_EQ(57, r.Call());
} }
void TestInt32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode, // clang-format messes up the FOR_INT32_INPUTS macros.
int32_t expected, int32_t a, int32_t b) { // clang-format off
{ template<typename ctype>
WasmRunner<int32_t> r(execution_mode); static void TestInt32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
// K op K ctype(*expected)(ctype, ctype)) {
BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b))); FOR_INT32_INPUTS(i) {
CHECK_EQ(expected, r.Call()); FOR_INT32_INPUTS(j) {
WasmRunner<ctype> r(execution_mode);
// Apply {opcode} on two constants.
BUILD(r, WASM_BINOP(opcode, WASM_I32V(*i), WASM_I32V(*j)));
CHECK_EQ(expected(*i, *j), r.Call());
}
} }
{ {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<ctype, ctype, ctype> r(execution_mode);
// a op b // Apply {opcode} on two parameters.
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b)); FOR_INT32_INPUTS(i) {
} FOR_INT32_INPUTS(j) {
} CHECK_EQ(expected(*i, *j), r.Call(*i, *j));
}
WASM_EXEC_TEST(Int32Binops) { }
TestInt32Binop(execution_mode, kExprI32Add, 88888888, 33333333, 55555555); }
TestInt32Binop(execution_mode, kExprI32Sub, -1111111, 7777777, 8888888); }
TestInt32Binop(execution_mode, kExprI32Mul, 65130756, 88734, 734); // clang-format on
TestInt32Binop(execution_mode, kExprI32DivS, -66, -4777344, 72384);
TestInt32Binop(execution_mode, kExprI32DivU, 805306368, 0xF0000000, 5); #define WASM_I32_BINOP_TEST(expr, ctype, expected) \
TestInt32Binop(execution_mode, kExprI32RemS, -3, -3003, 1000); WASM_EXEC_TEST(I32Binop_##expr) { \
TestInt32Binop(execution_mode, kExprI32RemU, 4, 4004, 1000); TestInt32Binop<ctype>(execution_mode, kExprI32##expr, \
TestInt32Binop(execution_mode, kExprI32And, 0xEE, 0xFFEE, 0xFF0000FF); [](ctype a, ctype b) -> ctype { return expected; }); \
TestInt32Binop(execution_mode, kExprI32Ior, 0xF0FF00FF, 0xF0F000EE, }
0x000F0011);
TestInt32Binop(execution_mode, kExprI32Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE); WASM_I32_BINOP_TEST(Add, int32_t, a + b)
TestInt32Binop(execution_mode, kExprI32Shl, 0xA0000000, 0xA, 28); WASM_I32_BINOP_TEST(Sub, int32_t, a - b)
TestInt32Binop(execution_mode, kExprI32ShrU, 0x07000010, 0x70000100, 4); WASM_I32_BINOP_TEST(Mul, int32_t, a* b)
TestInt32Binop(execution_mode, kExprI32ShrS, 0xFF000000, 0x80000000, 7); WASM_I32_BINOP_TEST(DivS, int32_t,
TestInt32Binop(execution_mode, kExprI32Ror, 0x01000000, 0x80000000, 7); (a == kMinInt && b == -1) || b == 0
TestInt32Binop(execution_mode, kExprI32Ror, 0x01000000, 0x80000000, 39); ? static_cast<int32_t>(0xdeadbeef)
TestInt32Binop(execution_mode, kExprI32Rol, 0x00000040, 0x80000000, 7); : a / b)
TestInt32Binop(execution_mode, kExprI32Rol, 0x00000040, 0x80000000, 39); WASM_I32_BINOP_TEST(DivU, uint32_t, b == 0 ? 0xdeadbeef : a / b)
TestInt32Binop(execution_mode, kExprI32Eq, 1, -99, -99); WASM_I32_BINOP_TEST(RemS, int32_t, b == 0 ? 0xdeadbeef : b == -1 ? 0 : a % b)
TestInt32Binop(execution_mode, kExprI32Ne, 0, -97, -97); WASM_I32_BINOP_TEST(RemU, uint32_t, b == 0 ? 0xdeadbeef : a % b)
WASM_I32_BINOP_TEST(And, int32_t, a& b)
TestInt32Binop(execution_mode, kExprI32LtS, 1, -4, 4); WASM_I32_BINOP_TEST(Ior, int32_t, a | b)
TestInt32Binop(execution_mode, kExprI32LeS, 0, -2, -3); WASM_I32_BINOP_TEST(Xor, int32_t, a ^ b)
TestInt32Binop(execution_mode, kExprI32LtU, 1, 0, -6); WASM_I32_BINOP_TEST(Shl, int32_t, a << b)
TestInt32Binop(execution_mode, kExprI32LeU, 1, 98978, 0xF0000000); WASM_I32_BINOP_TEST(ShrU, uint32_t, a >> (b % 32))
WASM_I32_BINOP_TEST(ShrS, int32_t, a >> (b % 32))
TestInt32Binop(execution_mode, kExprI32GtS, 1, 4, -4); WASM_I32_BINOP_TEST(Ror, uint32_t, (a >> (b % 32)) | (a << (32 - (b % 32))))
TestInt32Binop(execution_mode, kExprI32GeS, 0, -3, -2); WASM_I32_BINOP_TEST(Rol, uint32_t, (a << (b % 32)) | (a >> (32 - (b % 32))))
TestInt32Binop(execution_mode, kExprI32GtU, 1, -6, 0); WASM_I32_BINOP_TEST(Eq, int32_t, a == b)
TestInt32Binop(execution_mode, kExprI32GeU, 1, 0xF0000000, 98978); WASM_I32_BINOP_TEST(Ne, int32_t, a != b)
} WASM_I32_BINOP_TEST(LtS, int32_t, a < b)
WASM_I32_BINOP_TEST(LeS, int32_t, a <= b)
WASM_I32_BINOP_TEST(LtU, uint32_t, a < b)
WASM_I32_BINOP_TEST(LeU, uint32_t, a <= b)
WASM_I32_BINOP_TEST(GtS, int32_t, a > b)
WASM_I32_BINOP_TEST(GeS, int32_t, a >= b)
WASM_I32_BINOP_TEST(GtU, uint32_t, a > b)
WASM_I32_BINOP_TEST(GeU, uint32_t, a >= b)
#undef WASM_I32_BINOP_TEST
void TestInt32Unop(WasmExecutionMode execution_mode, WasmOpcode opcode, void TestInt32Unop(WasmExecutionMode execution_mode, WasmOpcode opcode,
int32_t expected, int32_t a) { int32_t expected, int32_t a) {
...@@ -311,41 +325,6 @@ WASM_EXEC_TEST(I32Eqz) { ...@@ -311,41 +325,6 @@ WASM_EXEC_TEST(I32Eqz) {
TestInt32Unop(execution_mode, kExprI32Eqz, 1, 0); TestInt32Unop(execution_mode, kExprI32Eqz, 1, 0);
} }
WASM_EXEC_TEST(I32Shl) {
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT32_INPUTS(i) {
FOR_UINT32_INPUTS(j) {
uint32_t expected = (*i) << (*j & 0x1f);
CHECK_EQ(expected, r.Call(*i, *j));
}
}
}
WASM_EXEC_TEST(I32Shr) {
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT32_INPUTS(i) {
FOR_UINT32_INPUTS(j) {
uint32_t expected = (*i) >> (*j & 0x1f);
CHECK_EQ(expected, r.Call(*i, *j));
}
}
}
WASM_EXEC_TEST(I32Sar) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) {
FOR_INT32_INPUTS(j) {
int32_t expected = (*i) >> (*j & 0x1f);
CHECK_EQ(expected, r.Call(*i, *j));
}
}
}
WASM_EXEC_TEST(Int32DivS_trap) { WASM_EXEC_TEST(Int32DivS_trap) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment