Skip to content

Commit

Permalink
Merge pull request #12210 from JosJuice/fastmem-init-order
Browse files Browse the repository at this point in the history
Jit: Fix fastmem initialization order
  • Loading branch information
AdmiralCurtiss committed Oct 1, 2023
2 parents 7c99500 + 02d76ba commit 9d41024
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
Expand Up @@ -82,7 +82,7 @@ CachedInterpreter::~CachedInterpreter() = default;

void CachedInterpreter::Init()
{
RefreshConfig();
RefreshConfig(InitFastmemArena::No);

m_code.reserve(CODE_SIZE / sizeof(Instruction));

Expand Down Expand Up @@ -384,5 +384,5 @@ void CachedInterpreter::ClearCache()
{
m_code.clear();
m_block_cache.Clear();
RefreshConfig();
RefreshConfig(InitFastmemArena::No);
}
7 changes: 2 additions & 5 deletions Source/Core/Core/PowerPC/Jit64/Jit.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -307,7 +304,7 @@ void Jit64::ClearCache()
m_const_pool.Clear();
ClearCodeSpace();
Clear();
RefreshConfig();
RefreshConfig(InitFastmemArena::No);
ResetFreeMemoryRanges();
}

Expand Down
7 changes: 2 additions & 5 deletions Source/Core/Core/PowerPC/JitArm64/Jit.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -158,7 +155,7 @@ void JitArm64::ClearCache()
const Common::ScopedJITPageWriteAndNoExecute enable_jit_page_writes;
ClearCodeSpace();
m_far_code.ClearCodeSpace();
RefreshConfig();
RefreshConfig(InitFastmemArena::No);

GenerateAsm();

Expand Down
8 changes: 7 additions & 1 deletion Source/Core/Core/PowerPC/JitCommon/JitBase.cpp
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/Core/PowerPC/JitCommon/JitBase.h
Expand Up @@ -163,8 +163,14 @@ class JitBase : public CPUCoreBase

static const std::array<std::pair<bool JitBase::*, const Config::Info<bool>*>, 22> JIT_SETTINGS;

enum class InitFastmemArena
{
No,
Yes,
};

bool DoesConfigNeedRefresh();
void RefreshConfig();
void RefreshConfig(InitFastmemArena init_fastmem_arena);

void InitBLROptimization();
void ProtectStack();
Expand Down

0 comments on commit 9d41024

Please sign in to comment.