Commit 6d34271b authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Base {CallIndirectImmediate} on {TableIndexImmediate}.

This makes sure that all encodings of a table index are based upon a
single implementation in the {TableIndexImmediate} class. It also fixes
one encoding that wasn't extended to support u32v yet.

R=ahaas@chromium.org
TEST=unittests/WasmOpcodeLengthTest.VariableLength

Change-Id: If24b6dc5e303d2d9e1e91cb2640c7c13eac40198
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1768375Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63408}
parent 35068b02
......@@ -338,35 +338,6 @@ struct BranchOnExceptionImmediate {
}
};
template <Decoder::ValidateFlag validate>
struct CallIndirectImmediate {
uint32_t table_index;
uint32_t sig_index;
FunctionSig* sig = nullptr;
uint32_t length = 0;
inline CallIndirectImmediate(const WasmFeatures enabled, Decoder* decoder,
const byte* pc) {
uint32_t len = 0;
sig_index = decoder->read_u32v<validate>(pc + 1, &len, "signature index");
table_index = decoder->read_u8<validate>(pc + 1 + len, "table index");
if (!VALIDATE(table_index == 0 || enabled.anyref)) {
decoder->errorf(pc + 1 + len, "expected table index 0, found %u",
table_index);
}
length = 1 + len;
}
};
template <Decoder::ValidateFlag validate>
struct CallFunctionImmediate {
uint32_t index;
FunctionSig* sig = nullptr;
uint32_t length;
inline CallFunctionImmediate(Decoder* decoder, const byte* pc) {
index = decoder->read_u32v<validate>(pc + 1, &length, "function index");
}
};
template <Decoder::ValidateFlag validate>
struct FunctionIndexImmediate {
uint32_t index = 0;
......@@ -399,6 +370,36 @@ struct TableIndexImmediate {
}
};
template <Decoder::ValidateFlag validate>
struct CallIndirectImmediate {
uint32_t table_index;
uint32_t sig_index;
FunctionSig* sig = nullptr;
uint32_t length = 0;
inline CallIndirectImmediate(const WasmFeatures enabled, Decoder* decoder,
const byte* pc) {
uint32_t len = 0;
sig_index = decoder->read_u32v<validate>(pc + 1, &len, "signature index");
TableIndexImmediate<validate> table(decoder, pc + len);
if (!VALIDATE((table.index == 0 && table.length == 1) || enabled.anyref)) {
decoder->errorf(pc + 1 + len, "expected table index 0, found %u",
table.index);
}
table_index = table.index;
length = len + table.length;
}
};
template <Decoder::ValidateFlag validate>
struct CallFunctionImmediate {
uint32_t index;
FunctionSig* sig = nullptr;
uint32_t length;
inline CallFunctionImmediate(Decoder* decoder, const byte* pc) {
index = decoder->read_u32v<validate>(pc + 1, &length, "function index");
}
};
template <Decoder::ValidateFlag validate>
struct BranchTableImmediate {
uint32_t table_count;
......
......@@ -3525,6 +3525,24 @@ TEST_F(WasmOpcodeLengthTest, VariableLength) {
ExpectLength(4, kExprRefFunc, U32V_3(44));
ExpectLength(5, kExprRefFunc, U32V_4(66));
ExpectLength(6, kExprRefFunc, U32V_5(77));
ExpectLength(2, kExprTableGet, U32V_1(1));
ExpectLength(3, kExprTableGet, U32V_2(33));
ExpectLength(4, kExprTableGet, U32V_3(44));
ExpectLength(5, kExprTableGet, U32V_4(66));
ExpectLength(6, kExprTableGet, U32V_5(77));
ExpectLength(2, kExprTableSet, U32V_1(1));
ExpectLength(3, kExprTableSet, U32V_2(33));
ExpectLength(4, kExprTableSet, U32V_3(44));
ExpectLength(5, kExprTableSet, U32V_4(66));
ExpectLength(6, kExprTableSet, U32V_5(77));
ExpectLength(3, kExprCallIndirect, U32V_1(1), U32V_1(1));
ExpectLength(4, kExprCallIndirect, U32V_1(1), U32V_2(33));
ExpectLength(5, kExprCallIndirect, U32V_1(1), U32V_3(44));
ExpectLength(6, kExprCallIndirect, U32V_1(1), U32V_4(66));
ExpectLength(7, kExprCallIndirect, U32V_1(1), U32V_5(77));
}
TEST_F(WasmOpcodeLengthTest, LoadsAndStores) {
......
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