Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jit: Fix fastmem initialization order #12210

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ JitArm64::~JitArm64() = default;

void JitArm64::Init()
{
RefreshConfig();
RefreshConfig(InitFastmemArena::Yes);
JosJuice marked this conversation as resolved.
Show resolved Hide resolved

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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