Commit af193e75 authored by binji's avatar binji Committed by Commit bot

[wasm] Update {i32,i64}.const to use signed leb128

Reland of https://codereview.chromium.org/1765673002

R=titzer@chromium.org
R=bradnelson@chromium.org
LOG=n
BUG=

Review URL: https://codereview.chromium.org/1761173003

Cr-Commit-Position: refs/heads/master@{#34506}
parent 9f8c2116
......@@ -237,7 +237,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
void SetLocalTo(uint16_t index, int value) {
current_function_builder_->Emit(kExprSetLocal);
AddLeb128(index, true);
byte code[] = {WASM_I32(value)};
// TODO(bradnelson): variable size
byte code[] = {WASM_I32V(value)};
current_function_builder_->EmitCode(code, sizeof(code));
block_size_++;
}
......@@ -465,7 +466,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
switch (type) {
case kAstI32: {
int val = static_cast<int>(expr->raw_value()->AsNumber());
byte code[] = {WASM_I32(val)};
// TODO(bradnelson): variable size
byte code[] = {WASM_I32V(val)};
current_function_builder_->EmitCode(code, sizeof(code));
break;
}
......@@ -742,7 +744,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
Handle<Object> nvalue = maybe_nvalue.ToHandleChecked();
if (nvalue->IsNumber()) {
int32_t val = static_cast<int32_t>(nvalue->Number());
byte code[] = {WASM_I32(val)};
// TODO(bradnelson): variable size
byte code[] = {WASM_I32V(val)};
current_function_builder_->EmitCode(code, sizeof(code));
return;
}
......@@ -754,7 +757,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
byte code[] = {WASM_F64(std::numeric_limits<double>::quiet_NaN())};
current_function_builder_->EmitCode(code, sizeof(code));
} else {
byte code[] = {WASM_I32(0)};
byte code[] = {WASM_I32V_1(0)};
current_function_builder_->EmitCode(code, sizeof(code));
}
}
......@@ -812,7 +815,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
DCHECK(value->raw_value()->IsNumber());
DCHECK_EQ(kAstI32, TypeOf(value));
int val = static_cast<int>(value->raw_value()->AsNumber());
byte code[] = {WASM_I32(val * size)};
// TODO(bradnelson): variable size
byte code[] = {WASM_I32V(val * size)};
current_function_builder_->EmitCode(code, sizeof(code));
return;
}
......@@ -1057,7 +1061,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
current_function_builder_->EmitWithU8(kExprCallIndirect,
indices->signature_index);
current_function_builder_->Emit(kExprI32Add);
byte code[] = {WASM_I32(indices->start_index)};
// TODO(bradnelson): variable size
byte code[] = {WASM_I32V(indices->start_index)};
current_function_builder_->EmitCode(code, sizeof(code));
RECURSE(Visit(p->key()));
break;
......
......@@ -46,8 +46,8 @@ struct ImmI32Operand {
int32_t value;
int length;
inline ImmI32Operand(Decoder* decoder, const byte* pc) {
value = bit_cast<int32_t>(decoder->checked_read_u32(pc, 1, "immi32"));
length = 4;
value =
bit_cast<int32_t>(decoder->checked_read_i32v(pc, 1, &length, "immi32"));
}
};
......@@ -55,8 +55,8 @@ struct ImmI64Operand {
int64_t value;
int length;
inline ImmI64Operand(Decoder* decoder, const byte* pc) {
value = bit_cast<int64_t>(decoder->checked_read_u64(pc, 1, "immi64"));
length = 8;
value =
bit_cast<int64_t>(decoder->checked_read_i64v(pc, 1, &length, "immi64"));
}
};
......
......@@ -80,13 +80,14 @@ class Decoder {
// Reads a variable-length unsigned integer (little endian).
uint32_t checked_read_u32v(const byte* base, int offset, int* length,
const char* msg = "expected LEB32") {
return checked_read_leb<uint32_t>(base, offset, length, msg);
return checked_read_leb<uint32_t, false>(base, offset, length, msg);
}
// Reads a variable-length signed integer (little endian).
int32_t checked_read_i32v(const byte* base, int offset, int* length,
const char* msg = "expected SLEB32") {
uint32_t result = checked_read_u32v(base, offset, length, msg);
uint32_t result =
checked_read_leb<uint32_t, true>(base, offset, length, msg);
if (*length == 5) return bit_cast<int32_t>(result);
if (*length > 0) {
int shift = 32 - 7 * *length;
......@@ -99,13 +100,14 @@ class Decoder {
// Reads a variable-length unsigned integer (little endian).
uint64_t checked_read_u64v(const byte* base, int offset, int* length,
const char* msg = "expected LEB64") {
return checked_read_leb<uint64_t>(base, offset, length, msg);
return checked_read_leb<uint64_t, false>(base, offset, length, msg);
}
// Reads a variable-length signed integer (little endian).
int64_t checked_read_i64v(const byte* base, int offset, int* length,
const char* msg = "expected SLEB64") {
uint64_t result = checked_read_u64v(base, offset, length, msg);
uint64_t result =
checked_read_leb<uint64_t, true>(base, offset, length, msg);
if (*length == 10) return bit_cast<int64_t>(result);
if (*length > 0) {
int shift = 64 - 7 * *length;
......@@ -339,7 +341,7 @@ class Decoder {
base::SmartArrayPointer<char> error_msg_;
private:
template <typename IntType>
template <typename IntType, bool is_signed>
IntType checked_read_leb(const byte* base, int offset, int* length,
const char* msg) {
if (!check(base, offset, 1, msg)) {
......@@ -367,7 +369,20 @@ class Decoder {
const int kExtraBits = (1 + kMaxLength * 7) - (sizeof(IntType) * 8);
const byte kExtraBitsMask =
static_cast<byte>((0xFF << (8 - kExtraBits)) & 0xFF);
if (*length == kMaxLength && (b & kExtraBitsMask) != 0) {
int extra_bits_value;
if (is_signed) {
// A signed-LEB128 must sign-extend the final byte, excluding its
// most-signifcant bit. e.g. for a 32-bit LEB128:
// kExtraBits = 4
// kExtraBitsMask = 0xf0
// If b is 0x0f, the value is negative, so extra_bits_value is 0x70.
// If b is 0x03, the value is positive, so extra_bits_value is 0x00.
extra_bits_value = (static_cast<int8_t>(b << kExtraBits) >> 8) &
kExtraBitsMask & ~0x80;
} else {
extra_bits_value = 0;
}
if (*length == kMaxLength && (b & kExtraBitsMask) != extra_bits_value) {
error(base, ptr, "extra bits in varint");
return 0;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -141,12 +141,12 @@ TEST(Run_WasmModule_CheckMemoryIsZero) {
byte code[] = {WASM_BLOCK(
2,
WASM_WHILE(
WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32(kCheckSize)),
WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)),
WASM_IF_ELSE(
WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)),
WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))),
WASM_I8(11))};
uint32_t local_indices[] = {7, 19, 25, 28};
uint32_t local_indices[] = {7, 18, 24, 27};
f->EmitCode(code, sizeof(code), local_indices, sizeof(local_indices) / 4);
WasmModuleWriter* writer = builder->Build(&zone);
TestModule(writer->WriteTo(&zone), 11);
......@@ -197,8 +197,8 @@ TEST(Run_WasmModule_Global) {
f = builder->FunctionAt(f2_index);
f->ReturnType(kAstI32);
f->Exported(1);
byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32(56)),
WASM_STORE_GLOBAL(global2, WASM_I32(41)),
byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32V_1(56)),
WASM_STORE_GLOBAL(global2, WASM_I32V_1(41)),
WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))};
f->EmitCode(code2, sizeof(code2));
WasmModuleWriter* writer = builder->Build(&zone);
......
......@@ -60,7 +60,7 @@ TEST(Run_WasmInt32Const) {
WasmRunner<int32_t> r;
const int32_t kExpectedValue = 0x11223344;
// return(kExpectedValue)
BUILD(r, WASM_I32(kExpectedValue));
BUILD(r, WASM_I32V_5(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call());
}
......@@ -70,7 +70,7 @@ TEST(Run_WasmInt32Const_many) {
WasmRunner<int32_t> r;
const int32_t kExpectedValue = *i;
// return(kExpectedValue)
BUILD(r, WASM_I32(kExpectedValue));
BUILD(r, WASM_I32V(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call());
}
}
......@@ -90,7 +90,7 @@ TEST(Run_WasmInt64Const) {
WasmRunner<int64_t> r;
const int64_t kExpectedValue = 0x1122334455667788LL;
// return(kExpectedValue)
BUILD(r, WASM_I64(kExpectedValue));
BUILD(r, WASM_I64V_9(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call());
}
......@@ -101,7 +101,7 @@ TEST(Run_WasmInt64Const_many) {
WasmRunner<int64_t> r;
const int64_t kExpectedValue = (static_cast<int64_t>(*i) << 32) | cntr;
// return(kExpectedValue)
BUILD(r, WASM_I64(kExpectedValue));
BUILD(r, WASM_I64V(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call());
cntr++;
}
......@@ -192,7 +192,7 @@ void TestInt32Binop(WasmOpcode opcode, int32_t expected, int32_t a, int32_t b) {
{
WasmRunner<int32_t> r;
// K op K
BUILD(r, WASM_BINOP(opcode, WASM_I32(a), WASM_I32(b)));
BUILD(r, WASM_BINOP(opcode, WASM_I32V(a), WASM_I32V(b)));
CHECK_EQ(expected, r.Call());
}
{
......@@ -240,7 +240,7 @@ void TestInt32Unop(WasmOpcode opcode, int32_t expected, int32_t a) {
{
WasmRunner<int32_t> r;
// return op K
BUILD(r, WASM_UNOP(opcode, WASM_I32(a)));
BUILD(r, WASM_UNOP(opcode, WASM_I32V(a)));
CHECK_EQ(expected, r.Call());
}
{
......@@ -341,7 +341,7 @@ void TestInt64Binop(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) {
{
WasmRunner<int64_t> r;
// return K op K
BUILD(r, WASM_BINOP(opcode, WASM_I64(a), WASM_I64(b)));
BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b)));
CHECK_EQ(expected, r.Call());
}
{
......@@ -358,7 +358,7 @@ void TestInt64Cmp(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) {
{
WasmRunner<int32_t> r;
// return K op K
BUILD(r, WASM_BINOP(opcode, WASM_I64(a), WASM_I64(b)));
BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b)));
CHECK_EQ(expected, r.Call());
}
{
......@@ -574,7 +574,7 @@ TEST(Run_WASM_Int32DivS_byzero_const) {
TEST(Run_WASM_Int32DivU_byzero_const) {
for (uint32_t denom = 0xfffffffe; denom < 8; denom++) {
WasmRunner<uint32_t> r(MachineType::Uint32());
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32(denom)));
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
for (uint32_t val = 0xfffffff0; val < 8; val++) {
if (denom == 0) {
......@@ -657,7 +657,7 @@ TEST(Run_WASM_Int64RemU_trap) {
TEST(Run_WASM_Int64DivS_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_I64(denom)));
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));
......@@ -672,7 +672,7 @@ TEST(Run_WASM_Int64DivS_byzero_const) {
TEST(Run_WASM_Int64DivU_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_I64(denom)));
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) {
if (denom == 0) {
......@@ -1268,7 +1268,7 @@ TEST(Run_Wasm_VoidReturn1) {
// Build the calling function.
WasmRunner<int32_t> r;
r.env()->module = &module;
BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected)));
BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
......@@ -1288,7 +1288,7 @@ TEST(Run_Wasm_VoidReturn2) {
// Build the calling function.
WasmRunner<int32_t> r;
r.env()->module = &module;
BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected)));
BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected)));
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
......@@ -1649,7 +1649,7 @@ TEST(Run_Wasm_StoreMemI32_offset) {
const int32_t kWritten = 0xaabbccdd;
BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
WASM_I32(kWritten)));
WASM_I32V_5(kWritten)));
for (int i = 0; i < 2; i++) {
module.RandomizeMemory(1111);
......@@ -2304,7 +2304,7 @@ TEST(Run_TestI64WasmRunner) {
{
FOR_INT64_INPUTS(i) {
WasmRunner<int64_t> r;
BUILD(r, WASM_I64(*i));
BUILD(r, WASM_I64V(*i));
CHECK_EQ(*i, r.Call());
}
}
......@@ -2359,7 +2359,7 @@ TEST(Run_WasmCallEmpty) {
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_v(), &module);
BUILD(t, WASM_I32(kExpected));
BUILD(t, WASM_I32V_3(kExpected));
uint32_t index = t.CompileAndAdd();
// Build the calling function.
......@@ -2431,7 +2431,7 @@ TEST(Run_WasmCallVoid) {
module.RandomizeMemory();
WasmFunctionCompiler t(sigs.v_v(), &module);
BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset),
WASM_I32(kExpected)));
WASM_I32V_3(kExpected)));
uint32_t index = t.CompileAndAdd();
// Build the calling function.
......@@ -2611,7 +2611,7 @@ static void Run_WasmMixedCall_N(int start) {
ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset)));
}
ADD_CODE(code, WASM_I32(kExpected));
ADD_CODE(code, WASM_I32V_2(kExpected));
size_t end = code.size();
code.push_back(0);
r.Build(&code[0], &code[end]);
......@@ -3176,6 +3176,40 @@ TEST(Run_Wasm_F64Max_Snan) {
#endif
#if WASM_64
TEST(Run_Wasm_F32SConvertI64) {
WasmRunner<float> r(MachineType::Int64());
BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<float>(*i), r.Call(*i)); }
}
#if !defined(_WIN64)
// TODO(ahaas): Fix this failure.
TEST(Run_Wasm_F32UConvertI64) {
WasmRunner<float> r(MachineType::Uint64());
BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(static_cast<float>(*i), r.Call(*i)); }
}
#endif
TEST(Run_Wasm_F64SConvertI64) {
WasmRunner<double> r(MachineType::Int64());
BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<double>(*i), r.Call(*i)); }
}
#if !defined(_WIN64)
// TODO(ahaas): Fix this failure.
TEST(Run_Wasm_F64UConvertI64) {
WasmRunner<double> r(MachineType::Uint64());
BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(static_cast<double>(*i), r.Call(*i)); }
}
#endif
TEST(Run_Wasm_I64SConvertF32) {
WasmRunner<int64_t> r(MachineType::Float32());
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
......
......@@ -219,26 +219,23 @@ TEST_F(AstDecoderTest, Int8Const_fallthru) {
}
TEST_F(AstDecoderTest, Int32Const) {
byte code[] = {kExprI32Const, 0, 0, 0, 0};
int32_t* ptr = reinterpret_cast<int32_t*>(code + 1);
const int kInc = 4498211;
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
*ptr = i;
// TODO(binji): expand test for other sized int32s; 1 through 5 bytes.
byte code[] = {WASM_I32V(i)};
EXPECT_VERIFIES(&env_i_i, code);
}
}
TEST_F(AstDecoderTest, Int8Const_fallthru2) {
byte code[] = {kExprI8Const, 0, kExprI32Const, 1, 2, 3, 4};
byte code[] = {WASM_I8(0), WASM_I32V_4(0x1122334)};
EXPECT_VERIFIES(&env_i_i, code);
}
TEST_F(AstDecoderTest, Int64Const) {
byte code[] = {kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t* ptr = reinterpret_cast<int64_t*>(code + 1);
const int kInc = 4498211;
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
*ptr = (static_cast<int64_t>(i) << 32) | i;
byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)};
EXPECT_VERIFIES(&env_l_l, code);
}
}
......@@ -783,7 +780,7 @@ TEST_F(AstDecoderTest, TypeConversions) {
}
TEST_F(AstDecoderTest, MacrosStmt) {
VERIFY(WASM_SET_LOCAL(0, WASM_I32(87348)));
VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348)));
VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40)));
VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
......@@ -798,7 +795,8 @@ TEST_F(AstDecoderTest, MacrosBreak) {
EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BREAK(0)));
EXPECT_VERIFIES_INLINE(&env_i_i, WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO)));
EXPECT_VERIFIES_INLINE(&env_l_l, WASM_LOOP(1, WASM_BREAKV(0, WASM_I64(0))));
EXPECT_VERIFIES_INLINE(&env_l_l,
WASM_LOOP(1, WASM_BREAKV(0, WASM_I64V_1(0))));
EXPECT_VERIFIES_INLINE(&env_f_ff,
WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0))));
EXPECT_VERIFIES_INLINE(&env_d_dd,
......@@ -895,35 +893,35 @@ TEST_F(AstDecoderTest, MacrosInt64) {
#define VERIFY_L_LL(...) EXPECT_VERIFIES_INLINE(&env_l_ll, __VA_ARGS__)
#define VERIFY_I_LL(...) EXPECT_VERIFIES_INLINE(&env_i_ll, __VA_ARGS__)
VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64(12)));
VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64(13)));
VERIFY_L_LL(WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64(14)));
VERIFY_L_LL(WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64(15)));
VERIFY_L_LL(WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64(16)));
VERIFY_L_LL(WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64(17)));
VERIFY_L_LL(WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64(18)));
VERIFY_L_LL(WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64(19)));
VERIFY_L_LL(WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64(20)));
VERIFY_L_LL(WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64(21)));
VERIFY_L_LL(WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64(22)));
VERIFY_L_LL(WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64(23)));
VERIFY_L_LL(WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64(24)));
VERIFY_L_LL(WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64(24)));
VERIFY_L_LL(WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64(24)));
VERIFY_I_LL(WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64(26)));
VERIFY_I_LL(WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64(27)));
VERIFY_I_LL(WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64(28)));
VERIFY_I_LL(WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64(29)));
VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64(26)));
VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64(27)));
VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64(28)));
VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64(29)));
VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64(25)));
VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64(25)));
VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12)));
VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13)));
VERIFY_L_LL(WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14)));
VERIFY_L_LL(WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15)));
VERIFY_L_LL(WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16)));
VERIFY_L_LL(WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17)));
VERIFY_L_LL(WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18)));
VERIFY_L_LL(WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19)));
VERIFY_L_LL(WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
VERIFY_L_LL(WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21)));
VERIFY_L_LL(WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22)));
VERIFY_L_LL(WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23)));
VERIFY_L_LL(WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
VERIFY_L_LL(WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
VERIFY_L_LL(WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
VERIFY_I_LL(WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26)));
VERIFY_I_LL(WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27)));
VERIFY_I_LL(WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28)));
VERIFY_I_LL(WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29)));
VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26)));
VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27)));
VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28)));
VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29)));
VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25)));
VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25)));
}
TEST_F(AstDecoderTest, AllSimpleExpressions) {
......@@ -1196,7 +1194,7 @@ TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) {
module_env.AddFunction(sigs.i_i());
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(17)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64V_1(17)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F32(17.1)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(17.1)));
}
......@@ -1209,13 +1207,13 @@ TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) {
module_env.AddFunction(sigs.i_f());
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I8(17)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(27)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64V_1(27)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
module_env.AddFunction(sigs.i_d());
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I64(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I64V_1(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
}
......@@ -1258,17 +1256,19 @@ TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) {
byte f0 = module_env.AddFunction(sigs.i_f());
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I8(17)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64(27)));
EXPECT_FAILURE_INLINE(env,
WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64V_1(27)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I8(17)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I64(27)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
byte f1 = module_env.AddFunction(sigs.i_d());
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64(16)));
EXPECT_FAILURE_INLINE(env,
WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64V_1(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6)));
}
......@@ -1295,14 +1295,14 @@ TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) {
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f0));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I8(17)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I64(27)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I64V_1(27)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_F64(37.2)));
byte f1 = module_env.AddImport(sigs.i_d());
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f1));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I64(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I64V_1(16)));
EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_F32(17.6)));
}
......@@ -1811,8 +1811,8 @@ TEST_F(AstDecoderTest, Select) {
WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO));
EXPECT_VERIFIES_INLINE(&env_d_dd,
WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO));
EXPECT_VERIFIES_INLINE(&env_l_l,
WASM_SELECT(WASM_I64(0), WASM_I64(0), WASM_ZERO));
EXPECT_VERIFIES_INLINE(
&env_l_l, WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO));
}
TEST_F(AstDecoderTest, Select_fail1) {
......@@ -1861,7 +1861,7 @@ TEST_F(AstDecoderTest, Select_TypeCheck) {
WASM_GET_LOCAL(0)));
EXPECT_FAILURE_INLINE(
&env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0)));
&env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0)));
}
......
......@@ -428,6 +428,26 @@ TEST_F(DecoderTest, ReadU32v_extra_bits) {
}
}
TEST_F(DecoderTest, ReadI32v_extra_bits_negative) {
// OK for negative signed values to have extra ones.
int length = 0;
byte data[] = {0xff, 0xff, 0xff, 0xff, 0x7f};
decoder.Reset(data, data + sizeof(data));
decoder.checked_read_i32v(decoder.start(), 0, &length);
EXPECT_EQ(5, length);
EXPECT_TRUE(decoder.ok());
}
TEST_F(DecoderTest, ReadI32v_extra_bits_positive) {
// Not OK for positive signed values to have extra ones.
int length = 0;
byte data[] = {0x80, 0x80, 0x80, 0x80, 0x77};
decoder.Reset(data, data + sizeof(data));
decoder.checked_read_i32v(decoder.start(), 0, &length);
EXPECT_EQ(5, length);
EXPECT_FALSE(decoder.ok());
}
TEST_F(DecoderTest, ReadU32v_Bits) {
// A more exhaustive test.
const int kMaxSize = 5;
......@@ -587,8 +607,7 @@ TEST_F(DecoderTest, ReadI64v_Bits) {
int length = 1 + i / 7;
for (int j = 0; j < kMaxSize; j++) {
const uint64_t uval = bit_cast<uint64_t>(val);
data[j] = static_cast<byte>((uval >> (7 * j)) & MASK_7);
data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7);
}
for (int j = 0; j < length - 1; j++) {
data[j] |= 0x80;
......@@ -623,6 +642,26 @@ TEST_F(DecoderTest, ReadU64v_extra_bits) {
}
}
TEST_F(DecoderTest, ReadI64v_extra_bits_negative) {
// OK for negative signed values to have extra ones.
int length = 0;
byte data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f};
decoder.Reset(data, data + sizeof(data));
decoder.checked_read_i64v(decoder.start(), 0, &length);
EXPECT_EQ(10, length);
EXPECT_TRUE(decoder.ok());
}
TEST_F(DecoderTest, ReadI64v_extra_bits_positive) {
// Not OK for positive signed values to have extra ones.
int length = 0;
byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77};
decoder.Reset(data, data + sizeof(data));
decoder.checked_read_i64v(decoder.start(), 0, &length);
EXPECT_EQ(10, length);
EXPECT_FALSE(decoder.ok());
}
} // namespace wasm
} // namespace internal
} // namespace v8
......@@ -26,14 +26,14 @@ TEST_F(WasmMacroGenTest, Constants) {
EXPECT_SIZE(2, WASM_I8(122));
EXPECT_SIZE(2, WASM_I8(254));
EXPECT_SIZE(5, WASM_I32(1));
EXPECT_SIZE(5, WASM_I32(10000));
EXPECT_SIZE(5, WASM_I32(-9828934));
EXPECT_SIZE(9, WASM_I64(1));
EXPECT_SIZE(9, WASM_I64(10000));
EXPECT_SIZE(9, WASM_I64(-9828934));
EXPECT_SIZE(9, WASM_I64(0x123456789abcdef0ULL));
EXPECT_SIZE(2, WASM_I32V_1(1));
EXPECT_SIZE(4, WASM_I32V_3(10000));
EXPECT_SIZE(5, WASM_I32V_4(-9828934));
EXPECT_SIZE(2, WASM_I64V_1(1));
EXPECT_SIZE(4, WASM_I64V_3(10000));
EXPECT_SIZE(5, WASM_I64V_4(-9828934));
EXPECT_SIZE(10, WASM_I64V_9(0x123456789abcdef0ULL));
EXPECT_SIZE(5, WASM_F32(1.0f));
EXPECT_SIZE(5, WASM_F32(10000.0f));
......
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