Commit 6031412e authored by Kanghua Yu's avatar Kanghua Yu Committed by Commit Bot

[x64] Reuse scratch register for ExternalReference

This reduces CEntryStub code size by 64 bytes, and reduces CallApiCallbackStub
by 27 bytes.

Change-Id: I46479077f61fdae6b260ca28c67df3509dee5c1a
Reviewed-on: https://chromium-review.googlesource.com/963652
Commit-Queue: Kanghua Yu <kanghua.yu@intel.com>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52005}
parent 97fc20f3
...@@ -405,16 +405,20 @@ void CEntryStub::Generate(MacroAssembler* masm) { ...@@ -405,16 +405,20 @@ void CEntryStub::Generate(MacroAssembler* masm) {
isolate()); isolate());
{ {
FrameScope scope(masm, StackFrame::MANUAL); FrameScope scope(masm, StackFrame::MANUAL);
__ movp(arg_reg_1, Immediate(0)); // argc. __ xorp(arg_reg_1, arg_reg_1); // argc.
__ movp(arg_reg_2, Immediate(0)); // argv. __ xorp(arg_reg_2, arg_reg_2); // argv.
__ Move(arg_reg_3, ExternalReference::isolate_address(isolate())); __ Move(arg_reg_3, ExternalReference::isolate_address(isolate()));
__ PrepareCallCFunction(3); __ PrepareCallCFunction(3);
__ CallCFunction(find_handler, 3); __ CallCFunction(find_handler, 3);
} }
// Retrieve the handler context, SP and FP. // Retrieve the handler context, SP and FP.
__ movp(rsi, masm->ExternalOperand(pending_handler_context_address)); __ movp(rsi, masm->ExternalOperand(pending_handler_context_address));
__ movp(rsp, masm->ExternalOperand(pending_handler_sp_address)); __ movp(rsp,
__ movp(rbp, masm->ExternalOperand(pending_handler_fp_address)); masm->ExternalOperandReuseScratchRegister(
pending_handler_sp_address, pending_handler_context_address));
__ movp(rbp,
masm->ExternalOperandReuseScratchRegister(
pending_handler_fp_address, pending_handler_context_address));
// If the handler is a JS frame, restore the context to the frame. Note that // If the handler is a JS frame, restore the context to the frame. Note that
// the context will be set to (rsi == 0) for non-JS frames. // the context will be set to (rsi == 0) for non-JS frames.
...@@ -431,7 +435,9 @@ void CEntryStub::Generate(MacroAssembler* masm) { ...@@ -431,7 +435,9 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ ResetSpeculationPoisonRegister(); __ ResetSpeculationPoisonRegister();
// Compute the handler entry address and jump to it. // Compute the handler entry address and jump to it.
__ movp(rdi, masm->ExternalOperand(pending_handler_entrypoint_address)); __ movp(rdi, masm->ExternalOperandReuseScratchRegister(
pending_handler_entrypoint_address,
pending_handler_context_address));
__ jmp(rdi); __ jmp(rdi);
} }
......
...@@ -160,6 +160,19 @@ Operand TurboAssembler::ExternalOperand(ExternalReference target, ...@@ -160,6 +160,19 @@ Operand TurboAssembler::ExternalOperand(ExternalReference target,
return Operand(scratch, 0); return Operand(scratch, 0);
} }
Operand TurboAssembler::ExternalOperandReuseScratchRegister(
ExternalReference target, ExternalReference previous, Register scratch) {
if (root_array_available_ && !serializer_enabled()) {
int64_t delta = RootRegisterDelta(target);
if (delta != kInvalidRootRegisterDelta && is_int32(delta)) {
return Operand(kRootRegister, static_cast<int32_t>(delta));
}
}
int64_t delta = target.address() - previous.address();
DCHECK(is_int32(delta));
return Operand(scratch, static_cast<int32_t>(delta));
}
int TurboAssembler::LoadAddressSize(ExternalReference source) { int TurboAssembler::LoadAddressSize(ExternalReference source) {
if (root_array_available_ && !serializer_enabled()) { if (root_array_available_ && !serializer_enabled()) {
// This calculation depends on the internals of LoadAddress. // This calculation depends on the internals of LoadAddress.
...@@ -2236,9 +2249,12 @@ void MacroAssembler::EnterExitFramePrologue(bool save_rax, ...@@ -2236,9 +2249,12 @@ void MacroAssembler::EnterExitFramePrologue(bool save_rax,
movp(r14, rax); // Backup rax in callee-save register. movp(r14, rax); // Backup rax in callee-save register.
} }
Store(ExternalReference(IsolateAddressId::kCEntryFPAddress, isolate()), rbp); ExternalReference fp_address(IsolateAddressId::kCEntryFPAddress, isolate()),
Store(ExternalReference(IsolateAddressId::kContextAddress, isolate()), rsi); context_address(IsolateAddressId::kContextAddress, isolate()),
Store(ExternalReference(IsolateAddressId::kCFunctionAddress, isolate()), rbx); function_address(IsolateAddressId::kCFunctionAddress, isolate());
movp(ExternalOperand(fp_address), rbp);
movp(ExternalOperandReuseScratchRegister(context_address, fp_address), rsi);
movp(ExternalOperandReuseScratchRegister(function_address, fp_address), rbx);
} }
...@@ -2346,7 +2362,8 @@ void MacroAssembler::LeaveExitFrameEpilogue() { ...@@ -2346,7 +2362,8 @@ void MacroAssembler::LeaveExitFrameEpilogue() {
// Clear the top frame. // Clear the top frame.
ExternalReference c_entry_fp_address(IsolateAddressId::kCEntryFPAddress, ExternalReference c_entry_fp_address(IsolateAddressId::kCEntryFPAddress,
isolate()); isolate());
Operand c_entry_fp_operand = ExternalOperand(c_entry_fp_address); Operand c_entry_fp_operand =
ExternalOperandReuseScratchRegister(c_entry_fp_address, context_address);
movp(c_entry_fp_operand, Immediate(0)); movp(c_entry_fp_operand, Immediate(0));
} }
......
...@@ -364,6 +364,9 @@ class TurboAssembler : public Assembler { ...@@ -364,6 +364,9 @@ class TurboAssembler : public Assembler {
// that is guaranteed not to be clobbered. // that is guaranteed not to be clobbered.
Operand ExternalOperand(ExternalReference reference, Operand ExternalOperand(ExternalReference reference,
Register scratch = kScratchRegister); Register scratch = kScratchRegister);
Operand ExternalOperandReuseScratchRegister(
ExternalReference target, ExternalReference previous,
Register scratch = kScratchRegister);
void Call(Operand op); void Call(Operand op);
void Call(Handle<Code> code_object, RelocInfo::Mode rmode); void Call(Handle<Code> code_object, RelocInfo::Mode rmode);
......
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