From c5c0b36046c67438c21471c0e5d10670cc22d960 Mon Sep 17 00:00:00 2001 From: comex Date: Sun, 7 Sep 2014 14:21:16 -0400 Subject: [PATCH] Remove the inaccurately named ABI_PushAllCalleeSavedRegsAndAdjustStack (it didn't preserve FPRs!) and replace with ABI_PushRegistersAndAdjustStack. To avoid FPRs being pushed unnecessarily, I checked the uses: DSPEmitter doesn't use FPRs, and VertexLoader doesn't use anything but RAX, so I specified the register list accordingly. The regular JIT, however, does use FPRs, and as far as I can tell, it was incorrect not to save them in the outer routine. Since the dispatcher loop is only exited when pausing or stopping, this should have no noticeable performance impact. --- Source/Core/Common/x64ABI.cpp | 60 ----------------------- Source/Core/Core/DSP/DSPEmitter.cpp | 6 ++- Source/Core/Core/PowerPC/Jit64/JitAsm.cpp | 6 +-- Source/Core/VideoCommon/VertexLoader.cpp | 5 +- 4 files changed, 10 insertions(+), 67 deletions(-) diff --git a/Source/Core/Common/x64ABI.cpp b/Source/Core/Common/x64ABI.cpp index 046d90e509..707d549e76 100644 --- a/Source/Core/Common/x64ABI.cpp +++ b/Source/Core/Common/x64ABI.cpp @@ -453,63 +453,3 @@ void XEmitter::ABI_CallFunctionA(void *func, const Gen::OpArg &arg1) ABI_RestoreStack(0); } -#ifdef _WIN32 -// Win64 Specific Code - -void XEmitter::ABI_PushAllCalleeSavedRegsAndAdjustStack() -{ - //we only want to do this once - PUSH(RBP); - MOV(64, R(RBP), R(RSP)); - PUSH(RBX); - PUSH(RSI); - PUSH(RDI); - PUSH(R12); - PUSH(R13); - PUSH(R14); - PUSH(R15); - SUB(64, R(RSP), Imm8(0x28)); - //TODO: Also preserve XMM0-3? -} - -void XEmitter::ABI_PopAllCalleeSavedRegsAndAdjustStack() -{ - ADD(64, R(RSP), Imm8(0x28)); - POP(R15); - POP(R14); - POP(R13); - POP(R12); - POP(RDI); - POP(RSI); - POP(RBX); - POP(RBP); -} - -#else -// Unix64 Specific Code - -void XEmitter::ABI_PushAllCalleeSavedRegsAndAdjustStack() -{ - PUSH(RBP); - MOV(64, R(RBP), R(RSP)); - PUSH(RBX); - PUSH(R12); - PUSH(R13); - PUSH(R14); - PUSH(R15); - SUB(64, R(RSP), Imm8(8)); -} - -void XEmitter::ABI_PopAllCalleeSavedRegsAndAdjustStack() -{ - ADD(64, R(RSP), Imm8(8)); - POP(R15); - POP(R14); - POP(R13); - POP(R12); - POP(RBX); - POP(RBP); -} - -#endif // WIN32 - diff --git a/Source/Core/Core/DSP/DSPEmitter.cpp b/Source/Core/Core/DSP/DSPEmitter.cpp index a7eec8a17e..188dfcaf2c 100644 --- a/Source/Core/Core/DSP/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/DSPEmitter.cpp @@ -384,7 +384,9 @@ const u8 *DSPEmitter::CompileStub() void DSPEmitter::CompileDispatcher() { enterDispatcher = AlignCode16(); - ABI_PushAllCalleeSavedRegsAndAdjustStack(); + // We don't use floating point (high 16 bits). + u32 registers_used = ABI_ALL_CALLEE_SAVED & 0xffff; + ABI_PushRegistersAndAdjustStack(registers_used, 8); const u8 *dispatcherLoop = GetCodePtr(); @@ -419,6 +421,6 @@ void DSPEmitter::CompileDispatcher() SetJumpTarget(exceptionExit); } //MOV(32, M(&cyclesLeft), Imm32(0)); - ABI_PopAllCalleeSavedRegsAndAdjustStack(); + ABI_PopRegistersAndAdjustStack(registers_used, 8); RET(); } diff --git a/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp b/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp index 1c5b78666f..40eb726db7 100644 --- a/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp +++ b/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp @@ -16,7 +16,7 @@ using namespace Gen; void Jit64AsmRoutineManager::Generate() { enterCode = AlignCode16(); - ABI_PushAllCalleeSavedRegsAndAdjustStack(); + ABI_PushRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8); // Two statically allocated registers. MOV(64, R(RMEM), Imm64((u64)Memory::base)); @@ -39,7 +39,7 @@ void Jit64AsmRoutineManager::Generate() ABI_CallFunction(reinterpret_cast(&PowerPC::CheckBreakPoints)); TEST(32, M((void*)PowerPC::GetStatePtr()), Imm32(0xFFFFFFFF)); FixupBranch noBreakpoint = J_CC(CC_Z); - ABI_PopAllCalleeSavedRegsAndAdjustStack(); + ABI_PopRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8); RET(); SetJumpTarget(noBreakpoint); SetJumpTarget(notStepping); @@ -126,7 +126,7 @@ void Jit64AsmRoutineManager::Generate() J_CC(CC_Z, outerLoop); //Landing pad for drec space - ABI_PopAllCalleeSavedRegsAndAdjustStack(); + ABI_PopRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8); RET(); GenerateCommon(); diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index e57dc134c6..3f509e8d32 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -584,7 +584,8 @@ void VertexLoader::CompileVertexTranslator() PanicAlert("Trying to recompile a vertex translator"); m_compiledCode = GetCodePtr(); - ABI_PushRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8); + // We don't use any callee saved registers or anything but RAX. + ABI_PushRegistersAndAdjustStack(0, 8); // Start loop here const u8 *loop_start = GetCodePtr(); @@ -845,7 +846,7 @@ void VertexLoader::CompileVertexTranslator() SUB(32, MatR(RAX), Imm8(1)); J_CC(CC_NZ, loop_start); - ABI_PopRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8); + ABI_PopRegistersAndAdjustStack(0, 8); RET(); #endif }