mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-24 03:25:02 +00:00
LibJS+LibJIT: Make Assembler::native_call accept preserved_registers
This makes JS::JIT::Compiler less architecture-specific and unifies aligning the stack into a single operation, where previously we were doing it separately for preserved registers and for stack arguments.
This commit is contained in:
parent
ecbb1df01b
commit
9f5450527f
|
@ -732,11 +732,17 @@ struct Assembler {
|
|||
}
|
||||
}
|
||||
|
||||
// NOTE: It's up to the caller of this function to preserve registers as needed.
|
||||
void native_call(void* callee, Vector<Operand> const& stack_arguments = {})
|
||||
void native_call(
|
||||
void* callee,
|
||||
Vector<Operand> const& preserved_registers = {},
|
||||
Vector<Operand> const& stack_arguments = {})
|
||||
{
|
||||
for (auto const& reg : preserved_registers.in_reverse())
|
||||
push(reg);
|
||||
|
||||
// Preserve 16-byte stack alignment for non-even amount of stack-passed arguments
|
||||
if ((stack_arguments.size() % 2) == 1)
|
||||
auto needs_aligning = ((stack_arguments.size() + preserved_registers.size()) % 2) == 1;
|
||||
if (needs_aligning)
|
||||
push(Operand::Imm(0));
|
||||
for (auto const& stack_argument : stack_arguments.in_reverse())
|
||||
push(stack_argument);
|
||||
|
@ -748,8 +754,11 @@ struct Assembler {
|
|||
emit8(0xff);
|
||||
emit_modrm_slash(2, Operand::Register(Reg::RAX));
|
||||
|
||||
if (!stack_arguments.is_empty())
|
||||
add(Operand::Register(Reg::RSP), Operand::Imm(align_up_to(stack_arguments.size(), 2) * sizeof(void*)));
|
||||
if (!stack_arguments.is_empty() || needs_aligning)
|
||||
add(Operand::Register(Reg::RSP), Operand::Imm((stack_arguments.size() + (needs_aligning ? 1 : 0)) * sizeof(void*)));
|
||||
|
||||
for (auto const& reg : preserved_registers)
|
||||
pop(reg);
|
||||
}
|
||||
|
||||
void trap()
|
||||
|
|
|
@ -1917,21 +1917,9 @@ void Compiler::jump_to_exit()
|
|||
|
||||
void Compiler::native_call(void* function_address, Vector<Assembler::Operand> const& stack_arguments)
|
||||
{
|
||||
// Make sure we don't clobber the VM&.
|
||||
m_assembler.push(Assembler::Operand::Register(ARG0));
|
||||
|
||||
// Align the stack pointer.
|
||||
m_assembler.sub(Assembler::Operand::Register(STACK_POINTER), Assembler::Operand::Imm(8));
|
||||
|
||||
// NOTE: We don't preserve caller-saved registers when making a native call.
|
||||
// This means that they may have changed after we return from the call.
|
||||
m_assembler.native_call(function_address, stack_arguments);
|
||||
|
||||
// Restore the stack pointer.
|
||||
m_assembler.add(Assembler::Operand::Register(STACK_POINTER), Assembler::Operand::Imm(8));
|
||||
|
||||
// Restore our VM&.
|
||||
m_assembler.pop(Assembler::Operand::Register(ARG0));
|
||||
m_assembler.native_call(function_address, { Assembler::Operand::Register(ARG0) }, stack_arguments);
|
||||
}
|
||||
|
||||
OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_executable)
|
||||
|
|
Loading…
Reference in a new issue