Commit 75391be2 authored by Matthias Liedtke's avatar Matthias Liedtke Committed by V8 LUCI CQ

[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: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82824}
parent 284d3182
...@@ -2002,7 +2002,7 @@ class WasmDecoder : public Decoder { ...@@ -2002,7 +2002,7 @@ class WasmDecoder : public Decoder {
case kExprArrayGetS: case kExprArrayGetS:
case kExprArrayGetU: case kExprArrayGetU:
case kExprArraySet: case kExprArraySet:
case kExprArrayLen: { case kExprArrayLenDeprecated: {
ArrayIndexImmediate<validate> imm(decoder, pc + length); ArrayIndexImmediate<validate> imm(decoder, pc + length);
if (io) io->TypeIndex(imm); if (io) io->TypeIndex(imm);
return length + imm.length; return length + imm.length;
...@@ -2068,6 +2068,7 @@ class WasmDecoder : public Decoder { ...@@ -2068,6 +2068,7 @@ class WasmDecoder : public Decoder {
case kExprRefIsI31: case kExprRefIsI31:
case kExprExternInternalize: case kExprExternInternalize:
case kExprExternExternalize: case kExprExternExternalize:
case kExprArrayLen:
return length; return length;
case kExprStringNewWtf16: case kExprStringNewWtf16:
case kExprStringEncodeWtf16: case kExprStringEncodeWtf16:
...@@ -2264,6 +2265,7 @@ class WasmDecoder : public Decoder { ...@@ -2264,6 +2265,7 @@ class WasmDecoder : public Decoder {
case kExprI31GetS: case kExprI31GetS:
case kExprI31GetU: case kExprI31GetU:
case kExprArrayNewDefault: case kExprArrayNewDefault:
case kExprArrayLenDeprecated:
case kExprArrayLen: case kExprArrayLen:
case kExprRefTestStatic: case kExprRefTestStatic:
case kExprRefCastStatic: case kExprRefCastStatic:
...@@ -4562,6 +4564,15 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> { ...@@ -4562,6 +4564,15 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
return opcode_length + imm.length; return opcode_length + imm.length;
} }
case kExprArrayLen: { 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 NON_CONST_ONLY
// Read but ignore an immediate array type index. // Read but ignore an immediate array type index.
// TODO(7748): Remove this once we are ready to make breaking changes. // TODO(7748): Remove this once we are ready to make breaking changes.
......
...@@ -694,9 +694,10 @@ bool V8_EXPORT_PRIVATE IsJSCompatibleSignature(const FunctionSig* sig, ...@@ -694,9 +694,10 @@ bool V8_EXPORT_PRIVATE IsJSCompatibleSignature(const FunctionSig* sig,
V(ArrayGetS, 0xfb14, _, "array.get_s") \ V(ArrayGetS, 0xfb14, _, "array.get_s") \
V(ArrayGetU, 0xfb15, _, "array.get_u") \ V(ArrayGetU, 0xfb15, _, "array.get_u") \
V(ArraySet, 0xfb16, _, "array.set") \ V(ArraySet, 0xfb16, _, "array.set") \
V(ArrayLen, 0xfb17, _, "array.len") \ V(ArrayLenDeprecated, 0xfb17, _, "array.len") \
V(ArrayCopy, 0xfb18, _, \ V(ArrayCopy, 0xfb18, _, \
"array.copy") /* not standardized - V8 experimental */ \ "array.copy") /* not standardized - V8 experimental */ \
V(ArrayLen, 0xfb19, _, "array.len") \
V(ArrayNewFixed, 0xfb1a, _, "array.new_fixed") \ V(ArrayNewFixed, 0xfb1a, _, "array.new_fixed") \
V(ArrayNew, 0xfb1b, _, "array.new") \ V(ArrayNew, 0xfb1b, _, "array.new") \
V(ArrayNewDefault, 0xfb1c, _, "array.new_default") \ V(ArrayNewDefault, 0xfb1c, _, "array.new_default") \
......
...@@ -833,6 +833,12 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) { ...@@ -833,6 +833,12 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
{WASM_ARRAY_LEN(WASM_ARRAY_NEW(type_index, WASM_I32V(0), WASM_I32V(42))), {WASM_ARRAY_LEN(WASM_ARRAY_NEW(type_index, WASM_I32V(0), WASM_I32V(42))),
kExprEnd}); 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]. // Create an array of length 2, initialized to [42, 42].
const byte kAllocate = tester.DefineFunction( const byte kAllocate = tester.DefineFunction(
&sig_q_v, {}, &sig_q_v, {},
...@@ -889,6 +895,7 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) { ...@@ -889,6 +895,7 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
tester.CheckHasThrown(kGetElem, 3); tester.CheckHasThrown(kGetElem, 3);
tester.CheckHasThrown(kGetElem, -1); tester.CheckHasThrown(kGetElem, -1);
tester.CheckResult(kGetLength, 42); tester.CheckResult(kGetLength, 42);
tester.CheckResult(kGetLengthDeprecated, 42);
tester.CheckResult(kImmutable, 42); tester.CheckResult(kImmutable, 42);
tester.CheckResult(kTestFpArray, static_cast<int32_t>(result_value)); tester.CheckResult(kTestFpArray, static_cast<int32_t>(result_value));
......
...@@ -567,8 +567,7 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) { ...@@ -567,8 +567,7 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
array, index, WASM_GC_OP(kExprArrayGetS), static_cast<byte>(typeidx) array, index, WASM_GC_OP(kExprArrayGetS), static_cast<byte>(typeidx)
#define WASM_ARRAY_SET(typeidx, array, index, value) \ #define WASM_ARRAY_SET(typeidx, array, index, value) \
array, index, value, WASM_GC_OP(kExprArraySet), static_cast<byte>(typeidx) array, index, value, WASM_GC_OP(kExprArraySet), static_cast<byte>(typeidx)
#define WASM_ARRAY_LEN(array) \ #define WASM_ARRAY_LEN(array) array, WASM_GC_OP(kExprArrayLen)
array, WASM_GC_OP(kExprArrayLen), /* dummy index */ 0
#define WASM_ARRAY_COPY(dst_idx, src_idx, dst_array, dst_index, src_array, \ #define WASM_ARRAY_COPY(dst_idx, src_idx, dst_array, dst_index, src_array, \
src_index, length) \ src_index, length) \
dst_array, dst_index, src_array, src_index, length, \ dst_array, dst_index, src_array, src_index, length, \
......
...@@ -14,7 +14,7 @@ builder.addFunction("main", kSig_i_i) ...@@ -14,7 +14,7 @@ builder.addFunction("main", kSig_i_i)
.addBody([ .addBody([
kExprLocalGet, 0, kExprLocalGet, 0,
kGCPrefix, kExprArrayNewDefault, array_index, kGCPrefix, kExprArrayNewDefault, array_index,
kGCPrefix, kExprArrayLen, array_index, kGCPrefix, kExprArrayLen,
]) ])
.exportFunc(); .exportFunc();
......
...@@ -26,7 +26,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -26,7 +26,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
// length = array.length // length = array.length
kExprLocalGet, 0, kExprLocalGet, 0,
kGCPrefix, kExprArrayLen, array_index, kGCPrefix, kExprArrayLen,
kExprLocalSet, 1, kExprLocalSet, 1,
// while (true) { // while (true) {
......
...@@ -496,8 +496,9 @@ let kExprArrayGet = 0x13; ...@@ -496,8 +496,9 @@ let kExprArrayGet = 0x13;
let kExprArrayGetS = 0x14; let kExprArrayGetS = 0x14;
let kExprArrayGetU = 0x15; let kExprArrayGetU = 0x15;
let kExprArraySet = 0x16; let kExprArraySet = 0x16;
let kExprArrayLen = 0x17; let kExprArrayLenDeprecated = 0x17;
let kExprArrayCopy = 0x18; let kExprArrayCopy = 0x18;
let kExprArrayLen = 0x19;
let kExprArrayNewFixed = 0x1a; let kExprArrayNewFixed = 0x1a;
let kExprArrayNew = 0x1b; let kExprArrayNew = 0x1b;
let kExprArrayNewDefault = 0x1c; let kExprArrayNewDefault = 0x1c;
......
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