From dd7ab4812b7b315c762a0224bbd12187168f3cff Mon Sep 17 00:00:00 2001 From: comex Date: Thu, 23 Apr 2015 00:41:36 -0400 Subject: [PATCH] On x86, disabling fastmem isn't enough actually. Without fastmem, the JIT code still does an inline check for RAM addresses. With watchpoints we have to disable that too. (Hardware watchpoints would avoid all the slow, but be complicated to implement and limited in number - I doubt most people debugging games care much if they run slower.) With this change and watchpoints enabled, Melee runs at no more than 40% speed, despite running at full speed without them. Oh well. Better works slowly than doesn't bloody work. Incidentally, I'm getting an unrelated crash in PowerPC::HostIsRAMAddress when shutting down a game. This code sucks. --- .../Core/Core/PowerPC/JitCommon/JitBase.cpp | 2 ++ Source/Core/Core/PowerPC/JitCommon/JitBase.h | 1 + .../Core/Core/PowerPC/JitCommon/Jit_Util.cpp | 30 +++++++++++-------- Source/Core/Core/PowerPC/MMU.cpp | 12 ++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp index a2077eaee9..d03df55846 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp @@ -90,4 +90,6 @@ void JitBase::UpdateMemoryOptions() !any_watchpoints; jo.memcheck = SConfig::GetInstance().m_LocalCoreStartupParameter.bMMU || any_watchpoints; + jo.alwaysUseMemFuncs = any_watchpoints; + } diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.h b/Source/Core/Core/PowerPC/JitCommon/JitBase.h index a207637482..15b89156b6 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.h @@ -63,6 +63,7 @@ protected: bool accurateSinglePrecision; bool fastmem; bool memcheck; + bool alwaysUseMemFuncs; }; struct JitState { diff --git a/Source/Core/Core/PowerPC/JitCommon/Jit_Util.cpp b/Source/Core/Core/PowerPC/JitCommon/Jit_Util.cpp index e2f9d4555c..0ed3ddbb3a 100644 --- a/Source/Core/Core/PowerPC/JitCommon/Jit_Util.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/Jit_Util.cpp @@ -349,14 +349,17 @@ void EmuCodeBlock::SafeLoadToReg(X64Reg reg_value, const Gen::OpArg & opAddress, LEA(32, RSCRATCH, MDisp(opAddress.GetSimpleReg(), offset)); } - FixupBranch slow, exit; - slow = CheckIfSafeAddress(R(reg_value), reg_addr, registersInUse, mem_mask); - UnsafeLoadToReg(reg_value, R(reg_addr), accessSize, 0, signExtend); - if (farcode.Enabled()) - SwitchToFarCode(); - else - exit = J(true); - SetJumpTarget(slow); + FixupBranch exit; + if (!jit->jo.alwaysUseMemFuncs) + { + FixupBranch slow = CheckIfSafeAddress(R(reg_value), reg_addr, registersInUse, mem_mask); + UnsafeLoadToReg(reg_value, R(reg_addr), accessSize, 0, signExtend); + if (farcode.Enabled()) + SwitchToFarCode(); + else + exit = J(true); + SetJumpTarget(slow); + } size_t rsp_alignment = (flags & SAFE_LOADSTORE_NO_PROLOG) ? 8 : 0; ABI_PushRegistersAndAdjustStack(registersInUse, rsp_alignment); switch (accessSize) @@ -387,12 +390,15 @@ void EmuCodeBlock::SafeLoadToReg(X64Reg reg_value, const Gen::OpArg & opAddress, MOVZX(64, accessSize, reg_value, R(ABI_RETURN)); } - if (farcode.Enabled()) + if (!jit->jo.alwaysUseMemFuncs) { - exit = J(true); - SwitchToNearCode(); + if (farcode.Enabled()) + { + exit = J(true); + SwitchToNearCode(); + } + SetJumpTarget(exit); } - SetJumpTarget(exit); } static OpArg SwapImmediate(int accessSize, OpArg reg_value) diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index 308c7d482b..4fc09c7f19 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -629,6 +629,10 @@ std::string HostGetString(u32 address, size_t size) bool IsOptimizableRAMAddress(const u32 address) { +#ifdef ENABLE_MEM_CHECK + return false; +#endif + if (!UReg_MSR(MSR).DR) return false; @@ -752,6 +756,10 @@ void ClearCacheLine(const u32 address) u32 IsOptimizableMMIOAccess(u32 address, u32 accessSize) { +#ifdef ENABLE_MEM_CHECK + return 0; +#endif + if (!UReg_MSR(MSR).DR) return 0; @@ -767,6 +775,10 @@ u32 IsOptimizableMMIOAccess(u32 address, u32 accessSize) bool IsOptimizableGatherPipeWrite(u32 address) { +#ifdef ENABLE_MEM_CHECK + return false; +#endif + if (!UReg_MSR(MSR).DR) return false;