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,
and in order to make use of this all loadstore exceptions should
have adjacent bit positions.)
  • Loading branch information
JosJuice committed Jul 4, 2021
1 parent 2409d30 commit deb70fd
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ static bool CheckFPU(u32 data)
return false;
}

static bool CheckDSI(u32 data)
static bool CheckLoadStore(u32 data)
{
if (PowerPC::ppcState.Exceptions & EXCEPTION_DSI)
if (PowerPC::ppcState.Exceptions & ANY_LOADSTORE_EXCEPTION)
{
PowerPC::CheckExceptions();
PowerPC::ppcState.downcount -= data;
Expand Down Expand Up @@ -287,7 +287,7 @@ void CachedInterpreter::Jit(u32 address)
m_code.emplace_back(WritePC, op.address);
m_code.emplace_back(PPCTables::GetInterpreterOp(op.inst), op.inst);
if (memcheck)
m_code.emplace_back(CheckDSI, js.downcountAmount);
m_code.emplace_back(CheckLoadStore, js.downcountAmount);
if (idle_loop)
m_code.emplace_back(CheckIdle, js.blockStart);
if (endblock)
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 @@ -900,14 +900,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,
};

constexpr s32 SignExt16(s16 x)
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 @@ -188,7 +188,7 @@ int Interpreter::SingleStepInner()
else if (MSR.FP)
{
m_op_table[m_prev_inst.OPCD](m_prev_inst);
if (PowerPC::ppcState.Exceptions & EXCEPTION_DSI)
if (PowerPC::ppcState.Exceptions & ANY_LOADSTORE_EXCEPTION)
{
CheckExceptions();
}
Expand All @@ -204,7 +204,7 @@ int Interpreter::SingleStepInner()
else
{
m_op_table[m_prev_inst.OPCD](m_prev_inst);
if (PowerPC::ppcState.Exceptions & EXCEPTION_DSI)
if (PowerPC::ppcState.Exceptions & ANY_LOADSTORE_EXCEPTION)
{
CheckExceptions();
}
Expand Down

0 comments on commit deb70fd

Please sign in to comment.