From f3671d21f3722b74702045aa2c33d4cdb86a379a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 30 Jun 2024 15:07:14 +1000 Subject: [PATCH] CPU/CodeCache: Reduce far code size when using NewRec --- src/core/cpu_code_cache.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/cpu_code_cache.cpp b/src/core/cpu_code_cache.cpp index 0167a87ee..61f1d5fd7 100644 --- a/src/core/cpu_code_cache.cpp +++ b/src/core/cpu_code_cache.cpp @@ -126,7 +126,7 @@ PerfScope MIPSPerfScope("MIPS"); #if defined(CPU_ARCH_ARM32) // Use a smaller code buffer size on AArch32 to have a better chance of being in range. -static constexpr u32 RECOMPILER_CODE_CACHE_SIZE = 20 * 1024 * 1024; +static constexpr u32 RECOMPILER_CODE_CACHE_SIZE = 16 * 1024 * 1024; static constexpr u32 RECOMPILER_FAR_CODE_CACHE_SIZE = 4 * 1024 * 1024; #else static constexpr u32 RECOMPILER_CODE_CACHE_SIZE = 48 * 1024 * 1024; @@ -1435,8 +1435,13 @@ void CPU::CodeCache::ResetCodeBuffer() s_code_size = RECOMPILER_CODE_CACHE_SIZE - RECOMPILER_FAR_CODE_CACHE_SIZE; s_code_used = 0; - s_far_code_size = RECOMPILER_FAR_CODE_CACHE_SIZE; - s_far_code_ptr = (s_far_code_size > 0) ? (static_cast(s_code_ptr) + s_code_size) : nullptr; + // Use half the far code size when using newrec and memory exceptions aren't enabled. It's only used for backpatching. + const u32 far_code_size = + (g_settings.cpu_execution_mode == CPUExecutionMode::NewRec && !g_settings.cpu_recompiler_memory_exceptions) ? + (RECOMPILER_FAR_CODE_CACHE_SIZE / 2) : + RECOMPILER_FAR_CODE_CACHE_SIZE; + s_far_code_size = far_code_size; + s_far_code_ptr = (far_code_size > 0) ? (static_cast(s_code_ptr) + s_code_size) : nullptr; s_free_far_code_ptr = s_far_code_ptr; s_far_code_used = 0;