Commit 163f3d09 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Simplify interpreter {ThreadImpl::DoStackTransfer}.

R=ahaas@chromium.org
BUG=v8:9183

Change-Id: Id8fbe12e6972ba22ee3974ec5bbbcfc1d4cb7458
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1612906
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61528}
parent 6c03d6bb
...@@ -1503,14 +1503,14 @@ class ThreadImpl { ...@@ -1503,14 +1503,14 @@ class ThreadImpl {
int JumpToHandlerDelta(InterpreterCode* code, pc_t pc) { int JumpToHandlerDelta(InterpreterCode* code, pc_t pc) {
ControlTransferEntry& control_transfer_entry = code->side_table->Lookup(pc); ControlTransferEntry& control_transfer_entry = code->side_table->Lookup(pc);
DoStackTransfer(sp_ - (control_transfer_entry.sp_diff + kCatchInArity), DoStackTransfer(control_transfer_entry.sp_diff + kCatchInArity,
control_transfer_entry.target_arity); control_transfer_entry.target_arity);
return control_transfer_entry.pc_diff; return control_transfer_entry.pc_diff;
} }
int DoBreak(InterpreterCode* code, pc_t pc, size_t depth) { int DoBreak(InterpreterCode* code, pc_t pc, size_t depth) {
ControlTransferEntry& control_transfer_entry = code->side_table->Lookup(pc); ControlTransferEntry& control_transfer_entry = code->side_table->Lookup(pc);
DoStackTransfer(sp_ - control_transfer_entry.sp_diff, DoStackTransfer(control_transfer_entry.sp_diff,
control_transfer_entry.target_arity); control_transfer_entry.target_arity);
return control_transfer_entry.pc_diff; return control_transfer_entry.pc_diff;
} }
...@@ -1534,12 +1534,12 @@ class ThreadImpl { ...@@ -1534,12 +1534,12 @@ class ThreadImpl {
bool DoReturn(Decoder* decoder, InterpreterCode** code, pc_t* pc, pc_t* limit, bool DoReturn(Decoder* decoder, InterpreterCode** code, pc_t* pc, pc_t* limit,
size_t arity) { size_t arity) {
DCHECK_GT(frames_.size(), 0); DCHECK_GT(frames_.size(), 0);
StackValue* sp_dest = stack_.get() + frames_.back().sp; spdiff_t sp_diff = static_cast<spdiff_t>(StackHeight() - frames_.back().sp);
frames_.pop_back(); frames_.pop_back();
if (frames_.size() == current_activation().fp) { if (frames_.size() == current_activation().fp) {
// A return from the last frame terminates the execution. // A return from the last frame terminates the execution.
state_ = WasmInterpreter::FINISHED; state_ = WasmInterpreter::FINISHED;
DoStackTransfer(sp_dest, arity); DoStackTransfer(sp_diff, arity);
TRACE(" => finish\n"); TRACE(" => finish\n");
return false; return false;
} else { } else {
...@@ -1551,7 +1551,7 @@ class ThreadImpl { ...@@ -1551,7 +1551,7 @@ class ThreadImpl {
*limit = top->code->end - top->code->start; *limit = top->code->end - top->code->start;
TRACE(" => Return to #%zu (#%u @%zu)\n", frames_.size() - 1, TRACE(" => Return to #%zu (#%u @%zu)\n", frames_.size() - 1,
(*code)->function->func_index, *pc); (*code)->function->func_index, *pc);
DoStackTransfer(sp_dest, arity); DoStackTransfer(sp_diff, arity);
return true; return true;
} }
} }
...@@ -1582,10 +1582,10 @@ class ThreadImpl { ...@@ -1582,10 +1582,10 @@ class ThreadImpl {
Frame* top = &frames_.back(); Frame* top = &frames_.back();
// Drop everything except current parameters. // Drop everything except current parameters.
StackValue* sp_dest = stack_.get() + top->sp; spdiff_t sp_diff = static_cast<spdiff_t>(StackHeight() - top->sp);
size_t arity = target->function->sig->parameter_count(); size_t arity = target->function->sig->parameter_count();
DoStackTransfer(sp_dest, arity); DoStackTransfer(sp_diff, arity);
*limit = target->end - target->start; *limit = target->end - target->start;
decoder->Reset(target->start, target->end); decoder->Reset(target->start, target->end);
...@@ -1604,30 +1604,29 @@ class ThreadImpl { ...@@ -1604,30 +1604,29 @@ class ThreadImpl {
return true; return true;
} }
// Copies {arity} values on the top of the stack down the stack to {dest}, // Copies {arity} values on the top of the stack down the stack while also
// dropping the values in-between. // dropping {sp_diff} many stack values in total from the stack.
void DoStackTransfer(StackValue* dest, size_t arity) { void DoStackTransfer(spdiff_t sp_diff, size_t arity) {
// before: |---------------| pop_count | arity | // before: |---------------| pop_count | arity |
// ^ 0 ^ dest ^ sp_ // ^ 0 ^ dest ^ src ^ StackHeight()
// ^----< sp_diff >----^
// //
// after: |---------------| arity | // after: |---------------| arity |
// ^ 0 ^ sp_ // ^ 0 ^ StackHeight()
DCHECK_LE(dest, sp_); sp_t stack_height = StackHeight();
DCHECK_LE(dest + arity, sp_); sp_t dest = stack_height - sp_diff;
if (arity && (dest != sp_ - arity)) { sp_t src = stack_height - arity;
memmove(dest, sp_ - arity, arity * sizeof(*sp_)); DCHECK_LE(dest, stack_height);
DCHECK_LE(dest, src);
if (arity && (dest != src)) {
StackValue* stack = stack_.get();
memmove(stack + dest, stack + src, arity * sizeof(StackValue));
// Also move elements on the reference stack accordingly. // Also move elements on the reference stack accordingly.
// TODO(mstarzinger): Refactor the interface so that we don't have to reference_stack().MoveElements(
// recompute values here which are already known at the call-site. isolate_, static_cast<int>(dest), static_cast<int>(src),
int dst = static_cast<int>(StackHeight() - (sp_ - dest)); static_cast<int>(arity), UPDATE_WRITE_BARRIER);
int src = static_cast<int>(StackHeight() - arity);
int len = static_cast<int>(arity);
reference_stack().MoveElements(isolate_, dst, src, len,
UPDATE_WRITE_BARRIER);
} }
// TODO(mstarzinger): Refactor the interface so that we don't have to ResetStack(dest + arity);
// recompute values here which are already known at the call-site.
ResetStack(StackHeight() - (sp_ - dest) + arity);
} }
inline Address EffectiveAddress(uint32_t index) { inline Address EffectiveAddress(uint32_t index) {
......
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