Merge pull request #9799 from Tilka/interpreter

Interpreter: deduplicate integer comparisons
This commit is contained in:
Tilka 2021-06-09 22:34:07 +01:00 committed by GitHub
commit e62610e6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 52 deletions

View File

@ -291,6 +291,8 @@ private:
// flag helper // flag helper
static void Helper_UpdateCR0(u32 value); static void Helper_UpdateCR0(u32 value);
template <typename T>
static void Helper_IntCompare(UGeckoInstruction inst, T a, T b);
static void Helper_FloatCompareOrdered(UGeckoInstruction inst, double a, double b); static void Helper_FloatCompareOrdered(UGeckoInstruction inst, double a, double b);
static void Helper_FloatCompareUnordered(UGeckoInstruction inst, double a, double b); static void Helper_FloatCompareUnordered(UGeckoInstruction inst, double a, double b);

View File

@ -66,42 +66,36 @@ void Interpreter::andis_rc(UGeckoInstruction inst)
Helper_UpdateCR0(rGPR[inst.RA]); Helper_UpdateCR0(rGPR[inst.RA]);
} }
template <typename T>
void Interpreter::Helper_IntCompare(UGeckoInstruction inst, T a, T b)
{
u32 cr_field;
if (a < b)
cr_field = PowerPC::CR_LT;
else if (a > b)
cr_field = PowerPC::CR_GT;
else
cr_field = PowerPC::CR_EQ;
if (PowerPC::GetXER_SO())
cr_field |= PowerPC::CR_SO;
PowerPC::ppcState.cr.SetField(inst.CRFD, cr_field);
}
void Interpreter::cmpi(UGeckoInstruction inst) void Interpreter::cmpi(UGeckoInstruction inst)
{ {
const s32 a = static_cast<s32>(rGPR[inst.RA]); const s32 a = static_cast<s32>(rGPR[inst.RA]);
const s32 b = inst.SIMM_16; const s32 b = inst.SIMM_16;
u32 f; Helper_IntCompare(inst, a, b);
if (a < b)
f = 0x8;
else if (a > b)
f = 0x4;
else
f = 0x2; // equals
if (PowerPC::GetXER_SO())
f |= 0x1;
PowerPC::ppcState.cr.SetField(inst.CRFD, f);
} }
void Interpreter::cmpli(UGeckoInstruction inst) void Interpreter::cmpli(UGeckoInstruction inst)
{ {
const u32 a = rGPR[inst.RA]; const u32 a = rGPR[inst.RA];
const u32 b = inst.UIMM; const u32 b = inst.UIMM;
u32 f; Helper_IntCompare(inst, a, b);
if (a < b)
f = 0x8;
else if (a > b)
f = 0x4;
else
f = 0x2; // equals
if (PowerPC::GetXER_SO())
f |= 0x1;
PowerPC::ppcState.cr.SetField(inst.CRFD, f);
} }
void Interpreter::mulli(UGeckoInstruction inst) void Interpreter::mulli(UGeckoInstruction inst)
@ -200,38 +194,14 @@ void Interpreter::cmp(UGeckoInstruction inst)
{ {
const s32 a = static_cast<s32>(rGPR[inst.RA]); const s32 a = static_cast<s32>(rGPR[inst.RA]);
const s32 b = static_cast<s32>(rGPR[inst.RB]); const s32 b = static_cast<s32>(rGPR[inst.RB]);
u32 temp; Helper_IntCompare(inst, a, b);
if (a < b)
temp = 0x8;
else if (a > b)
temp = 0x4;
else // Equals
temp = 0x2;
if (PowerPC::GetXER_SO())
temp |= 0x1;
PowerPC::ppcState.cr.SetField(inst.CRFD, temp);
} }
void Interpreter::cmpl(UGeckoInstruction inst) void Interpreter::cmpl(UGeckoInstruction inst)
{ {
const u32 a = rGPR[inst.RA]; const u32 a = rGPR[inst.RA];
const u32 b = rGPR[inst.RB]; const u32 b = rGPR[inst.RB];
u32 temp; Helper_IntCompare(inst, a, b);
if (a < b)
temp = 0x8;
else if (a > b)
temp = 0x4;
else // Equals
temp = 0x2;
if (PowerPC::GetXER_SO())
temp |= 0x1;
PowerPC::ppcState.cr.SetField(inst.CRFD, temp);
} }
void Interpreter::cntlzwx(UGeckoInstruction inst) void Interpreter::cntlzwx(UGeckoInstruction inst)