translate_arm/branch: Invert conditionals where applicable

Allows unindenting code a bit.
This commit is contained in:
Lioncash 2019-02-28 23:34:57 -05:00 committed by MerryMage
parent 20fabc5083
commit df5c51ff47

View file

@ -10,65 +10,75 @@
namespace Dynarmic::A32 { namespace Dynarmic::A32 {
// B <label>
bool ArmTranslatorVisitor::arm_B(Cond cond, Imm24 imm24) { bool ArmTranslatorVisitor::arm_B(Cond cond, Imm24 imm24) {
u32 imm32 = Common::SignExtend<26, u32>(imm24 << 2) + 8; if (!ConditionPassed(cond)) {
// B <label> return true;
if (ConditionPassed(cond)) {
auto new_location = ir.current_location.AdvancePC(imm32);
ir.SetTerm(IR::Term::LinkBlock{ new_location });
return false;
} }
return true;
}
bool ArmTranslatorVisitor::arm_BL(Cond cond, Imm24 imm24) { const u32 imm32 = Common::SignExtend<26, u32>(imm24 << 2) + 8;
u32 imm32 = Common::SignExtend<26, u32>(imm24 << 2) + 8; const auto new_location = ir.current_location.AdvancePC(imm32);
// BL <label> ir.SetTerm(IR::Term::LinkBlock{new_location});
if (ConditionPassed(cond)) {
ir.PushRSB(ir.current_location.AdvancePC(4));
ir.SetRegister(Reg::LR, ir.Imm32(ir.current_location.PC() + 4));
auto new_location = ir.current_location.AdvancePC(imm32);
ir.SetTerm(IR::Term::LinkBlock{ new_location });
return false;
}
return true;
}
bool ArmTranslatorVisitor::arm_BLX_imm(bool H, Imm24 imm24) {
u32 imm32 = Common::SignExtend<26, u32>((imm24 << 2)) + (H ? 2 : 0) + 8;
// BLX <label>
ir.PushRSB(ir.current_location.AdvancePC(4));
ir.SetRegister(Reg::LR, ir.Imm32(ir.current_location.PC() + 4));
auto new_location = ir.current_location.AdvancePC(imm32).SetTFlag(true);
ir.SetTerm(IR::Term::LinkBlock{ new_location });
return false; return false;
} }
bool ArmTranslatorVisitor::arm_BLX_reg(Cond cond, Reg m) { // BL <label>
if (m == Reg::PC) bool ArmTranslatorVisitor::arm_BL(Cond cond, Imm24 imm24) {
return UnpredictableInstruction(); if (!ConditionPassed(cond)) {
// BLX <Rm> return true;
if (ConditionPassed(cond)) {
ir.PushRSB(ir.current_location.AdvancePC(4));
ir.BXWritePC(ir.GetRegister(m));
ir.SetRegister(Reg::LR, ir.Imm32(ir.current_location.PC() + 4));
ir.SetTerm(IR::Term::FastDispatchHint{});
return false;
} }
return true;
ir.PushRSB(ir.current_location.AdvancePC(4));
ir.SetRegister(Reg::LR, ir.Imm32(ir.current_location.PC() + 4));
const u32 imm32 = Common::SignExtend<26, u32>(imm24 << 2) + 8;
const auto new_location = ir.current_location.AdvancePC(imm32);
ir.SetTerm(IR::Term::LinkBlock{new_location});
return false;
} }
bool ArmTranslatorVisitor::arm_BX(Cond cond, Reg m) { // BLX <label>
// BX <Rm> bool ArmTranslatorVisitor::arm_BLX_imm(bool H, Imm24 imm24) {
if (ConditionPassed(cond)) { ir.PushRSB(ir.current_location.AdvancePC(4));
ir.BXWritePC(ir.GetRegister(m)); ir.SetRegister(Reg::LR, ir.Imm32(ir.current_location.PC() + 4));
if (m == Reg::R14)
ir.SetTerm(IR::Term::PopRSBHint{}); const u32 imm32 = Common::SignExtend<26, u32>((imm24 << 2)) + (H ? 2 : 0) + 8;
else const auto new_location = ir.current_location.AdvancePC(imm32).SetTFlag(true);
ir.SetTerm(IR::Term::FastDispatchHint{}); ir.SetTerm(IR::Term::LinkBlock{new_location});
return false; return false;
}
// BLX <Rm>
bool ArmTranslatorVisitor::arm_BLX_reg(Cond cond, Reg m) {
if (m == Reg::PC) {
return UnpredictableInstruction();
} }
return true;
if (!ConditionPassed(cond)) {
return true;
}
ir.PushRSB(ir.current_location.AdvancePC(4));
ir.BXWritePC(ir.GetRegister(m));
ir.SetRegister(Reg::LR, ir.Imm32(ir.current_location.PC() + 4));
ir.SetTerm(IR::Term::FastDispatchHint{});
return false;
}
// BX <Rm>
bool ArmTranslatorVisitor::arm_BX(Cond cond, Reg m) {
if (!ConditionPassed(cond)) {
return true;
}
ir.BXWritePC(ir.GetRegister(m));
if (m == Reg::R14) {
ir.SetTerm(IR::Term::PopRSBHint{});
} else {
ir.SetTerm(IR::Term::FastDispatchHint{});
}
return false;
} }
bool ArmTranslatorVisitor::arm_BXJ(Cond cond, Reg m) { bool ArmTranslatorVisitor::arm_BXJ(Cond cond, Reg m) {