thumb32: Simplify register shift implementations to common function

This commit is contained in:
Lioncash 2021-02-23 04:52:21 -05:00
parent a7a9ed69b7
commit 725d712c88

View file

@ -6,61 +6,42 @@
#include "frontend/A32/translate/impl/translate_thumb.h" #include "frontend/A32/translate/impl/translate_thumb.h"
namespace Dynarmic::A32 { namespace Dynarmic::A32 {
static IR::U32 Rotate(A32::IREmitter& ir, Reg m, SignExtendRotation rotate) { namespace {
IR::U32 Rotate(A32::IREmitter& ir, Reg m, SignExtendRotation rotate) {
const u8 rotate_by = static_cast<u8>(static_cast<size_t>(rotate) * 8); const u8 rotate_by = static_cast<u8>(static_cast<size_t>(rotate) * 8);
return ir.RotateRight(ir.GetRegister(m), ir.Imm8(rotate_by), ir.Imm1(0)).result; return ir.RotateRight(ir.GetRegister(m), ir.Imm8(rotate_by), ir.Imm1(0)).result;
} }
bool ThumbTranslatorVisitor::thumb32_ASR_reg(Reg m, Reg d, Reg s) { using ShiftFunction = IR::ResultAndCarry<IR::U32> (IREmitter::*)(const IR::U32&, const IR::U8&, const IR::U1&);
bool ShiftInstruction(ThumbTranslatorVisitor& v, Reg m, Reg d, Reg s, ShiftFunction shift_fn) {
if (d == Reg::PC || m == Reg::PC || s == Reg::PC) { if (d == Reg::PC || m == Reg::PC || s == Reg::PC) {
return UnpredictableInstruction(); return v.UnpredictableInstruction();
} }
const auto shift_s = ir.LeastSignificantByte(ir.GetRegister(s)); const auto shift_s = v.ir.LeastSignificantByte(v.ir.GetRegister(s));
const auto apsr_c = ir.GetCFlag(); const auto apsr_c = v.ir.GetCFlag();
const auto result_carry = ir.ArithmeticShiftRight(ir.GetRegister(m), shift_s, apsr_c); const auto result_carry = (v.ir.*shift_fn)(v.ir.GetRegister(m), shift_s, apsr_c);
ir.SetRegister(d, result_carry.result); v.ir.SetRegister(d, result_carry.result);
return true; return true;
} }
} // Anonymous namespace
bool ThumbTranslatorVisitor::thumb32_ASR_reg(Reg m, Reg d, Reg s) {
return ShiftInstruction(*this, m, d, s, &IREmitter::ArithmeticShiftRight);
}
bool ThumbTranslatorVisitor::thumb32_LSL_reg(Reg m, Reg d, Reg s) { bool ThumbTranslatorVisitor::thumb32_LSL_reg(Reg m, Reg d, Reg s) {
if (d == Reg::PC || m == Reg::PC || s == Reg::PC) { return ShiftInstruction(*this, m, d, s, &IREmitter::LogicalShiftLeft);
return UnpredictableInstruction();
}
const auto shift_s = ir.LeastSignificantByte(ir.GetRegister(s));
const auto apsr_c = ir.GetCFlag();
const auto result_carry = ir.LogicalShiftLeft(ir.GetRegister(m), shift_s, apsr_c);
ir.SetRegister(d, result_carry.result);
return true;
} }
bool ThumbTranslatorVisitor::thumb32_LSR_reg(Reg m, Reg d, Reg s) { bool ThumbTranslatorVisitor::thumb32_LSR_reg(Reg m, Reg d, Reg s) {
if (d == Reg::PC || m == Reg::PC || s == Reg::PC) { return ShiftInstruction(*this, m, d, s, &IREmitter::LogicalShiftRight);
return UnpredictableInstruction();
}
const auto shift_s = ir.LeastSignificantByte(ir.GetRegister(s));
const auto apsr_c = ir.GetCFlag();
const auto result_carry = ir.LogicalShiftRight(ir.GetRegister(m), shift_s, apsr_c);
ir.SetRegister(d, result_carry.result);
return true;
} }
bool ThumbTranslatorVisitor::thumb32_ROR_reg(Reg m, Reg d, Reg s) { bool ThumbTranslatorVisitor::thumb32_ROR_reg(Reg m, Reg d, Reg s) {
if (d == Reg::PC || m == Reg::PC || s == Reg::PC) { return ShiftInstruction(*this, m, d, s, &IREmitter::RotateRight);
return UnpredictableInstruction();
}
const auto shift_s = ir.LeastSignificantByte(ir.GetRegister(s));
const auto apsr_c = ir.GetCFlag();
const auto result_carry = ir.RotateRight(ir.GetRegister(m), shift_s, apsr_c);
ir.SetRegister(d, result_carry.result);
return true;
} }
bool ThumbTranslatorVisitor::thumb32_SXTB(Reg d, SignExtendRotation rotate, Reg m) { bool ThumbTranslatorVisitor::thumb32_SXTB(Reg d, SignExtendRotation rotate, Reg m) {