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;
}
......
......@@ -52,18 +52,145 @@
#define WASM_ZERO kExprI8Const, 0
#define WASM_ONE kExprI8Const, 1
#define WASM_I8(val) kExprI8Const, static_cast<byte>(val)
#define WASM_I32(val) \
kExprI32Const, static_cast<byte>(val), static_cast<byte>(val >> 8), \
static_cast<byte>(val >> 16), static_cast<byte>(val >> 24)
#define WASM_I64(val) \
kExprI64Const, static_cast<byte>(static_cast<uint64_t>(val)), \
static_cast<byte>(static_cast<uint64_t>(val) >> 8), \
static_cast<byte>(static_cast<uint64_t>(val) >> 16), \
static_cast<byte>(static_cast<uint64_t>(val) >> 24), \
static_cast<byte>(static_cast<uint64_t>(val) >> 32), \
static_cast<byte>(static_cast<uint64_t>(val) >> 40), \
static_cast<byte>(static_cast<uint64_t>(val) >> 48), \
static_cast<byte>(static_cast<uint64_t>(val) >> 56)
#define I32V_MIN(length) -(1 << (6 + (7 * ((length) - 1))))
#define I32V_MAX(length) ((1 << (6 + (7 * ((length) - 1)))) - 1)
#define I64V_MIN(length) -(1LL << (6 + (7 * ((length) - 1))))
#define I64V_MAX(length) ((1LL << (6 + 7 * ((length) - 1))) - 1)
#define I32V_IN_RANGE(value, length) \
((value) >= I32V_MIN(length) && (value) <= I32V_MAX(length))
#define I64V_IN_RANGE(value, length) \
((value) >= I64V_MIN(length) && (value) <= I64V_MAX(length))
namespace v8 {
namespace internal {
namespace wasm {
inline void CheckI32v(int32_t value, int length) {
DCHECK(length >= 1 && length <= 5);
DCHECK(length == 5 || I32V_IN_RANGE(value, length));
DCHECK(length == 1 || !I32V_IN_RANGE(value, length - 1));
}
inline void CheckI64v(int64_t value, int length) {
DCHECK(length >= 1 && length <= 10);
DCHECK(length == 10 || I64V_IN_RANGE(value, length));
DCHECK(length == 1 || !I64V_IN_RANGE(value, length - 1));
}
} // namespace wasm
} // namespace internal
} // namespace v8
//------------------------------------------------------------------------------
// Int32 Const operations
//------------------------------------------------------------------------------
#define WASM_I32V(val) kExprI32Const, U32V_5(val)
#define WASM_I32V_1(val) \
static_cast<byte>(CheckI32v((val), 1), kExprI32Const), U32V_1(val)
#define WASM_I32V_2(val) \
static_cast<byte>(CheckI32v((val), 2), kExprI32Const), U32V_2(val)
#define WASM_I32V_3(val) \
static_cast<byte>(CheckI32v((val), 3), kExprI32Const), U32V_3(val)
#define WASM_I32V_4(val) \
static_cast<byte>(CheckI32v((val), 4), kExprI32Const), U32V_4(val)
#define WASM_I32V_5(val) \
static_cast<byte>(CheckI32v((val), 5), kExprI32Const), U32V_5(val)
//------------------------------------------------------------------------------
// Int64 Const operations
//------------------------------------------------------------------------------
#define WASM_I64V(val) \
kExprI64Const, \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 49) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 56) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 63) & MASK_7)
#define WASM_I64V_1(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 1), kExprI64Const), \
static_cast<byte>(static_cast<int64_t>(val) & MASK_7)
#define WASM_I64V_2(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 2), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 7) & MASK_7)
#define WASM_I64V_3(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 3), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 14) & MASK_7)
#define WASM_I64V_4(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 4), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 21) & MASK_7)
#define WASM_I64V_5(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 5), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 28) & MASK_7)
#define WASM_I64V_6(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 6), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 35) & MASK_7)
#define WASM_I64V_7(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 7), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 42) & MASK_7)
#define WASM_I64V_8(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 8), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 49) & MASK_7)
#define WASM_I64V_9(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 9), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 49) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 56) & MASK_7)
#define WASM_I64V_10(val) \
static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 10), kExprI64Const), \
static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 49) & MASK_7) | 0x80), \
static_cast<byte>(((static_cast<int64_t>(val) >> 56) & MASK_7) | 0x80), \
static_cast<byte>((static_cast<int64_t>(val) >> 63) & MASK_7)
#define WASM_F32(val) \
kExprF32Const, \
static_cast<byte>(bit_cast<int32_t>(static_cast<float>(val))), \
......@@ -303,6 +430,6 @@
static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \
static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \
static_cast<byte>((x >> 28) & 0xF)
static_cast<byte>(((x >> 28) & MASK_7))
#endif // V8_WASM_MACRO_GEN_H_
......@@ -132,7 +132,7 @@ TEST(Run_WasmI64GeU) {
TEST(Run_WasmI32ConvertI64) {
FOR_INT64_INPUTS(i) {
WasmRunner<int32_t> r;
BUILD(r, WASM_I32_CONVERT_I64(WASM_I64(*i)));
BUILD(r, WASM_I32_CONVERT_I64(WASM_I64V(*i)));
CHECK_EQ(static_cast<int32_t>(*i), r.Call());
}
}
......@@ -147,194 +147,9 @@ TEST(Run_WasmI32ConvertI64) {
// kExprI64Popcnt:
// kExprF32SConvertI64:
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)); }
}
// kExprF32UConvertI64:
TEST(Run_Wasm_F32UConvertI64) {
struct {
uint64_t input;
uint32_t expected;
} values[] = {{0x0, 0x0},
{0x1, 0x3f800000},
{0xffffffff, 0x4f800000},
{0x1b09788b, 0x4dd84bc4},
{0x4c5fce8, 0x4c98bf9d},
{0xcc0de5bf, 0x4f4c0de6},
{0x2, 0x40000000},
{0x3, 0x40400000},
{0x4, 0x40800000},
{0x5, 0x40a00000},
{0x8, 0x41000000},
{0x9, 0x41100000},
{0xffffffffffffffff, 0x5f800000},
{0xfffffffffffffffe, 0x5f800000},
{0xfffffffffffffffd, 0x5f800000},
{0x0, 0x0},
{0x100000000, 0x4f800000},
{0xffffffff00000000, 0x5f800000},
{0x1b09788b00000000, 0x5dd84bc4},
{0x4c5fce800000000, 0x5c98bf9d},
{0xcc0de5bf00000000, 0x5f4c0de6},
{0x200000000, 0x50000000},
{0x300000000, 0x50400000},
{0x400000000, 0x50800000},
{0x500000000, 0x50a00000},
{0x800000000, 0x51000000},
{0x900000000, 0x51100000},
{0x273a798e187937a3, 0x5e1ce9e6},
{0xece3af835495a16b, 0x5f6ce3b0},
{0xb668ecc11223344, 0x5d3668ed},
{0x9e, 0x431e0000},
{0x43, 0x42860000},
{0xaf73, 0x472f7300},
{0x116b, 0x458b5800},
{0x658ecc, 0x4acb1d98},
{0x2b3b4c, 0x4a2ced30},
{0x88776655, 0x4f087766},
{0x70000000, 0x4ee00000},
{0x7200000, 0x4ce40000},
{0x7fffffff, 0x4f000000},
{0x56123761, 0x4eac246f},
{0x7fffff00, 0x4efffffe},
{0x761c4761eeeeeeee, 0x5eec388f},
{0x80000000eeeeeeee, 0x5f000000},
{0x88888888dddddddd, 0x5f088889},
{0xa0000000dddddddd, 0x5f200000},
{0xddddddddaaaaaaaa, 0x5f5dddde},
{0xe0000000aaaaaaaa, 0x5f600000},
{0xeeeeeeeeeeeeeeee, 0x5f6eeeef},
{0xfffffffdeeeeeeee, 0x5f800000},
{0xf0000000dddddddd, 0x5f700000},
{0x7fffffdddddddd, 0x5b000000},
{0x3fffffaaaaaaaa, 0x5a7fffff},
{0x1fffffaaaaaaaa, 0x59fffffd},
{0xfffff, 0x497ffff0},
{0x7ffff, 0x48ffffe0},
{0x3ffff, 0x487fffc0},
{0x1ffff, 0x47ffff80},
{0xffff, 0x477fff00},
{0x7fff, 0x46fffe00},
{0x3fff, 0x467ffc00},
{0x1fff, 0x45fff800},
{0xfff, 0x457ff000},
{0x7ff, 0x44ffe000},
{0x3ff, 0x447fc000},
{0x1ff, 0x43ff8000},
{0x3fffffffffff, 0x56800000},
{0x1fffffffffff, 0x56000000},
{0xfffffffffff, 0x55800000},
{0x7ffffffffff, 0x55000000},
{0x3ffffffffff, 0x54800000},
{0x1ffffffffff, 0x54000000},
{0x8000008000000000, 0x5f000000},
{0x8000008000000001, 0x5f000001},
{0x8000000000000400, 0x5f000000},
{0x8000000000000401, 0x5f000000}};
WasmRunner<float> r(MachineType::Uint64());
BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<float>(values[i].expected), r.Call(values[i].input));
}
}
// kExprF64SConvertI64:
TEST(Run_WasmF64SConvertI64) {
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)); }
}
// kExprF64UConvertI64:
TEST(Run_Wasm_F64UConvertI64) {
struct {
uint64_t input;
uint64_t expected;
} values[] = {{0x0, 0x0},
{0x1, 0x3ff0000000000000},
{0xffffffff, 0x41efffffffe00000},
{0x1b09788b, 0x41bb09788b000000},
{0x4c5fce8, 0x419317f3a0000000},
{0xcc0de5bf, 0x41e981bcb7e00000},
{0x2, 0x4000000000000000},
{0x3, 0x4008000000000000},
{0x4, 0x4010000000000000},
{0x5, 0x4014000000000000},
{0x8, 0x4020000000000000},
{0x9, 0x4022000000000000},
{0xffffffffffffffff, 0x43f0000000000000},
{0xfffffffffffffffe, 0x43f0000000000000},
{0xfffffffffffffffd, 0x43f0000000000000},
{0x100000000, 0x41f0000000000000},
{0xffffffff00000000, 0x43efffffffe00000},
{0x1b09788b00000000, 0x43bb09788b000000},
{0x4c5fce800000000, 0x439317f3a0000000},
{0xcc0de5bf00000000, 0x43e981bcb7e00000},
{0x200000000, 0x4200000000000000},
{0x300000000, 0x4208000000000000},
{0x400000000, 0x4210000000000000},
{0x500000000, 0x4214000000000000},
{0x800000000, 0x4220000000000000},
{0x900000000, 0x4222000000000000},
{0x273a798e187937a3, 0x43c39d3cc70c3c9c},
{0xece3af835495a16b, 0x43ed9c75f06a92b4},
{0xb668ecc11223344, 0x43a6cd1d98224467},
{0x9e, 0x4063c00000000000},
{0x43, 0x4050c00000000000},
{0xaf73, 0x40e5ee6000000000},
{0x116b, 0x40b16b0000000000},
{0x658ecc, 0x415963b300000000},
{0x2b3b4c, 0x41459da600000000},
{0x88776655, 0x41e10eeccaa00000},
{0x70000000, 0x41dc000000000000},
{0x7200000, 0x419c800000000000},
{0x7fffffff, 0x41dfffffffc00000},
{0x56123761, 0x41d5848dd8400000},
{0x7fffff00, 0x41dfffffc0000000},
{0x761c4761eeeeeeee, 0x43dd8711d87bbbbc},
{0x80000000eeeeeeee, 0x43e00000001dddde},
{0x88888888dddddddd, 0x43e11111111bbbbc},
{0xa0000000dddddddd, 0x43e40000001bbbbc},
{0xddddddddaaaaaaaa, 0x43ebbbbbbbb55555},
{0xe0000000aaaaaaaa, 0x43ec000000155555},
{0xeeeeeeeeeeeeeeee, 0x43edddddddddddde},
{0xfffffffdeeeeeeee, 0x43efffffffbdddde},
{0xf0000000dddddddd, 0x43ee0000001bbbbc},
{0x7fffffdddddddd, 0x435ffffff7777777},
{0x3fffffaaaaaaaa, 0x434fffffd5555555},
{0x1fffffaaaaaaaa, 0x433fffffaaaaaaaa},
{0xfffff, 0x412ffffe00000000},
{0x7ffff, 0x411ffffc00000000},
{0x3ffff, 0x410ffff800000000},
{0x1ffff, 0x40fffff000000000},
{0xffff, 0x40efffe000000000},
{0x7fff, 0x40dfffc000000000},
{0x3fff, 0x40cfff8000000000},
{0x1fff, 0x40bfff0000000000},
{0xfff, 0x40affe0000000000},
{0x7ff, 0x409ffc0000000000},
{0x3ff, 0x408ff80000000000},
{0x1ff, 0x407ff00000000000},
{0x3fffffffffff, 0x42cfffffffffff80},
{0x1fffffffffff, 0x42bfffffffffff00},
{0xfffffffffff, 0x42affffffffffe00},
{0x7ffffffffff, 0x429ffffffffffc00},
{0x3ffffffffff, 0x428ffffffffff800},
{0x1ffffffffff, 0x427ffffffffff000},
{0x8000008000000000, 0x43e0000010000000},
{0x8000008000000001, 0x43e0000010000000},
{0x8000000000000400, 0x43e0000000000000},
{0x8000000000000401, 0x43e0000000000001}};
WasmRunner<double> r(MachineType::Uint64());
BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<double>(values[i].expected), r.Call(values[i].input));
}
}
// kExprI64SConvertF32:
// kExprI64SConvertF64:
// kExprI64UConvertF32:
......@@ -360,18 +175,20 @@ TEST(Run_WasmCallI64Parameter) {
// Build the calling function.
WasmRunner<int32_t> r;
r.env()->module = &module;
BUILD(r,
BUILD(
r,
WASM_I32_CONVERT_I64(WASM_CALL_FUNCTION(
index, WASM_I64(0xbcd12340000000b), WASM_I64(0xbcd12340000000c),
WASM_I32(0xd), WASM_I32_CONVERT_I64(WASM_I64(0xbcd12340000000e)),
WASM_I64(0xbcd12340000000f), WASM_I64(0xbcd1234000000010),
WASM_I64(0xbcd1234000000011), WASM_I64(0xbcd1234000000012),
WASM_I64(0xbcd1234000000013), WASM_I64(0xbcd1234000000014),
WASM_I64(0xbcd1234000000015), WASM_I64(0xbcd1234000000016),
WASM_I64(0xbcd1234000000017), WASM_I64(0xbcd1234000000018),
WASM_I64(0xbcd1234000000019), WASM_I64(0xbcd123400000001a),
WASM_I64(0xbcd123400000001b), WASM_I64(0xbcd123400000001c),
WASM_I64(0xbcd123400000001d))));
index, WASM_I64V_9(0xbcd12340000000b),
WASM_I64V_9(0xbcd12340000000c), WASM_I32V_1(0xd),
WASM_I32_CONVERT_I64(WASM_I64V_9(0xbcd12340000000e)),
WASM_I64V_9(0xbcd12340000000f), WASM_I64V_10(0xbcd1234000000010),
WASM_I64V_10(0xbcd1234000000011), WASM_I64V_10(0xbcd1234000000012),
WASM_I64V_10(0xbcd1234000000013), WASM_I64V_10(0xbcd1234000000014),
WASM_I64V_10(0xbcd1234000000015), WASM_I64V_10(0xbcd1234000000016),
WASM_I64V_10(0xbcd1234000000017), WASM_I64V_10(0xbcd1234000000018),
WASM_I64V_10(0xbcd1234000000019), WASM_I64V_10(0xbcd123400000001a),
WASM_I64V_10(0xbcd123400000001b), WASM_I64V_10(0xbcd123400000001c),
WASM_I64V_10(0xbcd123400000001d))));
CHECK_EQ(i + 0xb, r.Call());
}
......
......@@ -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