summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartino Fontana <tinozzo123@gmail.com>2026-09-05 00:23:14 +0200
committerMartino Fontana <tinozzo123@gmail.com>2026-09-26 22:23:41 +0200
commitf0eb5d60b50d01f0609cb26a81136dc6d52beef7 (patch)
treed3fbc968bd992c17fe2487ac4c7f67b50c1f648b
parent465c652da1dc0b3048089701a1885084821c9574 (diff)
Jit64: Merge m_exception_handler_at_loc in TrampolineInfo
If MMU is enabled, there's an m_exception_handler_at_loc entry for almost every entry in m_back_patch_info, so keeping them separate is a huge waste: hashmaps aren't free. Brings a decent improvement to codegen performance when MMU is enabled. If MMU is disabled, however, this increases the size of TrampolineInfo by 8 bytes. It's a little sad, but it's important to prioritize the worst-case performance. Also, it simplifies the next commit, which will reduce the memory usage anyway.
-rw-r--r--Source/Core/Core/PowerPC/Jit64/Jit.cpp13
-rw-r--r--Source/Core/Core/PowerPC/Jit64Common/EmuCodeBlock.cpp1
-rw-r--r--Source/Core/Core/PowerPC/Jit64Common/TrampolineInfo.h5
3 files changed, 6 insertions, 13 deletions
diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp
index 1248b1ab01..91085b6199 100644
--- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp
+++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp
@@ -179,14 +179,6 @@ bool Jit64::BackPatch(SContext* ctx)
TrampolineInfo& info = it->second;
- u8* exceptionHandler = nullptr;
- if (jo.memcheck)
- {
- auto it2 = m_exception_handler_at_loc.find(codePtr);
- if (it2 != m_exception_handler_at_loc.end())
- exceptionHandler = it2->second;
- }
-
// In the trampoline code, we jump back into the block at the beginning
// of the next instruction. The next instruction comes immediately
// after the backpatched operation, or BACKPATCH_SIZE bytes after the start
@@ -195,7 +187,7 @@ bool Jit64::BackPatch(SContext* ctx)
// to insert the backpatch jump.)
js.generatingTrampoline = true;
- js.trampolineExceptionHandler = exceptionHandler;
+ js.trampolineExceptionHandler = info.exception_handler_at_loc;
js.compilerPC = info.pc;
// Generate the trampoline.
@@ -1203,12 +1195,11 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
SwitchToFarCode();
if (!js.fastmemLoadStore)
{
- m_exception_handler_at_loc[js.fastmemLoadStore] = nullptr;
SetJumpTarget(js.fixupExceptionHandler ? js.exceptionHandler : memException);
}
else
{
- m_exception_handler_at_loc[js.fastmemLoadStore] = GetWritableCodePtr();
+ m_back_patch_info.at(js.fastmemLoadStore).exception_handler_at_loc = GetWritableCodePtr();
}
RCForkGuard gpr_guard = gpr.Fork();
diff --git a/Source/Core/Core/PowerPC/Jit64Common/EmuCodeBlock.cpp b/Source/Core/Core/PowerPC/Jit64Common/EmuCodeBlock.cpp
index 1019aa7d0a..d99ec2b155 100644
--- a/Source/Core/Core/PowerPC/Jit64Common/EmuCodeBlock.cpp
+++ b/Source/Core/Core/PowerPC/Jit64Common/EmuCodeBlock.cpp
@@ -1061,5 +1061,4 @@ void EmuCodeBlock::SetFPRF(Gen::X64Reg xmm, bool single)
void EmuCodeBlock::Clear()
{
m_back_patch_info.clear();
- m_exception_handler_at_loc.clear();
}
diff --git a/Source/Core/Core/PowerPC/Jit64Common/TrampolineInfo.h b/Source/Core/Core/PowerPC/Jit64Common/TrampolineInfo.h
index d76d3f724f..c230abe992 100644
--- a/Source/Core/Core/PowerPC/Jit64Common/TrampolineInfo.h
+++ b/Source/Core/Core/PowerPC/Jit64Common/TrampolineInfo.h
@@ -8,7 +8,7 @@
#include "Common/x64Emitter.h"
// Stores information we need to batch-patch a MOV with a call to the slow read/write path after
-// it faults. There will be 10s of thousands of these structs live, so be wary of making this too
+// it faults. There will be 100s of thousands of these structs live, so be wary of making this too
// big.
struct TrampolineInfo final
{
@@ -46,4 +46,7 @@ struct TrampolineInfo final
s32 offset = 0;
Gen::X64Reg op_reg{};
Gen::OpArg op_arg{};
+
+ // It's not set if memcheck is disabled. Otherwise, it's almost always set.
+ u8* exception_handler_at_loc = nullptr;
};