| Index: src/wasm/decoder.h
|
| diff --git a/src/wasm/decoder.h b/src/wasm/decoder.h
|
| index cc8024c82fe050061decb70dff226107bfaad0e3..9136fa511d4e3bb562e50612dc944c444d74a3ca 100644
|
| --- a/src/wasm/decoder.h
|
| +++ b/src/wasm/decoder.h
|
| @@ -24,6 +24,12 @@
|
| } while (false)
|
| #else
|
| #define TRACE(...)
|
| +#endif
|
| +
|
| +#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM)
|
| +#define UNALIGNED_ACCESS_OK 1
|
| +#else
|
| +#define UNALIGNED_ACCESS_OK 0
|
| #endif
|
|
|
| // A helper utility to decode bytes, integers, fields, varints, etc, from
|
| @@ -116,19 +122,47 @@
|
| // Reads a single 16-bit unsigned integer (little endian).
|
| inline uint16_t read_u16(const byte* ptr) {
|
| DCHECK(ptr >= start_ && (ptr + 2) <= end_);
|
| - return ReadLittleEndianValue<uint16_t>(ptr);
|
| +#if V8_TARGET_LITTLE_ENDIAN && UNALIGNED_ACCESS_OK
|
| + return *reinterpret_cast<const uint16_t*>(ptr);
|
| +#else
|
| + uint16_t b0 = ptr[0];
|
| + uint16_t b1 = ptr[1];
|
| + return (b1 << 8) | b0;
|
| +#endif
|
| }
|
|
|
| // Reads a single 32-bit unsigned integer (little endian).
|
| inline uint32_t read_u32(const byte* ptr) {
|
| DCHECK(ptr >= start_ && (ptr + 4) <= end_);
|
| - return ReadLittleEndianValue<uint32_t>(ptr);
|
| +#if V8_TARGET_LITTLE_ENDIAN && UNALIGNED_ACCESS_OK
|
| + return *reinterpret_cast<const uint32_t*>(ptr);
|
| +#else
|
| + uint32_t b0 = ptr[0];
|
| + uint32_t b1 = ptr[1];
|
| + uint32_t b2 = ptr[2];
|
| + uint32_t b3 = ptr[3];
|
| + return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
|
| +#endif
|
| }
|
|
|
| // Reads a single 64-bit unsigned integer (little endian).
|
| inline uint64_t read_u64(const byte* ptr) {
|
| DCHECK(ptr >= start_ && (ptr + 8) <= end_);
|
| - return ReadLittleEndianValue<uint64_t>(ptr);
|
| +#if V8_TARGET_LITTLE_ENDIAN && UNALIGNED_ACCESS_OK
|
| + return *reinterpret_cast<const uint64_t*>(ptr);
|
| +#else
|
| + uint32_t b0 = ptr[0];
|
| + uint32_t b1 = ptr[1];
|
| + uint32_t b2 = ptr[2];
|
| + uint32_t b3 = ptr[3];
|
| + uint32_t low = (b3 << 24) | (b2 << 16) | (b1 << 8) | b0;
|
| + uint32_t b4 = ptr[4];
|
| + uint32_t b5 = ptr[5];
|
| + uint32_t b6 = ptr[6];
|
| + uint32_t b7 = ptr[7];
|
| + uint64_t high = (b7 << 24) | (b6 << 16) | (b5 << 8) | b4;
|
| + return (high << 32) | low;
|
| +#endif
|
| }
|
|
|
| // Reads a 8-bit unsigned integer (byte) and advances {pc_}.
|
|
|