Skip to content
Permalink
Browse files
Merge pull request #9799 from Tilka/interpreter
Interpreter: deduplicate integer comparisons
  • Loading branch information
Tilka committed Jun 9, 2021
2 parents 0aa9e8d + 5fc3cb2 commit e62610e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 48 deletions.
@@ -291,6 +291,8 @@ class Interpreter : public CPUCoreBase
// flag helper
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_FloatCompareUnordered(UGeckoInstruction inst, double a, double b);

@@ -66,42 +66,36 @@ void Interpreter::andis_rc(UGeckoInstruction inst)
Helper_UpdateCR0(rGPR[inst.RA]);
}

void Interpreter::cmpi(UGeckoInstruction inst)
template <typename T>
void Interpreter::Helper_IntCompare(UGeckoInstruction inst, T a, T b)
{
const s32 a = static_cast<s32>(rGPR[inst.RA]);
const s32 b = inst.SIMM_16;
u32 f;
u32 cr_field;

if (a < b)
f = 0x8;
cr_field = PowerPC::CR_LT;
else if (a > b)
f = 0x4;
cr_field = PowerPC::CR_GT;
else
f = 0x2; // equals
cr_field = PowerPC::CR_EQ;

if (PowerPC::GetXER_SO())
f |= 0x1;
cr_field |= PowerPC::CR_SO;

PowerPC::ppcState.cr.SetField(inst.CRFD, f);
PowerPC::ppcState.cr.SetField(inst.CRFD, cr_field);
}

void Interpreter::cmpi(UGeckoInstruction inst)
{
const s32 a = static_cast<s32>(rGPR[inst.RA]);
const s32 b = inst.SIMM_16;
Helper_IntCompare(inst, a, b);
}

void Interpreter::cmpli(UGeckoInstruction inst)
{
const u32 a = rGPR[inst.RA];
const u32 b = inst.UIMM;
u32 f;

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);
Helper_IntCompare(inst, a, b);
}

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 b = static_cast<s32>(rGPR[inst.RB]);
u32 temp;

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);
Helper_IntCompare(inst, a, b);
}

void Interpreter::cmpl(UGeckoInstruction inst)
{
const u32 a = rGPR[inst.RA];
const u32 b = rGPR[inst.RB];
u32 temp;

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);
Helper_IntCompare(inst, a, b);
}

void Interpreter::cntlzwx(UGeckoInstruction inst)

0 comments on commit e62610e

Please sign in to comment.