Commit 727c7df0 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Extra LEB utilities to leb-helper.h

R=bradnelson@chromium.org,aseemgarg@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#35695}
parent c323d2a6
......@@ -1416,8 +1416,6 @@ source_set("v8_base") {
"src/version.h",
"src/vm-state-inl.h",
"src/vm-state.h",
"src/wasm/switch-logic.h",
"src/wasm/switch-logic.cc",
"src/wasm/asm-wasm-builder.cc",
"src/wasm/asm-wasm-builder.h",
"src/wasm/ast-decoder.cc",
......@@ -1425,8 +1423,11 @@ source_set("v8_base") {
"src/wasm/decoder.h",
"src/wasm/encoder.cc",
"src/wasm/encoder.h",
"src/wasm/leb-helper.h",
"src/wasm/module-decoder.cc",
"src/wasm/module-decoder.h",
"src/wasm/switch-logic.cc",
"src/wasm/switch-logic.h",
"src/wasm/wasm-external-refs.cc",
"src/wasm/wasm-external-refs.h",
"src/wasm/wasm-js.cc",
......
......@@ -273,10 +273,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
current_function_builder_->Emit(kExprNop);
} else {
current_function_builder_->Emit(kExprBrTable);
std::vector<uint8_t> count =
UnsignedLEB128From(node->end - node->begin + 1);
current_function_builder_->EmitCode(&count[0],
static_cast<uint32_t>(count.size()));
current_function_builder_->EmitVarInt(node->end - node->begin + 1);
for (int v = node->begin; v <= node->end; v++) {
if (case_to_block.find(v) != case_to_block.end()) {
byte break_code[] = {BR_TARGET(case_to_block.at(v))};
......@@ -1137,9 +1134,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
index = LookupOrInsertFunction(vp->var());
}
current_function_builder_->Emit(kExprCallFunction);
std::vector<uint8_t> index_arr = UnsignedLEB128From(index);
current_function_builder_->EmitCode(
&index_arr[0], static_cast<uint32_t>(index_arr.size()));
current_function_builder_->EmitVarInt(index);
break;
}
case Call::KEYED_PROPERTY_CALL: {
......
......@@ -1674,17 +1674,6 @@ std::ostream& operator<<(std::ostream& os, const Tree& tree) {
return os;
}
ReadUnsignedLEB128ErrorCode ReadUnsignedLEB128Operand(const byte* pc,
const byte* limit,
int* length,
uint32_t* result) {
Decoder decoder(pc, limit);
*result = decoder.checked_read_u32v(pc, 0, length);
if (decoder.ok()) return kNoError;
return (limit - pc) > 1 ? kInvalidLEB128 : kMissingLEB128;
}
int OpcodeLength(const byte* pc, const byte* end) {
WasmDecoder decoder(nullptr, nullptr, pc, end);
return decoder.OpcodeLength(pc);
......
......@@ -215,11 +215,6 @@ inline TreeResult BuildTFGraph(base::AccountingAllocator* allocator,
return BuildTFGraph(allocator, builder, body);
}
enum ReadUnsignedLEB128ErrorCode { kNoError, kInvalidLEB128, kMissingLEB128 };
ReadUnsignedLEB128ErrorCode ReadUnsignedLEB128Operand(const byte*, const byte*,
int*, uint32_t*);
struct AstLocalDecls {
// The size of the encoded declarations.
uint32_t decls_encoded_size; // size of encoded declarations
......
......@@ -10,6 +10,7 @@
#include "src/wasm/ast-decoder.h"
#include "src/wasm/encoder.h"
#include "src/wasm/leb-helper.h"
#include "src/wasm/wasm-macro-gen.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
......@@ -50,37 +51,18 @@ void EmitUint32(byte** b, uint32_t x) {
*b += 4;
}
void EmitVarInt(byte** b, size_t val) {
LEBHelper::write_u32v(b, static_cast<uint32_t>(val));
}
// Sections all start with a size, but it's unknown at the start.
// We generate a large varint which we then fixup later when the size is known.
//
// TODO(jfb) Not strictly necessary since sizes are calculated ahead of time.
const size_t padded_varint = 5;
void EmitVarInt(byte** b, size_t val) {
while (true) {
size_t next = val >> 7;
byte out = static_cast<byte>(val & 0x7f);
if (next) {
*((*b)++) = 0x80 | out;
val = next;
} else {
*((*b)++) = out;
break;
}
}
}
size_t SizeOfVarInt(size_t value) {
size_t size = 0;
do {
size++;
value = value >> 7;
} while (value > 0);
return size;
}
void FixupSection(byte* start, byte* end) {
// Same as EmitVarInt, but fixed-width with zeroes in the MSBs.
// Same as LEBHelper::write_u32v, but fixed-width with zeroes in the MSBs.
size_t val = end - start - padded_varint;
TRACE(" fixup %u\n", (unsigned)val);
for (size_t pos = 0; pos != padded_varint; ++pos) {
......@@ -126,6 +108,14 @@ WasmFunctionBuilder::WasmFunctionBuilder(Zone* zone)
local_indices_(zone),
name_(zone) {}
void WasmFunctionBuilder::EmitVarInt(uint32_t val) {
byte buffer[8];
byte* ptr = buffer;
LEBHelper::write_u32v(&ptr, val);
for (byte* p = buffer; p < ptr; p++) {
body_.push_back(*p);
}
}
uint16_t WasmFunctionBuilder::AddParam(LocalType type) {
return AddVar(type, true);
......@@ -193,10 +183,7 @@ void WasmFunctionBuilder::EmitWithU8U8(WasmOpcode opcode, const byte imm1,
void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode,
uint32_t immediate) {
body_.push_back(static_cast<byte>(opcode));
size_t immediate_size = SizeOfVarInt(immediate);
body_.insert(body_.end(), immediate_size, 0);
byte* p = &body_[body_.size() - immediate_size];
EmitVarInt(&p, immediate);
EmitVarInt(immediate);
}
uint32_t WasmFunctionBuilder::EmitEditableVarIntImmediate() {
......@@ -208,7 +195,8 @@ uint32_t WasmFunctionBuilder::EmitEditableVarIntImmediate() {
void WasmFunctionBuilder::EditVarIntImmediate(uint32_t offset,
const uint32_t immediate) {
uint32_t immediate_size = static_cast<uint32_t>(SizeOfVarInt(immediate));
uint32_t immediate_size =
static_cast<uint32_t>(LEBHelper::sizeof_u32v(immediate));
// In EmitEditableVarIntImmediate, we guessed that we'd only need one byte.
// If we need more, shift everything down to make room for the larger
// immediate.
......@@ -224,7 +212,7 @@ void WasmFunctionBuilder::EditVarIntImmediate(uint32_t offset,
}
DCHECK(offset + immediate_size <= body_.size());
byte* p = &body_[offset];
EmitVarInt(&p, immediate);
v8::internal::wasm::EmitVarInt(&p, immediate);
}
......@@ -252,20 +240,28 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
if (body_.size() > 0) {
// TODO(titzer): iterate over local indexes, not the bytes.
const byte* start = &body_[0];
const byte* end = start + body_.size();
size_t local_index = 0;
for (size_t i = 0; i < body_.size();) {
if (local_index < local_indices_.size() &&
i == local_indices_[local_index]) {
int length = 0;
uint32_t index;
ReadUnsignedLEB128Operand(start + i, end, &length, &index);
// Read the old index.
uint32_t index = 0;
uint8_t b = 0;
uint32_t shift = 0;
while ((b = start[i++]) >= 0x80) {
index |= (b & 0x7F) << shift;
shift += 7;
}
index |= b << shift;
// Write the new index.
uint16_t new_index = var_index[index];
const std::vector<uint8_t>& index_vec = UnsignedLEB128From(new_index);
for (size_t j = 0; j < index_vec.size(); j++) {
e->body_.push_back(index_vec.at(j));
while (new_index >= 0x80) {
e->body_.push_back(new_index | 0x80);
new_index >>= 7;
}
i += length;
e->body_.push_back(new_index);
local_index++;
} else {
e->body_.push_back(*(start + i));
......@@ -347,7 +343,8 @@ uint32_t WasmFunctionEncoder::HeaderSize() const {
if (!external_) size += 2;
if (HasName()) {
uint32_t name_size = NameSize();
size += static_cast<uint32_t>(SizeOfVarInt(name_size)) + name_size;
size +=
static_cast<uint32_t>(LEBHelper::sizeof_u32v(name_size)) + name_size;
}
return size;
}
......@@ -551,10 +548,11 @@ struct Sizes {
}
void AddSection(WasmSection::Code code, size_t other_size) {
Add(padded_varint + SizeOfVarInt(WasmSection::getNameLength(code)) +
Add(padded_varint +
LEBHelper::sizeof_u32v(WasmSection::getNameLength(code)) +
WasmSection::getNameLength(code),
0);
if (other_size) Add(SizeOfVarInt(other_size), 0);
if (other_size) Add(LEBHelper::sizeof_u32v(other_size), 0);
}
};
......@@ -579,8 +577,9 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
if (signatures_.size() > 0) {
sizes.AddSection(WasmSection::Code::Signatures, signatures_.size());
for (auto sig : signatures_) {
sizes.Add(
1 + SizeOfVarInt(sig->parameter_count()) + sig->parameter_count(), 0);
sizes.Add(1 + LEBHelper::sizeof_u32v(sig->parameter_count()) +
sig->parameter_count(),
0);
}
TRACE("Size after signatures: %u, %u\n", (unsigned)sizes.header_size,
(unsigned)sizes.body_size);
......@@ -598,7 +597,7 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
if (start_function_index_ >= 0) {
sizes.AddSection(WasmSection::Code::StartFunction, 0);
sizes.Add(SizeOfVarInt(start_function_index_), 0);
sizes.Add(LEBHelper::sizeof_u32v(start_function_index_), 0);
TRACE("Size after start: %u, %u\n", (unsigned)sizes.header_size,
(unsigned)sizes.body_size);
}
......@@ -616,7 +615,7 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
sizes.AddSection(WasmSection::Code::FunctionTable,
indirect_functions_.size());
for (auto function_index : indirect_functions_) {
sizes.Add(SizeOfVarInt(function_index), 0);
sizes.Add(LEBHelper::sizeof_u32v(function_index), 0);
}
TRACE("Size after indirect functions: %u, %u\n",
(unsigned)sizes.header_size, (unsigned)sizes.body_size);
......@@ -727,22 +726,6 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
return new (zone) WasmModuleIndex(buffer, buffer + sizes.total());
}
std::vector<uint8_t> UnsignedLEB128From(uint32_t result) {
std::vector<uint8_t> output;
uint8_t next = 0;
int shift = 0;
do {
next = static_cast<uint8_t>(result >> shift);
if (((result >> shift) & 0xFFFFFF80) != 0) {
next = next | 0x80;
}
output.push_back(next);
shift += 7;
} while ((next & 0x80) != 0);
return output;
}
} // namespace wasm
} // namespace internal
} // namespace v8
......@@ -50,6 +50,7 @@ class WasmFunctionBuilder : public ZoneObject {
uint16_t AddParam(LocalType type);
uint16_t AddLocal(LocalType type);
void ReturnType(LocalType type);
void EmitVarInt(uint32_t val);
void EmitCode(const byte* code, uint32_t code_size);
void EmitCode(const byte* code, uint32_t code_size,
const uint32_t* local_indices, uint32_t indices_size);
......@@ -150,7 +151,6 @@ class WasmModuleBuilder : public ZoneObject {
int start_function_index_;
};
std::vector<uint8_t> UnsignedLEB128From(uint32_t result);
} // namespace wasm
} // namespace internal
} // namespace v8
......
// Copyright 2016 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.
#ifndef V8_WASM_LEB_HELPER_H_
#define V8_WASM_LEB_HELPER_H_
namespace v8 {
namespace internal {
namespace wasm {
class LEBHelper {
public:
// Write a 32-bit unsigned LEB to {dest}, updating {dest} to point after
// the last uint8_t written. No safety checks.
static void write_u32v(uint8_t** dest, uint32_t val) {
while (val >= 0x80) {
*((*dest)++) = static_cast<uint8_t>(0x80 | (val & 0x7F));
val >>= 7;
}
*((*dest)++) = static_cast<uint8_t>(val & 0x7F);
}
// Write a 32-bit signed LEB to {dest}, updating {dest} to point after
// the last uint8_t written. No safety checks.
static void write_i32v(uint8_t** dest, int32_t val) {
if (val >= 0) {
while (val >= 0x40) { // prevent sign extension.
*((*dest)++) = static_cast<uint8_t>(0x80 | (val & 0x7F));
val >>= 7;
}
*((*dest)++) = static_cast<uint8_t>(val & 0xFF);
} else {
while ((val >> 6) != -1) {
*((*dest)++) = static_cast<uint8_t>(0x80 | (val & 0x7F));
val >>= 7;
}
*((*dest)++) = static_cast<uint8_t>(val & 0x7F);
}
}
// Write a 64-bit unsigned LEB to {dest}, updating {dest} to point after
// the last uint8_t written. No safety checks.
static void write_u64v(uint8_t** dest, uint64_t val) {
while (val >= 0x80) {
*((*dest)++) = static_cast<uint8_t>(0x80 | (val & 0x7F));
val >>= 7;
}
*((*dest)++) = static_cast<uint8_t>(val & 0x7F);
}
// Write a 64-bit signed LEB to {dest}, updating {dest} to point after
// the last uint8_t written. No safety checks.
static void write_i64v(uint8_t** dest, int64_t val) {
if (val >= 0) {
while (val >= 0x40) { // prevent sign extension.
*((*dest)++) = static_cast<uint8_t>(0x80 | (val & 0x7F));
val >>= 7;
}
*((*dest)++) = static_cast<uint8_t>(val & 0xFF);
} else {
while ((val >> 6) != -1) {
*((*dest)++) = static_cast<uint8_t>(0x80 | (val & 0x7F));
val >>= 7;
}
*((*dest)++) = static_cast<uint8_t>(val & 0x7F);
}
}
// TODO(titzer): move core logic for decoding LEBs from decoder.h to here.
// Compute the size of {val} if emitted as an LEB32.
static inline size_t sizeof_u32v(size_t val) {
size_t size = 0;
do {
size++;
val = val >> 7;
} while (val > 0);
return size;
}
// Compute the size of {val} if emitted as an LEB32.
static inline size_t sizeof_i32v(int32_t val) {
size_t size = 1;
if (val >= 0) {
while (val >= 0x40) { // prevent sign extension.
size++;
val >>= 7;
}
} else {
while ((val >> 6) != -1) {
size++;
val >>= 7;
}
}
return size;
}
// Compute the size of {val} if emitted as an unsigned LEB64.
static inline size_t sizeof_u64v(uint64_t val) {
size_t size = 0;
do {
size++;
val = val >> 7;
} while (val > 0);
return size;
}
// Compute the size of {val} if emitted as a signed LEB64.
static inline size_t sizeof_i64v(int64_t val) {
size_t size = 1;
if (val >= 0) {
while (val >= 0x40) { // prevent sign extension.
size++;
val >>= 7;
}
} else {
while ((val >> 6) != -1) {
size++;
val >>= 7;
}
}
return size;
}
};
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_LEB_HELPER_H_
......@@ -119,6 +119,7 @@
'wasm/ast-decoder-unittest.cc',
'wasm/decoder-unittest.cc',
'wasm/encoder-unittest.cc',
'wasm/leb-helper-unittest.cc',
'wasm/loop-assignment-analysis-unittest.cc',
'wasm/module-decoder-unittest.cc',
'wasm/switch-logic-unittest.cc',
......
......@@ -17,36 +17,7 @@ class EncoderTest : public TestWithZone {
protected:
void AddLocal(WasmFunctionBuilder* f, LocalType type) {
uint16_t index = f->AddLocal(type);
const std::vector<uint8_t>& out_index = UnsignedLEB128From(index);
std::vector<uint8_t> code;
code.push_back(kExprGetLocal);
for (size_t i = 0; i < out_index.size(); i++) {
code.push_back(out_index.at(i));
}
uint32_t local_indices[] = {1};
f->EmitCode(&code[0], static_cast<uint32_t>(code.size()), local_indices, 1);
}
void CheckReadValue(uint8_t* leb_value, uint32_t expected_result,
int expected_length,
ReadUnsignedLEB128ErrorCode expected_error_code) {
int length;
uint32_t result;
ReadUnsignedLEB128ErrorCode error_code =
ReadUnsignedLEB128Operand(leb_value, leb_value + 5, &length, &result);
CHECK_EQ(error_code, expected_error_code);
if (error_code == 0) {
CHECK_EQ(result, expected_result);
CHECK_EQ(length, expected_length);
}
}
void CheckWriteValue(uint32_t input, int length, uint8_t* vals) {
const std::vector<uint8_t> result = UnsignedLEB128From(input);
CHECK_EQ(result.size(), length);
for (int i = 0; i < length; i++) {
CHECK_EQ(result.at(i), vals[i]);
}
f->EmitGetLocal(index);
}
};
......@@ -187,32 +158,6 @@ TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate_Locals) {
}
CHECK_EQ(offset, 479);
}
TEST_F(EncoderTest, LEB_Functions) {
byte leb_value[5] = {0, 0, 0, 0, 0};
CheckReadValue(leb_value, 0, 1, kNoError);
CheckWriteValue(0, 1, leb_value);
leb_value[0] = 23;
CheckReadValue(leb_value, 23, 1, kNoError);
CheckWriteValue(23, 1, leb_value);
leb_value[0] = 0x80;
leb_value[1] = 0x01;
CheckReadValue(leb_value, 128, 2, kNoError);
CheckWriteValue(128, 2, leb_value);
leb_value[0] = 0x80;
leb_value[1] = 0x80;
leb_value[2] = 0x80;
leb_value[3] = 0x80;
leb_value[4] = 0x01;
CheckReadValue(leb_value, 0x10000000, 5, kNoError);
CheckWriteValue(0x10000000, 5, leb_value);
leb_value[0] = 0x80;
leb_value[1] = 0x80;
leb_value[2] = 0x80;
leb_value[3] = 0x80;
leb_value[4] = 0x80;
CheckReadValue(leb_value, -1, -1, kInvalidLEB128);
}
} // namespace wasm
} // namespace internal
} // namespace v8
// Copyright 2016 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/unittests/test-utils.h"
#include "src/wasm/decoder.h"
#include "src/wasm/leb-helper.h"
namespace v8 {
namespace internal {
namespace wasm {
class LEBHelperTest : public TestWithZone {};
TEST_F(LEBHelperTest, sizeof_u32v) {
EXPECT_EQ(1, LEBHelper::sizeof_u32v(0));
EXPECT_EQ(1, LEBHelper::sizeof_u32v(1));
EXPECT_EQ(1, LEBHelper::sizeof_u32v(3));
for (uint32_t i = 4; i < 128; i++) {
EXPECT_EQ(1, LEBHelper::sizeof_u32v(i));
}
for (uint32_t i = (1 << 7); i < (1 << 9); i++) {
EXPECT_EQ(2, LEBHelper::sizeof_u32v(i));
}
for (uint32_t i = (1 << 14); i < (1 << 16); i += 33) {
EXPECT_EQ(3, LEBHelper::sizeof_u32v(i));
}
for (uint32_t i = (1 << 21); i < (1 << 24); i += 33999) {
EXPECT_EQ(4, LEBHelper::sizeof_u32v(i));
}
for (uint32_t i = (1 << 28); i < (1 << 31); i += 33997779) {
EXPECT_EQ(5, LEBHelper::sizeof_u32v(i));
}
EXPECT_EQ(5, LEBHelper::sizeof_u32v(0xFFFFFFFF));
}
TEST_F(LEBHelperTest, sizeof_i32v) {
EXPECT_EQ(1, LEBHelper::sizeof_i32v(0));
EXPECT_EQ(1, LEBHelper::sizeof_i32v(1));
EXPECT_EQ(1, LEBHelper::sizeof_i32v(3));
for (int32_t i = 0; i < (1 << 6); i++) {
EXPECT_EQ(1, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = (1 << 6); i < (1 << 8); i++) {
EXPECT_EQ(2, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = (1 << 13); i < (1 << 15); i += 31) {
EXPECT_EQ(3, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = (1 << 20); i < (1 << 22); i += 31991) {
EXPECT_EQ(4, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = (1 << 27); i < (1 << 29); i += 3199893) {
EXPECT_EQ(5, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = -(1 << 6); i <= 0; i++) {
EXPECT_EQ(1, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = -(1 << 13); i < -(1 << 6); i++) {
EXPECT_EQ(2, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = -(1 << 20); i < -(1 << 18); i += 11) {
EXPECT_EQ(3, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = -(1 << 27); i < -(1 << 25); i += 11999) {
EXPECT_EQ(4, LEBHelper::sizeof_i32v(i));
}
for (int32_t i = -(1 << 30); i < -(1 << 28); i += 1199999) {
EXPECT_EQ(5, LEBHelper::sizeof_i32v(i));
}
}
#define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \
static void CheckEncodeDecode_##name(ctype val) { \
static const int kSize = 16; \
static byte buffer[kSize]; \
byte *ptr = buffer; \
LEBHelper::write_##name(&ptr, val); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), \
static_cast<size_t>(ptr - buffer)); \
Decoder decoder(buffer, buffer + kSize); \
int length = 0; \
ctype result = decoder.checked_read_##name(buffer, 0, &length); \
EXPECT_EQ(val, result); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \
}
DECLARE_ENCODE_DECODE_CHECKER(int32_t, i32v)
DECLARE_ENCODE_DECODE_CHECKER(uint32_t, u32v)
DECLARE_ENCODE_DECODE_CHECKER(int64_t, i64v)
DECLARE_ENCODE_DECODE_CHECKER(uint64_t, u64v)
TEST_F(LEBHelperTest, WriteAndDecode_u32v) {
CheckEncodeDecode_u32v(0);
CheckEncodeDecode_u32v(1);
CheckEncodeDecode_u32v(5);
CheckEncodeDecode_u32v(99);
CheckEncodeDecode_u32v(298);
CheckEncodeDecode_u32v(87348723);
CheckEncodeDecode_u32v(77777);
for (uint32_t val = 0x3a; val != 0; val = val << 1) {
CheckEncodeDecode_u32v(val);
}
}
TEST_F(LEBHelperTest, WriteAndDecode_i32v) {
CheckEncodeDecode_i32v(0);
CheckEncodeDecode_i32v(1);
CheckEncodeDecode_i32v(5);
CheckEncodeDecode_i32v(99);
CheckEncodeDecode_i32v(298);
CheckEncodeDecode_i32v(87348723);
CheckEncodeDecode_i32v(77777);
CheckEncodeDecode_i32v(-2);
CheckEncodeDecode_i32v(-4);
CheckEncodeDecode_i32v(-59);
CheckEncodeDecode_i32v(-288);
CheckEncodeDecode_i32v(-12608);
CheckEncodeDecode_i32v(-87328723);
CheckEncodeDecode_i32v(-77377);
for (uint32_t val = 0x3a; val != 0; val = val << 1) {
CheckEncodeDecode_i32v(bit_cast<int32_t>(val));
}
for (uint32_t val = 0xFFFFFF3B; val != 0; val = val << 1) {
CheckEncodeDecode_i32v(bit_cast<int32_t>(val));
}
}
TEST_F(LEBHelperTest, WriteAndDecode_u64v) {
CheckEncodeDecode_u64v(0);
CheckEncodeDecode_u64v(1);
CheckEncodeDecode_u64v(5);
CheckEncodeDecode_u64v(99);
CheckEncodeDecode_u64v(298);
CheckEncodeDecode_u64v(87348723);
CheckEncodeDecode_u64v(77777);
for (uint64_t val = 0x3a; val != 0; val = val << 1) {
CheckEncodeDecode_u64v(val);
}
}
TEST_F(LEBHelperTest, WriteAndDecode_i64v) {
CheckEncodeDecode_i64v(0);
CheckEncodeDecode_i64v(1);
CheckEncodeDecode_i64v(5);
CheckEncodeDecode_i64v(99);
CheckEncodeDecode_i64v(298);
CheckEncodeDecode_i64v(87348723);
CheckEncodeDecode_i64v(77777);
CheckEncodeDecode_i64v(-2);
CheckEncodeDecode_i64v(-4);
CheckEncodeDecode_i64v(-59);
CheckEncodeDecode_i64v(-288);
CheckEncodeDecode_i64v(-87648723);
CheckEncodeDecode_i64v(-77377);
for (uint64_t val = 0x3a; val != 0; val = val << 1) {
CheckEncodeDecode_i64v(bit_cast<int64_t>(val));
}
for (uint64_t val = 0xFFFFFFFFFFFFFF3B; val != 0; val = val << 1) {
CheckEncodeDecode_i64v(bit_cast<int64_t>(val));
}
}
} // namespace wasm
} // namespace internal
} // namespace v8
......@@ -1133,6 +1133,7 @@
'../../src/wasm/encoder.h',
'../../src/wasm/wasm-external-refs.cc',
'../../src/wasm/wasm-external-refs.h',
'../../src/wasm/leb-helper.h',
'../../src/wasm/module-decoder.cc',
'../../src/wasm/module-decoder.h',
'../../src/wasm/wasm-js.cc',
......
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