From 87cb771bd2f35a0750423fe4dc4a2b9c37bf68c7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 7 Feb 2021 17:37:26 -0500 Subject: [PATCH] thumb32: Implement SMLALXY --- src/frontend/A32/decoder/thumb32.inc | 2 +- .../translate/impl/thumb32_long_multiply.cpp | 24 +++++++++++++++++++ .../A32/translate/impl/translate_thumb.h | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index c5421c69..a5e82003 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -284,7 +284,7 @@ INST(thumb32_SMULL, "SMULL", "111110111000nnnnllllhh INST(thumb32_UMULL, "UMULL", "111110111010nnnnllllhhhh0000mmmm") //INST(thumb32_UDIV, "UDIV", "111110111011------------1111----") INST(thumb32_SMLAL, "SMLAL", "111110111100nnnnllllhhhh0000mmmm") -//INST(thumb32_SMLALXY, "SMLALXY", "111110111100------------10------") +INST(thumb32_SMLALXY, "SMLALXY", "111110111100nnnnllllhhhh10NMmmmm") //INST(thumb32_SMLALD, "SMLALD", "111110111100------------110-----") //INST(thumb32_SMLSLD, "SMLSLD", "111110111101------------110-----") INST(thumb32_UMLAL, "UMLAL", "111110111110nnnnllllhhhh0000mmmm") diff --git a/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp b/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp index 7c607b71..5d89bd52 100644 --- a/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp +++ b/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp @@ -29,6 +29,30 @@ bool ThumbTranslatorVisitor::thumb32_SMLAL(Reg n, Reg dLo, Reg dHi, Reg m) { return true; } +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) { + return UnpredictableInstruction(); + } + + if (dHi == dLo) { + return UnpredictableInstruction(); + } + + const IR::U32 n32 = ir.GetRegister(n); + const IR::U32 m32 = ir.GetRegister(m); + const IR::U32 n16 = N ? ir.ArithmeticShiftRight(n32, ir.Imm8(16), ir.Imm1(0)).result + : ir.SignExtendHalfToWord(ir.LeastSignificantHalf(n32)); + const IR::U32 m16 = M ? ir.ArithmeticShiftRight(m32, ir.Imm8(16), ir.Imm1(0)).result + : ir.SignExtendHalfToWord(ir.LeastSignificantHalf(m32)); + const IR::U64 product = ir.SignExtendWordToLong(ir.Mul(n16, m16)); + const auto addend = ir.Pack2x32To1x64(ir.GetRegister(dLo), ir.GetRegister(dHi)); + const auto result = ir.Add(product, addend); + + ir.SetRegister(dLo, ir.LeastSignificantWord(result)); + ir.SetRegister(dHi, ir.MostSignificantWord(result).result); + return true; +} + bool ThumbTranslatorVisitor::thumb32_SMULL(Reg n, Reg dLo, Reg dHi, Reg m) { if (dLo == Reg::PC || dHi == Reg::PC || n == Reg::PC || m == Reg::PC) { return UnpredictableInstruction(); diff --git a/src/frontend/A32/translate/impl/translate_thumb.h b/src/frontend/A32/translate/impl/translate_thumb.h index d5c7d3a1..22a3fd88 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -118,6 +118,7 @@ struct ThumbTranslatorVisitor final { // thumb32 long multiply, long multiply accumulate, and divide instructions bool thumb32_SMLAL(Reg n, Reg dLo, Reg dHi, 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_UMLAL(Reg n, Reg dLo, Reg dHi, Reg m); bool thumb32_UMULL(Reg n, Reg dLo, Reg dHi, Reg m);