thumb32: Implement SMLALD{X}

This commit is contained in:
Lioncash 2021-02-07 17:40:34 -05:00
parent 87cb771bd2
commit fe3deb1831
3 changed files with 32 additions and 1 deletions

View file

@ -285,7 +285,7 @@ INST(thumb32_UMULL, "UMULL", "111110111010nnnnllllhh
//INST(thumb32_UDIV, "UDIV", "111110111011------------1111----") //INST(thumb32_UDIV, "UDIV", "111110111011------------1111----")
INST(thumb32_SMLAL, "SMLAL", "111110111100nnnnllllhhhh0000mmmm") INST(thumb32_SMLAL, "SMLAL", "111110111100nnnnllllhhhh0000mmmm")
INST(thumb32_SMLALXY, "SMLALXY", "111110111100nnnnllllhhhh10NMmmmm") INST(thumb32_SMLALXY, "SMLALXY", "111110111100nnnnllllhhhh10NMmmmm")
//INST(thumb32_SMLALD, "SMLALD", "111110111100------------110-----") INST(thumb32_SMLALD, "SMLALD", "111110111100nnnnllllhhhh110Mmmmm")
//INST(thumb32_SMLSLD, "SMLSLD", "111110111101------------110-----") //INST(thumb32_SMLSLD, "SMLSLD", "111110111101------------110-----")
INST(thumb32_UMLAL, "UMLAL", "111110111110nnnnllllhhhh0000mmmm") INST(thumb32_UMLAL, "UMLAL", "111110111110nnnnllllhhhh0000mmmm")
//INST(thumb32_UMAAL, "UMAAL", "111110111110------------0110----") //INST(thumb32_UMAAL, "UMAAL", "111110111110------------0110----")

View file

@ -29,6 +29,36 @@ bool ThumbTranslatorVisitor::thumb32_SMLAL(Reg n, Reg dLo, Reg dHi, Reg m) {
return true; return true;
} }
bool ThumbTranslatorVisitor::thumb32_SMLALD(Reg n, Reg dLo, Reg dHi, bool M, Reg m) {
if (dLo == Reg::PC || dHi == Reg::PC || n == Reg::PC || m == Reg::PC) {
return UnpredictableInstruction();
}
if (dHi == dLo) {
return UnpredictableInstruction();
}
const IR::U32 n32 = ir.GetRegister(n);
const IR::U32 m32 = ir.GetRegister(m);
const IR::U32 n_lo = ir.SignExtendHalfToWord(ir.LeastSignificantHalf(n32));
const IR::U32 n_hi = ir.ArithmeticShiftRight(n32, ir.Imm8(16), ir.Imm1(0)).result;
IR::U32 m_lo = ir.SignExtendHalfToWord(ir.LeastSignificantHalf(m32));
IR::U32 m_hi = ir.ArithmeticShiftRight(m32, ir.Imm8(16), ir.Imm1(0)).result;
if (M) {
std::swap(m_lo, m_hi);
}
const IR::U64 product_lo = ir.SignExtendWordToLong(ir.Mul(n_lo, m_lo));
const IR::U64 product_hi = ir.SignExtendWordToLong(ir.Mul(n_hi, m_hi));
const auto addend = ir.Pack2x32To1x64(ir.GetRegister(dLo), ir.GetRegister(dHi));
const auto result = ir.Add(ir.Add(product_lo, product_hi), addend);
ir.SetRegister(dLo, ir.LeastSignificantWord(result));
ir.SetRegister(dHi, ir.MostSignificantWord(result).result);
return true;
}
bool ThumbTranslatorVisitor::thumb32_SMLALXY(Reg n, Reg dLo, Reg dHi, bool N, bool M, Reg m) { bool ThumbTranslatorVisitor::thumb32_SMLALXY(Reg n, Reg dLo, Reg dHi, bool N, bool M, Reg m) {
if (dLo == Reg::PC || dHi == Reg::PC || n == Reg::PC || m == Reg::PC) { if (dLo == Reg::PC || dHi == Reg::PC || n == Reg::PC || m == Reg::PC) {
return UnpredictableInstruction(); return UnpredictableInstruction();

View file

@ -118,6 +118,7 @@ struct ThumbTranslatorVisitor final {
// thumb32 long multiply, long multiply accumulate, and divide instructions // thumb32 long multiply, long multiply accumulate, and divide instructions
bool thumb32_SMLAL(Reg n, Reg dLo, Reg dHi, Reg m); bool thumb32_SMLAL(Reg n, Reg dLo, Reg dHi, Reg m);
bool thumb32_SMLALD(Reg n, Reg dLo, Reg dHi, bool M, Reg m);
bool thumb32_SMLALXY(Reg n, Reg dLo, Reg dHi, bool N, bool M, Reg m); bool thumb32_SMLALXY(Reg n, Reg dLo, Reg dHi, bool N, bool M, Reg m);
bool thumb32_SMULL(Reg n, Reg dLo, Reg dHi, Reg m); bool thumb32_SMULL(Reg n, Reg dLo, Reg dHi, Reg m);
bool thumb32_UMLAL(Reg n, Reg dLo, Reg dHi, Reg m); bool thumb32_UMLAL(Reg n, Reg dLo, Reg dHi, Reg m);