Upgrade V8 to 5.1.281.57
Change-Id: Id981b686b4d587ac31697662eb98bb34be42ad90
diff --git a/src/wasm/wasm-macro-gen.h b/src/wasm/wasm-macro-gen.h
index dd653c1..d9199e8 100644
--- a/src/wasm/wasm-macro-gen.h
+++ b/src/wasm/wasm-macro-gen.h
@@ -7,6 +7,50 @@
#include "src/wasm/wasm-opcodes.h"
+#define U32_LE(v) \
+ static_cast<byte>(v), static_cast<byte>((v) >> 8), \
+ static_cast<byte>((v) >> 16), static_cast<byte>((v) >> 24)
+
+#define U16_LE(v) static_cast<byte>(v), static_cast<byte>((v) >> 8)
+
+#define WASM_MODULE_HEADER U32_LE(kWasmMagic), U32_LE(kWasmVersion)
+
+#define SIG_INDEX(v) U16_LE(v)
+// TODO(binji): make SIG_INDEX match this.
+#define IMPORT_SIG_INDEX(v) U32V_1(v)
+#define FUNC_INDEX(v) U32V_1(v)
+#define NO_NAME U32V_1(0)
+#define NAME_LENGTH(v) U32V_1(v)
+
+#define ZERO_ALIGNMENT 0
+#define ZERO_OFFSET 0
+
+#define BR_TARGET(v) U32_LE(v)
+
+#define MASK_7 ((1 << 7) - 1)
+#define MASK_14 ((1 << 14) - 1)
+#define MASK_21 ((1 << 21) - 1)
+#define MASK_28 ((1 << 28) - 1)
+
+#define U32V_1(x) static_cast<byte>((x)&MASK_7)
+#define U32V_2(x) \
+ static_cast<byte>(((x)&MASK_7) | 0x80), static_cast<byte>(((x) >> 7) & MASK_7)
+#define U32V_3(x) \
+ static_cast<byte>((((x)) & MASK_7) | 0x80), \
+ static_cast<byte>((((x) >> 7) & MASK_7) | 0x80), \
+ static_cast<byte>(((x) >> 14) & MASK_7)
+#define U32V_4(x) \
+ static_cast<byte>(((x)&MASK_7) | 0x80), \
+ static_cast<byte>((((x) >> 7) & MASK_7) | 0x80), \
+ static_cast<byte>((((x) >> 14) & MASK_7) | 0x80), \
+ static_cast<byte>(((x) >> 21) & MASK_7)
+#define U32V_5(x) \
+ static_cast<byte>(((x)&MASK_7) | 0x80), \
+ 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) & MASK_7))
+
// Convenience macros for building Wasm bytecode directly into a byte array.
//------------------------------------------------------------------------------
@@ -33,14 +77,8 @@
#define WASM_RETURN(...) kExprReturn, __VA_ARGS__
#define WASM_UNREACHABLE kExprUnreachable
-#define WASM_TABLESWITCH_OP(case_count, table_count, ...) \
- kExprTableSwitch, static_cast<byte>(case_count), \
- static_cast<byte>(case_count >> 8), static_cast<byte>(table_count), \
- static_cast<byte>(table_count >> 8), __VA_ARGS__
-
-#define WASM_TABLESWITCH_BODY0(key) key
-
-#define WASM_TABLESWITCH_BODY(key, ...) key, __VA_ARGS__
+#define WASM_BR_TABLE(key, count, ...) \
+ kExprBrTable, U32V_1(count), __VA_ARGS__, key
#define WASM_CASE(x) static_cast<byte>(x), static_cast<byte>(x >> 8)
#define WASM_CASE_BR(x) static_cast<byte>(x), static_cast<byte>(0x80 | (x) >> 8)
@@ -52,18 +90,222 @@
#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))
+
+#define WASM_NO_LOCALS 0
+
+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));
+}
+
+inline void CheckI64v(int64_t value, int length) {
+ DCHECK(length >= 1 && length <= 10);
+ DCHECK(length == 10 || I64V_IN_RANGE(value, length));
+}
+
+// A helper for encoding local declarations prepended to the body of a
+// function.
+class LocalDeclEncoder {
+ public:
+ // Prepend local declarations by creating a new buffer and copying data
+ // over. The new buffer must be delete[]'d by the caller.
+ void Prepend(const byte** start, const byte** end) const {
+ size_t size = (*end - *start);
+ byte* buffer = new byte[Size() + size];
+ size_t pos = Emit(buffer);
+ memcpy(buffer + pos, *start, size);
+ pos += size;
+ *start = buffer;
+ *end = buffer + pos;
+ }
+
+ size_t Emit(byte* buffer) const {
+ size_t pos = 0;
+ pos = WriteUint32v(buffer, pos, static_cast<uint32_t>(local_decls.size()));
+ for (size_t i = 0; i < local_decls.size(); i++) {
+ pos = WriteUint32v(buffer, pos, local_decls[i].first);
+ buffer[pos++] = WasmOpcodes::LocalTypeCodeFor(local_decls[i].second);
+ }
+ DCHECK_EQ(Size(), pos);
+ return pos;
+ }
+
+ // Add locals declarations to this helper. Return the index of the newly added
+ // local(s), with an optional adjustment for the parameters.
+ uint32_t AddLocals(uint32_t count, LocalType type,
+ FunctionSig* sig = nullptr) {
+ if (count == 0) {
+ return static_cast<uint32_t>((sig ? sig->parameter_count() : 0) +
+ local_decls.size());
+ }
+ size_t pos = local_decls.size();
+ if (local_decls.size() > 0 && local_decls.back().second == type) {
+ count += local_decls.back().first;
+ local_decls.pop_back();
+ }
+ local_decls.push_back(std::pair<uint32_t, LocalType>(count, type));
+ return static_cast<uint32_t>(pos + (sig ? sig->parameter_count() : 0));
+ }
+
+ size_t Size() const {
+ size_t size = SizeofUint32v(static_cast<uint32_t>(local_decls.size()));
+ for (auto p : local_decls) size += 1 + SizeofUint32v(p.first);
+ return size;
+ }
+
+ private:
+ std::vector<std::pair<uint32_t, LocalType>> local_decls;
+
+ size_t SizeofUint32v(uint32_t val) const {
+ size_t size = 1;
+ while (true) {
+ byte b = val & MASK_7;
+ if (b == val) return size;
+ size++;
+ val = val >> 7;
+ }
+ }
+
+ // TODO(titzer): lift encoding of u32v to a common place.
+ size_t WriteUint32v(byte* buffer, size_t pos, uint32_t val) const {
+ while (true) {
+ byte b = val & MASK_7;
+ if (b == val) {
+ buffer[pos++] = b;
+ break;
+ }
+ buffer[pos++] = 0x80 | b;
+ val = val >> 7;
+ }
+ return pos;
+ }
+};
+} // 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))), \
@@ -87,21 +329,19 @@
#define WASM_LOAD_MEM(type, index) \
static_cast<byte>( \
v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf(type, false)), \
- v8::internal::wasm::WasmOpcodes::LoadStoreAccessOf(false), index
+ ZERO_ALIGNMENT, ZERO_OFFSET, index
#define WASM_STORE_MEM(type, index, val) \
static_cast<byte>( \
v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf(type, true)), \
- v8::internal::wasm::WasmOpcodes::LoadStoreAccessOf(false), index, val
+ ZERO_ALIGNMENT, ZERO_OFFSET, index, val
#define WASM_LOAD_MEM_OFFSET(type, offset, index) \
static_cast<byte>( \
v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf(type, false)), \
- v8::internal::wasm::WasmOpcodes::LoadStoreAccessOf(true), \
- static_cast<byte>(offset), index
+ ZERO_ALIGNMENT, U32V_1(offset), index
#define WASM_STORE_MEM_OFFSET(type, offset, index, val) \
static_cast<byte>( \
v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf(type, true)), \
- v8::internal::wasm::WasmOpcodes::LoadStoreAccessOf(true), \
- static_cast<byte>(offset), index, val
+ ZERO_ALIGNMENT, U32V_1(offset), index, val
#define WASM_CALL_FUNCTION(index, ...) \
kExprCallFunction, static_cast<byte>(index), __VA_ARGS__
#define WASM_CALL_IMPORT(index, ...) \
@@ -112,7 +352,7 @@
#define WASM_CALL_IMPORT0(index) kExprCallImport, static_cast<byte>(index)
#define WASM_CALL_INDIRECT0(index, func) \
kExprCallIndirect, static_cast<byte>(index), func
-#define WASM_NOT(x) kExprBoolNot, x
+#define WASM_NOT(x) kExprI32Eqz, x
//------------------------------------------------------------------------------
// Constructs that are composed of multiple bytecodes.
@@ -144,6 +384,8 @@
#define WASM_I32_SHL(x, y) kExprI32Shl, x, y
#define WASM_I32_SHR(x, y) kExprI32ShrU, x, y
#define WASM_I32_SAR(x, y) kExprI32ShrS, x, y
+#define WASM_I32_ROR(x, y) kExprI32Ror, x, y
+#define WASM_I32_ROL(x, y) kExprI32Rol, x, y
#define WASM_I32_EQ(x, y) kExprI32Eq, x, y
#define WASM_I32_NE(x, y) kExprI32Ne, x, y
#define WASM_I32_LTS(x, y) kExprI32LtS, x, y
@@ -157,6 +399,7 @@
#define WASM_I32_CLZ(x) kExprI32Clz, x
#define WASM_I32_CTZ(x) kExprI32Ctz, x
#define WASM_I32_POPCNT(x) kExprI32Popcnt, x
+#define WASM_I32_EQZ(x) kExprI32Eqz, x
//------------------------------------------------------------------------------
// Int64 operations
@@ -174,6 +417,8 @@
#define WASM_I64_SHL(x, y) kExprI64Shl, x, y
#define WASM_I64_SHR(x, y) kExprI64ShrU, x, y
#define WASM_I64_SAR(x, y) kExprI64ShrS, x, y
+#define WASM_I64_ROR(x, y) kExprI64Ror, x, y
+#define WASM_I64_ROL(x, y) kExprI64Rol, x, y
#define WASM_I64_EQ(x, y) kExprI64Eq, x, y
#define WASM_I64_NE(x, y) kExprI64Ne, x, y
#define WASM_I64_LTS(x, y) kExprI64LtS, x, y
@@ -187,6 +432,7 @@
#define WASM_I64_CLZ(x) kExprI64Clz, x
#define WASM_I64_CTZ(x) kExprI64Ctz, x
#define WASM_I64_POPCNT(x) kExprI64Popcnt, x
+#define WASM_I64_EQZ(x) kExprI64Eqz, x
//------------------------------------------------------------------------------
// Float32 operations