summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2026-11-15 12:29:37 +0100
committerGitHub <noreply@github.com>2026-11-15 12:29:37 +0100
commitf7a0bf5bd6c09233d56ff765cc2823da1586d4d4 (patch)
tree807727ddd2f2230fb4a949e68ef0d0c0a161c03c
parent80a1a25fbcdc01d8a374ff77a28d711f49558230 (diff)
parentffc287903e52f5c53b4e37c98eecc73784c0a66a (diff)
Merge pull request #14888 from SuperSamus/dcbx-dont-clear-icache
Jit: Don't invalidate instruction block cache with dcbx
-rw-r--r--Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStore.cpp33
-rw-r--r--Source/Core/Core/PowerPC/Jit64/Jit.h1
-rw-r--r--Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp8
-rw-r--r--Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp21
-rw-r--r--Source/Core/Core/PowerPC/JitArm64/Jit.h1
-rw-r--r--Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp21
-rw-r--r--Source/Core/Core/PowerPC/JitArm64/JitArm64_Tables.cpp8
7 files changed, 24 insertions, 69 deletions
diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStore.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStore.cpp
index 035904930d..b237ba22c9 100644
--- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStore.cpp
+++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_LoadStore.cpp
@@ -471,9 +471,18 @@ void Interpreter::dcbf(Interpreter& interpreter, UGeckoInstruction inst)
const u32 address = Helper_Get_EA_X(ppc_state, inst);
if (!ppc_state.m_enable_dcache)
{
- // Invalidate the JIT cache here as a heuristic to compensate for
- // the lack of precise L1 icache emulation in the JIT. (Portable software
- // should use icbi consistently, but games aren't portable.)
+ // Some games do not use `icbi` properly, and the JIT does not emulate the ICache accurately.
+ // Therefore, we use this instruction as an heuristic for invalidating the block cache. This is
+ // known to solve a crash after loading an area in games developed by Artificial Mind and
+ // Movement (Monster House, Scooby-Doo! Mystery Mayhem, Scooby-Doo! Unmasked).
+ // Note that this could cause unnecessary invalidation that would result in lengthy stutters. In
+ // the past `dcbi` and `dcbst` invalidated the block cache as well, and games like NBA Live
+ // 2005/06 or Harry Potter and the Prisoner of Azkaban are known to have suffered because of
+ // that (some games like The Last Story were fixed by making `dcbst` do nothing if it was
+ // preceded by `dcbt`/`dcbtst`).
+ // No games are known to be negatively affected with just `dcbf`, but if some were found, then
+ // this behavior would probably need to become an option.
+
interpreter.m_system.GetJitInterface().InvalidateICacheLine(address);
return;
}
@@ -491,15 +500,6 @@ void Interpreter::dcbi(Interpreter& interpreter, UGeckoInstruction inst)
}
const u32 address = Helper_Get_EA_X(ppc_state, inst);
- if (!ppc_state.m_enable_dcache)
- {
- // Invalidate the JIT cache here as a heuristic to compensate for
- // the lack of precise L1 icache emulation in the JIT. (Portable software
- // should use icbi consistently, but games aren't portable.)
- interpreter.m_system.GetJitInterface().InvalidateICacheLine(address);
- return;
- }
-
interpreter.m_mmu.InvalidateDCacheLine(address);
}
@@ -507,15 +507,6 @@ void Interpreter::dcbst(Interpreter& interpreter, UGeckoInstruction inst)
{
auto& ppc_state = interpreter.m_ppc_state;
const u32 address = Helper_Get_EA_X(ppc_state, inst);
- if (!ppc_state.m_enable_dcache)
- {
- // Invalidate the JIT cache here as a heuristic to compensate for
- // the lack of precise L1 icache emulation in the JIT. (Portable software
- // should use icbi consistently, but games aren't portable.)
- interpreter.m_system.GetJitInterface().InvalidateICacheLine(address);
- return;
- }
-
interpreter.m_mmu.StoreDCacheLine(address);
}
diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.h b/Source/Core/Core/PowerPC/Jit64/Jit.h
index 34275eada4..69b6e279fe 100644
--- a/Source/Core/Core/PowerPC/Jit64/Jit.h
+++ b/Source/Core/Core/PowerPC/Jit64/Jit.h
@@ -253,7 +253,6 @@ public:
void negx(UGeckoInstruction inst);
void slwx(UGeckoInstruction inst);
void srwx(UGeckoInstruction inst);
- void dcbt(UGeckoInstruction inst);
void dcbz(UGeckoInstruction inst);
void subfic(UGeckoInstruction inst);
diff --git a/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp b/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp
index be5458bffc..fa5e723c25 100644
--- a/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp
+++ b/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp
@@ -199,11 +199,11 @@ constexpr std::array<Jit64OpTemplate, 107> s_table31{{
{824, &Jit64::srawix}, // srawix
{24, &Jit64::slwx}, // slwx
- {54, &Jit64::dcbx}, // dcbst
+ {54, &Jit64::DoNothing}, // dcbst
{86, &Jit64::dcbx}, // dcbf
- {246, &Jit64::dcbt}, // dcbtst
- {278, &Jit64::dcbt}, // dcbt
- {470, &Jit64::dcbx}, // dcbi
+ {246, &Jit64::DoNothing}, // dcbtst
+ {278, &Jit64::DoNothing}, // dcbt
+ {470, &Jit64::DoNothing}, // dcbi
{758, &Jit64::DoNothing}, // dcba
{1014, &Jit64::dcbz}, // dcbz
diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp
index 89599f279e..8500081804 100644
--- a/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp
+++ b/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp
@@ -238,6 +238,8 @@ void Jit64::dcbx(UGeckoInstruction inst)
JITDISABLE(bJITLoadStoreOff);
FALLBACK_IF(m_accurate_cpu_cache_enabled);
+ // See Interpreter::dcbf comment on explanation of why this exists.
+
// Check if the next instructions match a known looping pattern:
// - dcbx rX
// - addi rX,rX,32
@@ -400,25 +402,6 @@ void Jit64::dcbx(UGeckoInstruction inst)
SetJumpTarget(done);
}
-void Jit64::dcbt(UGeckoInstruction inst)
-{
- INSTRUCTION_START
- JITDISABLE(bJITLoadStoreOff);
-
- // Prefetch. Since we don't emulate the data cache, we don't need to do anything.
-
- // If a dcbst follows a dcbt, it probably isn't a case of dynamic code
- // modification, so don't bother invalidating the jit block cache.
- // This is important because invalidating the block cache when we don't
- // need to is terrible for performance.
- // (Invalidating the jit block cache on dcbst is a heuristic.)
- if (CanMergeNextInstructions(1) && js.op[1].inst.OPCD == 31 && js.op[1].inst.SUBOP10 == 54 &&
- js.op[1].inst.RA == inst.RA && js.op[1].inst.RB == inst.RB)
- {
- js.skipInstructions = 1;
- }
-}
-
// Zero cache line.
void Jit64::dcbz(UGeckoInstruction inst)
{
diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.h b/Source/Core/Core/PowerPC/JitArm64/Jit.h
index 0472b36405..ebbae0205d 100644
--- a/Source/Core/Core/PowerPC/JitArm64/Jit.h
+++ b/Source/Core/Core/PowerPC/JitArm64/Jit.h
@@ -143,7 +143,6 @@ public:
void lmw(UGeckoInstruction inst);
void stmw(UGeckoInstruction inst);
void dcbx(UGeckoInstruction inst);
- void dcbt(UGeckoInstruction inst);
void dcbz(UGeckoInstruction inst);
void eieio(UGeckoInstruction inst);
diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp
index 7e5da7a904..e2f6afa31b 100644
--- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp
+++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp
@@ -706,6 +706,8 @@ void JitArm64::dcbx(UGeckoInstruction inst)
JITDISABLE(bJITLoadStoreOff);
FALLBACK_IF(m_accurate_cpu_cache_enabled);
+ // See Interpreter::dcbf comment on explanation of why this invalidates the block cache.
+
u32 a = inst.RA, b = inst.RB;
// Check if the next instructions match a known looping pattern:
@@ -878,25 +880,6 @@ void JitArm64::dcbx(UGeckoInstruction inst)
gpr.Unlock(loop_counter);
}
-void JitArm64::dcbt(UGeckoInstruction inst)
-{
- INSTRUCTION_START
- JITDISABLE(bJITLoadStoreOff);
-
- // Prefetch. Since we don't emulate the data cache, we don't need to do anything.
-
- // If a dcbst follows a dcbt, it probably isn't a case of dynamic code
- // modification, so don't bother invalidating the jit block cache.
- // This is important because invalidating the block cache when we don't
- // need to is terrible for performance.
- // (Invalidating the jit block cache on dcbst is a heuristic.)
- if (CanMergeNextInstructions(1) && js.op[1].inst.OPCD == 31 && js.op[1].inst.SUBOP10 == 54 &&
- js.op[1].inst.RA == inst.RA && js.op[1].inst.RB == inst.RB)
- {
- js.skipInstructions = 1;
- }
-}
-
void JitArm64::dcbz(UGeckoInstruction inst)
{
INSTRUCTION_START
diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Tables.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Tables.cpp
index dc72083d39..438d1ffc15 100644
--- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Tables.cpp
+++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Tables.cpp
@@ -199,11 +199,11 @@ constexpr std::array<JitArm64OpTemplate, 107> s_table31{{
{824, &JitArm64::srawix}, // srawix
{24, &JitArm64::slwx}, // slwx
- {54, &JitArm64::dcbx}, // dcbst
+ {54, &JitArm64::DoNothing}, // dcbst
{86, &JitArm64::dcbx}, // dcbf
- {246, &JitArm64::dcbt}, // dcbtst
- {278, &JitArm64::dcbt}, // dcbt
- {470, &JitArm64::dcbx}, // dcbi
+ {246, &JitArm64::DoNothing}, // dcbtst
+ {278, &JitArm64::DoNothing}, // dcbt
+ {470, &JitArm64::DoNothing}, // dcbi
{758, &JitArm64::DoNothing}, // dcba
{1014, &JitArm64::dcbz}, // dcbz