[wasm-gc] array.len: Add new opcode without type immediate

Bug: v8:7748
Change-Id: Ib5df6996583435275e9f9c8929763cb19d467d09
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3865157
Auto-Submit: Matthias Liedtke <mliedtke@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82824}
This commit is contained in:
Matthias Liedtke 2022-08-30 14:51:33 +02:00 committed by V8 LUCI CQ
parent 284d3182ab
commit 75391be247
7 changed files with 26 additions and 7 deletions

View File

@ -2002,7 +2002,7 @@ class WasmDecoder : public Decoder {
case kExprArrayGetS:
case kExprArrayGetU:
case kExprArraySet:
case kExprArrayLen: {
case kExprArrayLenDeprecated: {
ArrayIndexImmediate<validate> imm(decoder, pc + length);
if (io) io->TypeIndex(imm);
return length + imm.length;
@ -2068,6 +2068,7 @@ class WasmDecoder : public Decoder {
case kExprRefIsI31:
case kExprExternInternalize:
case kExprExternExternalize:
case kExprArrayLen:
return length;
case kExprStringNewWtf16:
case kExprStringEncodeWtf16:
@ -2264,6 +2265,7 @@ class WasmDecoder : public Decoder {
case kExprI31GetS:
case kExprI31GetU:
case kExprArrayNewDefault:
case kExprArrayLenDeprecated:
case kExprArrayLen:
case kExprRefTestStatic:
case kExprRefCastStatic:
@ -4562,6 +4564,15 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
return opcode_length + imm.length;
}
case kExprArrayLen: {
NON_CONST_ONLY
Value array_obj = Peek(0, 0, kWasmArrayRef);
Value value = CreateValue(kWasmI32);
CALL_INTERFACE_IF_OK_AND_REACHABLE(ArrayLen, array_obj, &value);
Drop(array_obj);
Push(value);
return opcode_length;
}
case kExprArrayLenDeprecated: {
NON_CONST_ONLY
// Read but ignore an immediate array type index.
// TODO(7748): Remove this once we are ready to make breaking changes.

View File

@ -694,9 +694,10 @@ bool V8_EXPORT_PRIVATE IsJSCompatibleSignature(const FunctionSig* sig,
V(ArrayGetS, 0xfb14, _, "array.get_s") \
V(ArrayGetU, 0xfb15, _, "array.get_u") \
V(ArraySet, 0xfb16, _, "array.set") \
V(ArrayLen, 0xfb17, _, "array.len") \
V(ArrayLenDeprecated, 0xfb17, _, "array.len") \
V(ArrayCopy, 0xfb18, _, \
"array.copy") /* not standardized - V8 experimental */ \
V(ArrayLen, 0xfb19, _, "array.len") \
V(ArrayNewFixed, 0xfb1a, _, "array.new_fixed") \
V(ArrayNew, 0xfb1b, _, "array.new") \
V(ArrayNewDefault, 0xfb1c, _, "array.new_default") \

View File

@ -833,6 +833,12 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
{WASM_ARRAY_LEN(WASM_ARRAY_NEW(type_index, WASM_I32V(0), WASM_I32V(42))),
kExprEnd});
const byte kGetLengthDeprecated = tester.DefineFunction(
tester.sigs.i_v(), {},
{WASM_ARRAY_NEW(type_index, WASM_I32V(0), WASM_I32V(42)),
WASM_GC_OP(kExprArrayLenDeprecated), /*dummy type immediate*/ 0,
kExprEnd});
// Create an array of length 2, initialized to [42, 42].
const byte kAllocate = tester.DefineFunction(
&sig_q_v, {},
@ -889,6 +895,7 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
tester.CheckHasThrown(kGetElem, 3);
tester.CheckHasThrown(kGetElem, -1);
tester.CheckResult(kGetLength, 42);
tester.CheckResult(kGetLengthDeprecated, 42);
tester.CheckResult(kImmutable, 42);
tester.CheckResult(kTestFpArray, static_cast<int32_t>(result_value));

View File

@ -567,8 +567,7 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
array, index, WASM_GC_OP(kExprArrayGetS), static_cast<byte>(typeidx)
#define WASM_ARRAY_SET(typeidx, array, index, value) \
array, index, value, WASM_GC_OP(kExprArraySet), static_cast<byte>(typeidx)
#define WASM_ARRAY_LEN(array) \
array, WASM_GC_OP(kExprArrayLen), /* dummy index */ 0
#define WASM_ARRAY_LEN(array) array, WASM_GC_OP(kExprArrayLen)
#define WASM_ARRAY_COPY(dst_idx, src_idx, dst_array, dst_index, src_array, \
src_index, length) \
dst_array, dst_index, src_array, src_index, length, \

View File

@ -14,7 +14,7 @@ builder.addFunction("main", kSig_i_i)
.addBody([
kExprLocalGet, 0,
kGCPrefix, kExprArrayNewDefault, array_index,
kGCPrefix, kExprArrayLen, array_index,
kGCPrefix, kExprArrayLen,
])
.exportFunc();

View File

@ -26,7 +26,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
// length = array.length
kExprLocalGet, 0,
kGCPrefix, kExprArrayLen, array_index,
kGCPrefix, kExprArrayLen,
kExprLocalSet, 1,
// while (true) {

View File

@ -496,8 +496,9 @@ let kExprArrayGet = 0x13;
let kExprArrayGetS = 0x14;
let kExprArrayGetU = 0x15;
let kExprArraySet = 0x16;
let kExprArrayLen = 0x17;
let kExprArrayLenDeprecated = 0x17;
let kExprArrayCopy = 0x18;
let kExprArrayLen = 0x19;
let kExprArrayNewFixed = 0x1a;
let kExprArrayNew = 0x1b;
let kExprArrayNewDefault = 0x1c;