Commit 7631358e authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Reuse information from wasm-linkage.h

For generating the WasmCompileLazy builtin, we need to know the list of
parameter registers in wasm. Instead of duplicating this, just use the
existing array from wasm-linkage.h.

R=titzer@chromium.org

Change-Id: Ib552af7b6a3defbc9c8b48390244bf943306a4b7
Reviewed-on: https://chromium-review.googlesource.com/1057310Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53182}
parent 8ae28f32
......@@ -8,6 +8,8 @@
#ifndef V8_BASE_ADAPTERS_H_
#define V8_BASE_ADAPTERS_H_
#include <iterator>
#include "src/base/macros.h"
namespace v8 {
......@@ -17,13 +19,15 @@ namespace base {
template <typename T>
class ReversedAdapter {
public:
typedef decltype(static_cast<T*>(nullptr)->rbegin()) Iterator;
using Iterator =
std::reverse_iterator<decltype(std::begin(std::declval<T>()))>;
explicit ReversedAdapter(T& t) : t_(t) {}
ReversedAdapter(const ReversedAdapter& ra) : t_(ra.t_) {}
ReversedAdapter(const ReversedAdapter& ra) = default;
Iterator begin() const { return t_.rbegin(); }
Iterator end() const { return t_.rend(); }
// TODO(clemensh): Use std::rbegin/std::rend once we have C++14 support.
Iterator begin() const { return Iterator(std::end(t_)); }
Iterator end() const { return Iterator(std::begin(t_)); }
private:
T& t_;
......
......@@ -4,12 +4,14 @@
#if V8_TARGET_ARCH_IA32
#include "src/base/adapters.h"
#include "src/code-factory.h"
#include "src/debug/debug.h"
#include "src/deoptimizer.h"
#include "src/frame-constants.h"
#include "src/frames.h"
#include "src/objects-inl.h"
#include "src/wasm/wasm-linkage.h"
namespace v8 {
namespace internal {
......@@ -2770,22 +2772,22 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
// Save all parameter registers (see wasm-linkage.cc). They might be
// overwritten in the runtime call below. We don't have any callee-saved
// registers in wasm, so no need to store anything else.
constexpr Register gp_regs[]{eax, ebx, ecx, edx};
constexpr XMMRegister xmm_regs[]{xmm1, xmm2, xmm3, xmm4, xmm5, xmm6};
for (auto reg : gp_regs) {
for (Register reg : wasm::kGpParamRegisters) {
if (reg == kWasmInstanceRegister) continue;
__ Push(reg);
}
__ sub(esp, Immediate(16 * arraysize(xmm_regs)));
for (int i = 0, e = arraysize(xmm_regs); i < e; ++i) {
__ movdqu(Operand(esp, 16 * i), xmm_regs[i]);
__ sub(esp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
int offset = 0;
for (DoubleRegister reg : wasm::kFpParamRegisters) {
__ movdqu(Operand(esp, offset), reg);
offset += 16;
}
// Pass the WASM instance as an explicit argument to WasmCompileLazy.
__ Push(kWasmInstanceRegister);
// Initialize the JavaScript context with 0. CEntry will use it to
// set the current context on the isolate.
__ Move(esi, Smi::kZero);
__ Move(kContextRegister, Smi::kZero);
__ CallRuntime(Runtime::kWasmCompileLazy);
// The entrypoint address is the first return value.
__ mov(edi, kReturnRegister0);
......@@ -2793,12 +2795,15 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ mov(kWasmInstanceRegister, kReturnRegister1);
// Restore registers.
for (int i = arraysize(xmm_regs) - 1; i >= 0; --i) {
__ movdqu(xmm_regs[i], Operand(esp, 16 * i));
for (DoubleRegister reg : base::Reversed(wasm::kFpParamRegisters)) {
offset -= 16;
__ movdqu(reg, Operand(esp, offset));
}
__ add(esp, Immediate(16 * arraysize(xmm_regs)));
for (int i = arraysize(gp_regs) - 1; i >= 0; --i) {
__ Pop(gp_regs[i]);
DCHECK_EQ(0, offset);
__ add(esp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
for (Register reg : base::Reversed(wasm::kGpParamRegisters)) {
if (reg == kWasmInstanceRegister) continue;
__ Pop(reg);
}
}
// Finally, jump to the entrypoint.
......
......@@ -4,6 +4,7 @@
#if V8_TARGET_ARCH_X64
#include "src/base/adapters.h"
#include "src/code-factory.h"
#include "src/counters.h"
#include "src/deoptimizer.h"
......@@ -11,6 +12,7 @@
#include "src/frames.h"
#include "src/objects-inl.h"
#include "src/objects/debug-objects.h"
#include "src/wasm/wasm-linkage.h"
namespace v8 {
namespace internal {
......@@ -2715,22 +2717,22 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
// Save all parameter registers (see wasm-linkage.cc). They might be
// overwritten in the runtime call below. We don't have any callee-saved
// registers in wasm, so no need to store anything else.
constexpr Register gp_regs[]{rax, rbx, rcx, rdx, rdi};
constexpr XMMRegister xmm_regs[]{xmm1, xmm2, xmm3, xmm4, xmm5, xmm6};
for (auto reg : gp_regs) {
for (Register reg : wasm::kGpParamRegisters) {
if (reg == kWasmInstanceRegister) continue;
__ Push(reg);
}
__ subp(rsp, Immediate(16 * arraysize(xmm_regs)));
for (int i = 0, e = arraysize(xmm_regs); i < e; ++i) {
__ movdqu(Operand(rsp, 16 * i), xmm_regs[i]);
__ subp(rsp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
int offset = 0;
for (DoubleRegister reg : wasm::kFpParamRegisters) {
__ movdqu(Operand(rsp, offset), reg);
offset += 16;
}
// Pass the WASM instance as an explicit argument to WasmCompileLazy.
__ Push(kWasmInstanceRegister);
// Initialize the JavaScript context with 0. CEntry will use it to
// set the current context on the isolate.
__ Move(rsi, Smi::kZero);
__ Move(kContextRegister, Smi::kZero);
__ CallRuntime(Runtime::kWasmCompileLazy);
// The entrypoint address is the first return value.
__ movq(r11, kReturnRegister0);
......@@ -2738,12 +2740,15 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ movq(kWasmInstanceRegister, kReturnRegister1);
// Restore registers.
for (int i = arraysize(xmm_regs) - 1; i >= 0; --i) {
__ movdqu(xmm_regs[i], Operand(rsp, 16 * i));
for (DoubleRegister reg : base::Reversed(wasm::kFpParamRegisters)) {
offset -= 16;
__ movdqu(reg, Operand(rsp, offset));
}
__ addp(rsp, Immediate(16 * arraysize(xmm_regs)));
for (int i = arraysize(gp_regs) - 1; i >= 0; --i) {
__ Pop(gp_regs[i]);
DCHECK_EQ(0, offset);
__ addp(rsp, Immediate(16 * arraysize(wasm::kFpParamRegisters)));
for (Register reg : base::Reversed(wasm::kGpParamRegisters)) {
if (reg == kWasmInstanceRegister) continue;
__ Pop(reg);
}
}
// Finally, jump to the entrypoint.
......
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