From f1295f6262623745bdf1d2e0776f0fc1aedc05df Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 19 Jan 2013 02:48:48 -0800 Subject: [PATCH] Don't muck with currentMIPS->r in the slowmem jit. --- Common/ABI.cpp | 26 +++++++++++++++++ Common/x64Emitter.h | 1 + Core/MIPS/x86/CompLoadStore.cpp | 50 ++++++++++++++++++--------------- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/Common/ABI.cpp b/Common/ABI.cpp index f0489e346d..4a79b64434 100644 --- a/Common/ABI.cpp +++ b/Common/ABI.cpp @@ -170,6 +170,16 @@ void XEmitter::ABI_CallFunctionACC(void *func, const Gen::OpArg &arg1, u32 param ABI_RestoreStack(3 * 4); } +void XEmitter::ABI_CallFunctionAAC(void *func, const Gen::OpArg &arg1, const Gen::OpArg &arg2, u32 param3) +{ + ABI_AlignStack(3 * 4); + PUSH(32, Imm32(param3)); + PUSH(32, arg2); + PUSH(32, arg1); + CALL(func); + ABI_RestoreStack(3 * 4); +} + void XEmitter::ABI_CallFunctionA(void *func, const Gen::OpArg &arg1) { ABI_AlignStack(1 * 4); @@ -430,6 +440,22 @@ void XEmitter::ABI_CallFunctionACC(void *func, const Gen::OpArg &arg1, u32 param } } +void XEmitter::ABI_CallFunctionAAC(void *func, const Gen::OpArg &arg1, const Gen::OpArg &arg2, u32 param3) +{ + MOV(32, R(ABI_PARAM1), arg1); + MOV(32, R(ABI_PARAM2), arg2); + MOV(64, R(ABI_PARAM3), Imm64(param3)); + u64 distance = u64(func) - (u64(code) + 5); + if (distance >= 0x0000000080000000ULL + && distance < 0xFFFFFFFF80000000ULL) { + // Far call + MOV(64, R(RAX), Imm64((u64)func)); + CALLptr(R(RAX)); + } else { + CALL(func); + } +} + void XEmitter::ABI_CallFunctionA(void *func, const Gen::OpArg &arg1) { if (!arg1.IsSimpleReg(ABI_PARAM1)) diff --git a/Common/x64Emitter.h b/Common/x64Emitter.h index e0b85e6b85..fb8ec8694b 100644 --- a/Common/x64Emitter.h +++ b/Common/x64Emitter.h @@ -657,6 +657,7 @@ public: void ABI_CallFunctionPPC(void *func, void *param1, void *param2,u32 param3); void ABI_CallFunctionAC(void *func, const Gen::OpArg &arg1, u32 param2); void ABI_CallFunctionACC(void *func, const Gen::OpArg &arg1, u32 param2, u32 param3); + void ABI_CallFunctionAAC(void *func, const Gen::OpArg &arg1, const Gen::OpArg &arg2, u32 param3); void ABI_CallFunctionA(void *func, const Gen::OpArg &arg1); // Pass a register as a paremeter. diff --git a/Core/MIPS/x86/CompLoadStore.cpp b/Core/MIPS/x86/CompLoadStore.cpp index f53338823a..1b9695612b 100644 --- a/Core/MIPS/x86/CompLoadStore.cpp +++ b/Core/MIPS/x86/CompLoadStore.cpp @@ -41,24 +41,24 @@ namespace MIPSComp { - static void ReadMemSafe32(u32 addr, int preg, u32 offset) + static u32 ReadMemSafe32(u32 addr, u32 offset) { - currentMIPS->r[preg] = Memory::Read_U32(addr + offset); + return Memory::Read_U32(addr + offset); } - static void ReadMemSafe16(u32 addr, int preg, u32 offset) + static u32 ReadMemSafe16(u32 addr, u32 offset) { - currentMIPS->r[preg] = Memory::Read_U16(addr + offset); + return Memory::Read_U16(addr + offset); } - static void WriteMemSafe32(u32 addr, int preg, u32 offset) + static void WriteMemSafe32(u32 addr, u32 value, u32 offset) { - Memory::Write_U32(currentMIPS->r[preg], addr + offset); + Memory::Write_U32(value, addr + offset); } - static void WriteMemSafe16(u32 addr, int preg, u32 offset) + static void WriteMemSafe16(u32 addr, u32 value, u32 offset) { - Memory::Write_U16(currentMIPS->r[preg], addr + offset); + Memory::Write_U16(value, addr + offset); } void Jit::Comp_ITypeMem(u32 op) @@ -92,14 +92,16 @@ namespace MIPSComp #else MOVZX(32, 16, gpr.RX(rt), MComplex(RBX, EAX, SCALE_1, offset)); #endif - gpr.UnlockAll(); - FlushAll(); FixupBranch skip = J(); SetJumpTarget(tooLow); SetJumpTarget(tooHigh); - ABI_CallFunctionACC((void *) &ReadMemSafe16, gpr.R(rs), rt, offset); + + ABI_CallFunctionAC((void *) &ReadMemSafe16, R(EAX), offset); + MOVZX(32, 16, gpr.RX(rt), R(EAX)); + SetJumpTarget(skip); + gpr.UnlockAll(); } else { @@ -139,14 +141,16 @@ namespace MIPSComp #else MOV(32, gpr.R(rt), MComplex(RBX, EAX, SCALE_1, offset)); #endif - gpr.UnlockAll(); - FlushAll(); FixupBranch skip = J(); SetJumpTarget(tooLow); SetJumpTarget(tooHigh); - ABI_CallFunctionACC((void *) &ReadMemSafe32, gpr.R(rs), rt, offset); + + ABI_CallFunctionAC((void *) &ReadMemSafe32, R(EAX), offset); + MOV(32, gpr.R(rt), R(EAX)); + SetJumpTarget(skip); + gpr.UnlockAll(); } else { @@ -177,7 +181,7 @@ namespace MIPSComp FlushAll(); gpr.Lock(rt, rs); - gpr.BindToRegister(rt, true, true); + gpr.BindToRegister(rt, true, false); MOV(32, R(EAX), gpr.R(rs)); CMP(32, R(EAX), Imm32(0x08000000)); @@ -189,14 +193,15 @@ namespace MIPSComp #else MOV(16, MComplex(RBX, EAX, SCALE_1, offset), gpr.R(rt)); #endif - gpr.UnlockAll(); - FlushAll(); FixupBranch skip = J(); SetJumpTarget(tooLow); SetJumpTarget(tooHigh); - ABI_CallFunctionACC((void *) &WriteMemSafe16, gpr.R(rs), rt, offset); + + ABI_CallFunctionAAC((void *) &WriteMemSafe16, R(EAX), gpr.R(rt), offset); + SetJumpTarget(skip); + gpr.UnlockAll(); } else { @@ -220,7 +225,7 @@ namespace MIPSComp FlushAll(); gpr.Lock(rt, rs); - gpr.BindToRegister(rt, true, true); + gpr.BindToRegister(rt, true, false); MOV(32, R(EAX), gpr.R(rs)); CMP(32, R(EAX), Imm32(0x08000000)); @@ -232,14 +237,15 @@ namespace MIPSComp #else MOV(32, MComplex(RBX, EAX, SCALE_1, offset), gpr.R(rt)); #endif - gpr.UnlockAll(); - FlushAll(); FixupBranch skip = J(); SetJumpTarget(tooLow); SetJumpTarget(tooHigh); - ABI_CallFunctionACC((void *) &WriteMemSafe32, gpr.R(rs), rt, offset); + + ABI_CallFunctionAAC((void *) &WriteMemSafe32, R(EAX), gpr.R(rt), offset); + SetJumpTarget(skip); + gpr.UnlockAll(); } else {