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

Unified Diff: src/wasm/decoder.h

Issue 1760363003: Revert of [wasm] Update {i32,i64}.const to use signed leb128 (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/ast-decoder.h ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/decoder.h
diff --git a/src/wasm/decoder.h b/src/wasm/decoder.h
index af7d27d1340b67c9a59eef962b2d5aaf932f60c8..88af8f7297e9a6d9165138ff4fa394b30b4c0fb9 100644
--- a/src/wasm/decoder.h
+++ b/src/wasm/decoder.h
@@ -80,14 +80,13 @@
// 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, false>(base, offset, length, msg);
+ return checked_read_leb<uint32_t>(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_leb<uint32_t, true>(base, offset, length, msg);
+ uint32_t result = checked_read_u32v(base, offset, length, msg);
if (*length == 5) return bit_cast<int32_t>(result);
if (*length > 0) {
int shift = 32 - 7 * *length;
@@ -100,14 +99,13 @@
// 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, false>(base, offset, length, msg);
+ return checked_read_leb<uint64_t>(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_leb<uint64_t, true>(base, offset, length, msg);
+ uint64_t result = checked_read_u64v(base, offset, length, msg);
if (*length == 10) return bit_cast<int64_t>(result);
if (*length > 0) {
int shift = 64 - 7 * *length;
@@ -341,7 +339,7 @@
base::SmartArrayPointer<char> error_msg_;
private:
- template <typename IntType, bool is_signed>
+ template <typename IntType>
IntType checked_read_leb(const byte* base, int offset, int* length,
const char* msg) {
if (!check(base, offset, 1, msg)) {
@@ -367,21 +365,9 @@
if (ptr == end) {
// Check there are no bits set beyond the bitwidth of {IntType}.
const int kExtraBits = (1 + kMaxLength * 7) - (sizeof(IntType) * 8);
- const byte kExtraBitsMask = static_cast<byte>(0xFF << (8 - kExtraBits));
- 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) {
+ const byte kExtraBitsMask =
+ static_cast<byte>((0xFF << (8 - kExtraBits)) & 0xFF);
+ if (*length == kMaxLength && (b & kExtraBitsMask) != 0) {
error(base, ptr, "extra bits in varint");
return 0;
}
« no previous file with comments | « src/wasm/ast-decoder.h ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698