Commit f30bf402 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][liftoff] Implement table.grow

Adjust also the TurboFan implementation to match the style of other
instructions like table.copy and table.fill.


R=thibaudm@chromium.org

Bug: v8:7581
Change-Id: Icad042055fc321855d7ffba6cd2245b016dbc013
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2735636
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73218}
parent b48afd91
......@@ -13,6 +13,8 @@ extern runtime WasmTableCopy(
Context, WasmInstanceObject, Object, Object, Smi, Smi, Smi): JSAny;
extern runtime WasmTableFill(
Context, WasmInstanceObject, Smi, Smi, Object, Smi): JSAny;
extern runtime WasmTableGrow(
Context, WasmInstanceObject, Smi, Object, Smi): Smi;
extern runtime WasmFunctionTableGet(
Context, WasmInstanceObject, Smi, Smi): JSAny;
extern runtime WasmFunctionTableSet(
......@@ -134,6 +136,18 @@ builtin WasmTableFill(
}
}
builtin WasmTableGrow(table: Smi, deltaRaw: uint32, value: Object): Smi {
try {
const instance: WasmInstanceObject = LoadInstanceFromFrame();
const delta: Smi =
Convert<PositiveSmi>(deltaRaw) otherwise TableOutOfBounds;
tail runtime::WasmTableGrow(
LoadContextFromInstance(instance), instance, table, value, delta);
} label TableOutOfBounds deferred {
return -1;
}
}
builtin WasmTableGet(tableIndex: intptr, index: int32): Object {
const instance: WasmInstanceObject = LoadInstanceFromFrame();
const entryIndex: intptr = ChangeInt32ToIntPtr(index);
......
......@@ -5520,12 +5520,10 @@ Node* WasmGraphBuilder::TableCopy(uint32_t table_dst_index,
Node* WasmGraphBuilder::TableGrow(uint32_t table_index, Node* value,
Node* delta) {
Node* args[] = {
gasm_->NumberConstant(table_index), value,
BuildConvertUint32ToSmiWithSaturation(delta, FLAG_wasm_max_table_size)};
Node* result =
BuildCallToRuntime(Runtime::kWasmTableGrow, args, arraysize(args));
return BuildChangeSmiToInt32(result);
return BuildChangeSmiToInt32(gasm_->CallRuntimeStub(
wasm::WasmCode::kWasmTableGrow,
graph()->NewNode(mcgraph()->common()->NumberConstant(table_index)), delta,
value));
}
Node* WasmGraphBuilder::TableSize(uint32_t table_index) {
......
......@@ -498,14 +498,13 @@ RUNTIME_FUNCTION(Runtime_WasmTableCopy) {
RUNTIME_FUNCTION(Runtime_WasmTableGrow) {
ClearThreadInWasmScope flag_scope(isolate);
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());
auto instance =
Handle<WasmInstanceObject>(GetWasmInstanceOnStackTop(isolate), isolate);
CONVERT_UINT32_ARG_CHECKED(table_index, 0);
CONVERT_ARG_CHECKED(Object, value_raw, 1);
DCHECK_EQ(4, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0);
CONVERT_UINT32_ARG_CHECKED(table_index, 1);
CONVERT_ARG_CHECKED(Object, value_raw, 2);
// TODO(wasm): Manually box because parameters are not visited yet.
Handle<Object> value(value_raw, isolate);
CONVERT_UINT32_ARG_CHECKED(delta, 2);
CONVERT_UINT32_ARG_CHECKED(delta, 3);
Handle<WasmTableObject> table(
WasmTableObject::cast(instance->tables().get(table_index)), isolate);
......
......@@ -4391,8 +4391,36 @@ class LiftoffCompiler {
}
void TableGrow(FullDecoder* decoder, const TableIndexImmediate<validate>& imm,
const Value& value, const Value& delta, Value* result) {
unsupported(decoder, kRefTypes, "table.grow");
const Value&, const Value&, Value* result) {
LiftoffRegList pinned;
LiftoffRegister table_index_reg =
pinned.set(__ GetUnusedRegister(kGpReg, pinned));
LoadSmi(table_index_reg, imm.index);
LiftoffAssembler::VarState table_index(kPointerValueType, table_index_reg,
0);
LiftoffAssembler::VarState delta = __ cache_state()->stack_state.end()[-1];
LiftoffAssembler::VarState value = __ cache_state()->stack_state.end()[-2];
WasmCode::RuntimeStubId target = WasmCode::kWasmTableGrow;
compiler::CallDescriptor* call_descriptor =
GetBuiltinCallDescriptor<WasmTableGrowDescriptor>(compilation_zone_);
ValueKind sig_reps[] = {kSmiValueType, kSmiValueType, kI32,
kTaggedValueType};
ValueKindSig sig(1, 3, sig_reps);
__ PrepareBuiltinCall(&sig, call_descriptor, {table_index, delta, value});
__ CallRuntimeStub(target);
DefineSafepoint();
// Pop parameters from the value stack.
__ cache_state()->stack_state.pop_back(2);
RegisterDebugSideTableEntry(decoder, DebugSideTableBuilder::kDidSpill);
__ SmiUntag(kReturnRegister0);
__ PushRegister(kI32, LiftoffRegister(kReturnRegister0));
}
void TableSize(FullDecoder* decoder, const TableIndexImmediate<validate>& imm,
......
......@@ -68,6 +68,7 @@ struct WasmModule;
V(WasmTableInit) \
V(WasmTableCopy) \
V(WasmTableFill) \
V(WasmTableGrow) \
V(WasmTableGet) \
V(WasmTableSet) \
V(WasmStackGuard) \
......
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