From 02d76ba2a00ac86b0f7ad28d09394ff02733f2bb Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 30 Sep 2023 14:46:08 +0200 Subject: [PATCH] Jit: Fix fastmem initialization order When evaluating whether jo.fastmem should be set to true, we check the value of jo.fastmem_arena. However, due to a change made in 28e8117b90, jo.fastmem_arena wasn't set until after the first time we set jo.fastmem, so jo.fastmem would end up always being false until the next time RefreshConfig was called. Fixes https://bugs.dolphin-emu.org/issues/13364. --- .../Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp | 4 ++-- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 7 ++----- Source/Core/Core/PowerPC/JitArm64/Jit.cpp | 7 ++----- Source/Core/Core/PowerPC/JitCommon/JitBase.cpp | 8 +++++++- Source/Core/Core/PowerPC/JitCommon/JitBase.h | 8 +++++++- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp index 8fbed42f06..632fbb23f1 100644 --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp @@ -82,7 +82,7 @@ CachedInterpreter::~CachedInterpreter() = default; void CachedInterpreter::Init() { - RefreshConfig(); + RefreshConfig(InitFastmemArena::No); m_code.reserve(CODE_SIZE / sizeof(Instruction)); @@ -384,5 +384,5 @@ void CachedInterpreter::ClearCache() { m_code.clear(); m_block_cache.Clear(); - RefreshConfig(); + RefreshConfig(InitFastmemArena::No); } diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 9fe8e1430c..9a5f603573 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -251,13 +251,10 @@ bool Jit64::BackPatch(SContext* ctx) void Jit64::Init() { - RefreshConfig(); + RefreshConfig(InitFastmemArena::Yes); EnableBlockLink(); - auto& memory = m_system.GetMemory(); - - jo.fastmem_arena = m_fastmem_enabled && memory.InitFastmemArena(); jo.optimizeGatherPipe = true; jo.accurateSinglePrecision = true; js.fastmemLoadStore = nullptr; @@ -307,7 +304,7 @@ void Jit64::ClearCache() m_const_pool.Clear(); ClearCodeSpace(); Clear(); - RefreshConfig(); + RefreshConfig(InitFastmemArena::No); ResetFreeMemoryRanges(); } diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index 55c6b75231..961395e83c 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -47,15 +47,12 @@ JitArm64::~JitArm64() = default; void JitArm64::Init() { - RefreshConfig(); + RefreshConfig(InitFastmemArena::Yes); const size_t child_code_size = jo.memcheck ? FARCODE_SIZE_MMU : FARCODE_SIZE; AllocCodeSpace(CODE_SIZE + child_code_size); AddChildCodeSpace(&m_far_code, child_code_size); - auto& memory = m_system.GetMemory(); - - jo.fastmem_arena = m_fastmem_enabled && memory.InitFastmemArena(); jo.optimizeGatherPipe = true; SetBlockLinkingEnabled(true); SetOptimizationEnabled(true); @@ -158,7 +155,7 @@ void JitArm64::ClearCache() const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes; ClearCodeSpace(); m_far_code.ClearCodeSpace(); - RefreshConfig(); + RefreshConfig(InitFastmemArena::No); GenerateAsm(); diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp index bcdafd9725..88d28ea8ac 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.cpp @@ -115,7 +115,7 @@ bool JitBase::DoesConfigNeedRefresh() }); } -void JitBase::RefreshConfig() +void JitBase::RefreshConfig(InitFastmemArena init_fastmem_arena) { for (const auto& [member, config_info] : JIT_SETTINGS) this->*member = Config::Get(*config_info); @@ -132,6 +132,12 @@ void JitBase::RefreshConfig() analyzer.SetFloatExceptionsEnabled(m_enable_float_exceptions); analyzer.SetDivByZeroExceptionsEnabled(m_enable_div_by_zero_exceptions); + if (init_fastmem_arena != InitFastmemArena::No) + { + auto& memory = m_system.GetMemory(); + jo.fastmem_arena = m_fastmem_enabled && memory.InitFastmemArena(); + } + bool any_watchpoints = m_system.GetPowerPC().GetMemChecks().HasAny(); jo.fastmem = m_fastmem_enabled && jo.fastmem_arena && (m_ppc_state.msr.DR || !any_watchpoints) && EMM::IsExceptionHandlerSupported(); diff --git a/Source/Core/Core/PowerPC/JitCommon/JitBase.h b/Source/Core/Core/PowerPC/JitCommon/JitBase.h index 6c95559438..f96c068b98 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitBase.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitBase.h @@ -163,8 +163,14 @@ protected: static const std::array*>, 22> JIT_SETTINGS; + enum class InitFastmemArena + { + No, + Yes, + }; + bool DoesConfigNeedRefresh(); - void RefreshConfig(); + void RefreshConfig(InitFastmemArena init_fastmem_arena); void InitBLROptimization(); void ProtectStack();