From 5859105a613498066c4da398fdc7e2c40c7a2e7e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 7 Feb 2021 17:32:11 -0500 Subject: [PATCH] thumb32: Implement SMLAL --- src/frontend/A32/decoder/thumb32.inc | 2 +- .../translate/impl/thumb32_long_multiply.cpp | 22 +++++++++++++++++++ .../A32/translate/impl/translate_thumb.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index 7cae4fe2..8dd232a5 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -283,7 +283,7 @@ INST(thumb32_SMULL, "SMULL", "111110111000nnnnllllhh //INST(thumb32_SDIV, "SDIV", "111110111001------------1111----") INST(thumb32_UMULL, "UMULL", "111110111010nnnnllllhhhh0000mmmm") //INST(thumb32_UDIV, "UDIV", "111110111011------------1111----") -//INST(thumb32_SMLAL, "SMLAL", "111110111100------------0000----") +INST(thumb32_SMLAL, "SMLAL", "111110111100nnnnllllhhhh0000mmmm") //INST(thumb32_SMLALXY, "SMLALXY", "111110111100------------10------") //INST(thumb32_SMLALD, "SMLALD", "111110111100------------110-----") //INST(thumb32_SMLSLD, "SMLSLD", "111110111101------------110-----") diff --git a/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp b/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp index d1c9f044..13e1b3ec 100644 --- a/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp +++ b/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp @@ -7,6 +7,28 @@ namespace Dynarmic::A32 { +bool ThumbTranslatorVisitor::thumb32_SMLAL(Reg n, Reg dLo, Reg dHi, Reg m) { + if (dLo == Reg::PC || dHi == Reg::PC || n == Reg::PC || m == Reg::PC) { + return UnpredictableInstruction(); + } + + if (dHi == dLo) { + return UnpredictableInstruction(); + } + + const auto n64 = ir.SignExtendWordToLong(ir.GetRegister(n)); + const auto m64 = ir.SignExtendWordToLong(ir.GetRegister(m)); + const auto product = ir.Mul(n64, m64); + const auto addend = ir.Pack2x32To1x64(ir.GetRegister(dLo), ir.GetRegister(dHi)); + const auto result = ir.Add(product, addend); + const auto lo = ir.LeastSignificantWord(result); + const auto hi = ir.MostSignificantWord(result).result; + + ir.SetRegister(dLo, lo); + ir.SetRegister(dHi, hi); + 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 86598a26..69d87d5e 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -117,6 +117,7 @@ struct ThumbTranslatorVisitor final { bool thumb32_UDF(); // thumb32 long multiply, long multiply accumulate, and divide instructions + bool thumb32_SMLAL(Reg n, Reg dLo, Reg dHi, Reg m); bool thumb32_SMULL(Reg n, Reg dLo, Reg dHi, Reg m); bool thumb32_UMULL(Reg n, Reg dLo, Reg dHi, Reg m);