diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index 6a42ca01..d7b8b953 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -269,7 +269,7 @@ INST(thumb32_SMLAXY, "SMLAXY", "111110110001nnnnaaaadd INST(thumb32_SMUAD, "SMUAD", "111110110010nnnn1111dddd000Mmmmm") INST(thumb32_SMLAD, "SMLAD", "111110110010nnnnaaaadddd000Xmmmm") INST(thumb32_SMULWY, "SMULWY", "111110110011nnnn1111dddd000Mmmmm") -//INST(thumb32_SMLAWY, "SMLAWY", "111110110011------------000-----") +INST(thumb32_SMLAWY, "SMLAWY", "111110110011nnnnaaaadddd000Mmmmm") INST(thumb32_SMUSD, "SMUSD", "111110110100nnnn1111dddd000Mmmmm") INST(thumb32_SMLSD, "SMLSD", "111110110100nnnnaaaadddd000Xmmmm") INST(thumb32_SMMUL, "SMMUL", "111110110101nnnn1111dddd000Rmmmm") diff --git a/src/frontend/A32/translate/impl/thumb32_multiply.cpp b/src/frontend/A32/translate/impl/thumb32_multiply.cpp index c15190ff..13143949 100644 --- a/src/frontend/A32/translate/impl/thumb32_multiply.cpp +++ b/src/frontend/A32/translate/impl/thumb32_multiply.cpp @@ -245,6 +245,25 @@ bool ThumbTranslatorVisitor::thumb32_SMULXY(Reg n, Reg d, bool N, bool M, Reg m) return true; } +bool ThumbTranslatorVisitor::thumb32_SMLAWY(Reg n, Reg a, Reg d, bool M, Reg m) { + if (d == Reg::PC || n == Reg::PC || m == Reg::PC || a == 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 product = ir.LeastSignificantWord(ir.LogicalShiftRight(ir.Mul(n32, m16), ir.Imm8(16))); + const auto result_overflow = ir.AddWithCarry(product, ir.GetRegister(a), ir.Imm1(0)); + + ir.SetRegister(d, result_overflow.result); + ir.OrQFlag(result_overflow.overflow); + 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(); diff --git a/src/frontend/A32/translate/impl/translate_thumb.h b/src/frontend/A32/translate/impl/translate_thumb.h index 6aee5355..24b449cc 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -134,6 +134,7 @@ struct ThumbTranslatorVisitor final { bool thumb32_MUL(Reg n, Reg d, Reg m); bool thumb32_SMLAD(Reg n, Reg a, Reg d, bool X, Reg m); bool thumb32_SMLAXY(Reg n, Reg a, Reg d, bool N, bool M, Reg m); + bool thumb32_SMLAWY(Reg n, Reg a, Reg d, bool M, Reg m); bool thumb32_SMLSD(Reg n, Reg a, Reg d, bool X, Reg m); bool thumb32_SMMLA(Reg n, Reg a, Reg d, bool R, Reg m); bool thumb32_SMMLS(Reg n, Reg a, Reg d, bool R, Reg m);