Skip to content

Commit

Permalink
PowerPC: Use broader mask for checking loadstore exceptions
Browse files Browse the repository at this point in the history
We will need to check for EXCEPTION_ALIGNMENT in addition to
EXCEPTION_DSI. Let's also throw in EXCEPTION_FAKE_MEMCHECK_HIT
while we're at it so we can skip doing fake DSI exceptions for that.

Reordering the exceptions enum is done for the sake of saving one
instruction on AArch64 when checking for loadstore exceptions.
(Bitwise operations can encode immediates containing a run of ones
of an arbitrary length, rotated by an arbitrary amount of bits.
In order to make use of this, all loadstore exceptions should
have adjacent bit positions.)
  • Loading branch information
JosJuice committed Jan 21, 2024
1 parent 40e0df3 commit 04ecf4d
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ bool CachedInterpreter::CheckFPU(CachedInterpreter& cached_interpreter, u32 data
return false;
}

bool CachedInterpreter::CheckDSI(CachedInterpreter& cached_interpreter, u32 data)
bool CachedInterpreter::CheckLoadStore(CachedInterpreter& cached_interpreter, u32 data)
{
auto& ppc_state = cached_interpreter.m_ppc_state;
if (ppc_state.Exceptions & EXCEPTION_DSI)
if (ppc_state.Exceptions & ANY_LOADSTORE_EXCEPTION)
{
cached_interpreter.m_system.GetPowerPC().CheckExceptions();
ppc_state.downcount -= data;
Expand Down Expand Up @@ -356,7 +356,7 @@ void CachedInterpreter::Jit(u32 address)

m_code.emplace_back(Interpreter::GetInterpreterOp(op.inst), op.inst);
if (memcheck)
m_code.emplace_back(CheckDSI, js.downcountAmount);
m_code.emplace_back(CheckLoadStore, js.downcountAmount);
if (check_program_exception)
m_code.emplace_back(CheckProgramException, js.downcountAmount);
if (idle_loop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CachedInterpreter : public JitBase
static void WritePC(CachedInterpreter& cached_interpreter, UGeckoInstruction data);
static void WriteBrokenBlockNPC(CachedInterpreter& cached_interpreter, UGeckoInstruction data);
static bool CheckFPU(CachedInterpreter& cached_interpreter, u32 data);
static bool CheckDSI(CachedInterpreter& cached_interpreter, u32 data);
static bool CheckLoadStore(CachedInterpreter& cached_interpreter, u32 data);
static bool CheckProgramException(CachedInterpreter& cached_interpreter, u32 data);
static bool CheckBreakpoint(CachedInterpreter& cached_interpreter, u32 data);
static bool CheckIdle(CachedInterpreter& cached_interpreter, u32 idle_pc);
Expand Down
13 changes: 7 additions & 6 deletions Source/Core/Core/PowerPC/Gekko.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,15 @@ enum
EXCEPTION_DECREMENTER = 0x00000001,
EXCEPTION_SYSCALL = 0x00000002,
EXCEPTION_EXTERNAL_INT = 0x00000004,
EXCEPTION_DSI = 0x00000008,
EXCEPTION_ISI = 0x00000010,
EXCEPTION_ISI = 0x00000008,
EXCEPTION_DSI = 0x00000010,
EXCEPTION_ALIGNMENT = 0x00000020,
EXCEPTION_FPU_UNAVAILABLE = 0x00000040,
EXCEPTION_PROGRAM = 0x00000080,
EXCEPTION_PERFORMANCE_MONITOR = 0x00000100,
EXCEPTION_FAKE_MEMCHECK_HIT = 0x00000040,
EXCEPTION_FPU_UNAVAILABLE = 0x00000080,
EXCEPTION_PROGRAM = 0x00000100,
EXCEPTION_PERFORMANCE_MONITOR = 0x00000200,

EXCEPTION_FAKE_MEMCHECK_HIT = 0x00000200,
ANY_LOADSTORE_EXCEPTION = EXCEPTION_DSI | EXCEPTION_ALIGNMENT | EXCEPTION_FAKE_MEMCHECK_HIT,
};

enum CPUEmuFeatureFlags : u32
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int Interpreter::SingleStepInner()
else if (m_ppc_state.msr.FP)
{
RunInterpreterOp(*this, m_prev_inst);
if ((m_ppc_state.Exceptions & EXCEPTION_DSI) != 0)
if ((m_ppc_state.Exceptions & ANY_LOADSTORE_EXCEPTION) != 0)
{
CheckExceptions();
}
Expand All @@ -173,7 +173,7 @@ int Interpreter::SingleStepInner()
else
{
RunInterpreterOp(*this, m_prev_inst);
if ((m_ppc_state.Exceptions & EXCEPTION_DSI) != 0)
if ((m_ppc_state.Exceptions & ANY_LOADSTORE_EXCEPTION) != 0)
{
CheckExceptions();
}
Expand Down
Loading

0 comments on commit 04ecf4d

Please sign in to comment.