diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index 4cf49efe..6a42ca01 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -268,7 +268,7 @@ INST(thumb32_SMULXY, "SMULXY", "111110110001nnnn1111dd INST(thumb32_SMLAXY, "SMLAXY", "111110110001nnnnaaaadddd00NMmmmm") INST(thumb32_SMUAD, "SMUAD", "111110110010nnnn1111dddd000Mmmmm") INST(thumb32_SMLAD, "SMLAD", "111110110010nnnnaaaadddd000Xmmmm") -//INST(thumb32_SMULWY, "SMULWY", "111110110011----1111----000-----") +INST(thumb32_SMULWY, "SMULWY", "111110110011nnnn1111dddd000Mmmmm") //INST(thumb32_SMLAWY, "SMLAWY", "111110110011------------000-----") INST(thumb32_SMUSD, "SMUSD", "111110110100nnnn1111dddd000Mmmmm") INST(thumb32_SMLSD, "SMLSD", "111110110100nnnnaaaadddd000Xmmmm") diff --git a/src/frontend/A32/translate/impl/thumb32_multiply.cpp b/src/frontend/A32/translate/impl/thumb32_multiply.cpp index 46c36a0f..c15190ff 100644 --- a/src/frontend/A32/translate/impl/thumb32_multiply.cpp +++ b/src/frontend/A32/translate/impl/thumb32_multiply.cpp @@ -245,6 +245,23 @@ bool ThumbTranslatorVisitor::thumb32_SMULXY(Reg n, Reg d, bool N, bool M, Reg m) return true; } +bool ThumbTranslatorVisitor::thumb32_SMULWY(Reg n, Reg d, bool M, Reg m) { + if (d == Reg::PC || n == Reg::PC || m == Reg::PC) { + return UnpredictableInstruction(); + } + + const IR::U64 n32 = ir.SignExtendWordToLong(ir.GetRegister(n)); + IR::U32 m32 = ir.GetRegister(m); + if (M) { + m32 = ir.LogicalShiftRight(m32, ir.Imm8(16), ir.Imm1(0)).result; + } + const IR::U64 m16 = ir.SignExtendWordToLong(ir.SignExtendHalfToWord(ir.LeastSignificantHalf(m32))); + const auto result = ir.LogicalShiftRight(ir.Mul(n32, m16), ir.Imm8(16)); + + ir.SetRegister(d, ir.LeastSignificantWord(result)); + return true; +} + bool ThumbTranslatorVisitor::thumb32_USAD8(Reg n, Reg d, Reg m) { if (d == 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 e62d2fbe..6aee5355 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -141,6 +141,7 @@ struct ThumbTranslatorVisitor final { bool thumb32_SMUAD(Reg n, Reg d, bool M, Reg m); bool thumb32_SMUSD(Reg n, Reg d, bool M, Reg m); bool thumb32_SMULXY(Reg n, Reg d, bool N, bool M, Reg m); + bool thumb32_SMULWY(Reg n, Reg d, bool M, Reg m); bool thumb32_USAD8(Reg n, Reg d, Reg m); bool thumb32_USADA8(Reg n, Reg a, Reg d, Reg m);