Skip to content

Commit

Permalink
JitArm64: Optimize creqv setting eq/gt bit
Browse files Browse the repository at this point in the history
For the eq and gt bits specifically, setting negate_result is one
instruction shorter than not setting it.
  • Loading branch information
JosJuice committed Jan 6, 2025
1 parent c04ef2e commit 82695ea
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Source/Core/Core/PowerPC/JitArm64/JitArm64_SystemRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,11 @@ void JitArm64::crXXX(UGeckoInstruction inst)
}
}

// crnor or crnand
const bool negate_result = inst.SUBOP10 == 33 || inst.SUBOP10 == 225;
const u32 crbd_bit = 3 - (inst.CRBD & 3);
// crnor, crnand and sometimes creqv
const bool negate_result =
inst.SUBOP10 == 33 || inst.SUBOP10 == 225 ||
(inst.SUBOP10 == 289 && (crbd_bit == PowerPC::CR_EQ_BIT || crbd_bit == PowerPC::CR_GT_BIT));
bool bits_1_to_31_are_set = false;

auto WA = gpr.GetScopedReg();
Expand Down Expand Up @@ -666,8 +669,17 @@ void JitArm64::crXXX(UGeckoInstruction inst)
break;

case 289: // creqv: ~(A ^ B) = A ^ ~B
EON(WA, WA, WB);
bits_1_to_31_are_set = true;
// Both of these two implementations are equally correct, but which one is more efficient
// depends on which bit we're going to set in CRBD
if (negate_result)
{
ORR(XA, XA, XB);
}
else
{
EON(WA, WA, WB);
bits_1_to_31_are_set = true;
}
break;

case 33: // crnor: ~(A || B)
Expand Down

0 comments on commit 82695ea

Please sign in to comment.