From 50d81f95e5e38dea22b03be1c482df61dd85db8a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 6 Feb 2021 19:01:14 -0500 Subject: [PATCH] thumb32: Implement USADA8 --- src/frontend/A32/decoder/thumb32.inc | 2 +- .../A32/translate/impl/thumb32_multiply.cpp | 15 +++++++++++++++ src/frontend/A32/translate/impl/translate_thumb.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index 8b8b8a99..63b1942b 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -276,7 +276,7 @@ INST(thumb32_MLS, "MLS", "111110110000nnnnaaaadd //INST(thumb32_SMMLA, "SMMLA", "111110110101------------000-----") //INST(thumb32_SMMLS, "SMMLS", "111110110110------------000-----") INST(thumb32_USAD8, "USAD8", "111110110111nnnn1111dddd0000mmmm") -//INST(thumb32_USADA8, "USADA8", "111110110111------------0000----") +INST(thumb32_USADA8, "USADA8", "111110110111nnnnaaaadddd0000mmmm") // Long Multiply, Long Multiply Accumulate, and Divide //INST(thumb32_SMULL, "SMULL", "111110111000------------0000----") diff --git a/src/frontend/A32/translate/impl/thumb32_multiply.cpp b/src/frontend/A32/translate/impl/thumb32_multiply.cpp index 2a25be52..ecaee5a7 100644 --- a/src/frontend/A32/translate/impl/thumb32_multiply.cpp +++ b/src/frontend/A32/translate/impl/thumb32_multiply.cpp @@ -61,4 +61,19 @@ bool ThumbTranslatorVisitor::thumb32_USAD8(Reg n, Reg d, Reg m) { return true; } +bool ThumbTranslatorVisitor::thumb32_USADA8(Reg n, Reg a, Reg d, Reg m) { + if (d == Reg::PC || n == Reg::PC || m == Reg::PC) { + return UnpredictableInstruction(); + } + + const auto reg_a = ir.GetRegister(a); + const auto reg_m = ir.GetRegister(m); + const auto reg_n = ir.GetRegister(n); + const auto tmp = ir.PackedAbsDiffSumS8(reg_n, reg_m); + const auto result = ir.AddWithCarry(reg_a, tmp, ir.Imm1(0)); + + ir.SetRegister(d, result.result); + return true; +} + } // namespace Dynarmic::A32 diff --git a/src/frontend/A32/translate/impl/translate_thumb.h b/src/frontend/A32/translate/impl/translate_thumb.h index 9fbb3092..185665ad 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -133,6 +133,7 @@ struct ThumbTranslatorVisitor final { bool thumb32_MLS(Reg n, Reg a, Reg d, Reg m); bool thumb32_MUL(Reg n, Reg d, Reg m); bool thumb32_USAD8(Reg n, Reg d, Reg m); + bool thumb32_USADA8(Reg n, Reg a, Reg d, Reg m); // thumb32 parallel add/sub instructions bool thumb32_SADD8(Reg n, Reg d, Reg m);