From 6cf47e0ce0efc76a683fa546c40d34cff5222fb0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 7 Feb 2021 17:16:05 -0500 Subject: [PATCH] thumb32: Implement SMULL --- src/CMakeLists.txt | 1 + src/frontend/A32/decoder/thumb32.inc | 2 +- .../translate/impl/thumb32_long_multiply.cpp | 30 +++++++++++++++++++ .../A32/translate/impl/translate_thumb.h | 3 ++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/frontend/A32/translate/impl/thumb32_long_multiply.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e3ea5c2..300393f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -152,6 +152,7 @@ if ("A32" IN_LIST DYNARMIC_FRONTENDS) frontend/A32/translate/impl/synchronization.cpp frontend/A32/translate/impl/thumb16.cpp frontend/A32/translate/impl/thumb32.cpp + frontend/A32/translate/impl/thumb32_long_multiply.cpp frontend/A32/translate/impl/thumb32_misc.cpp frontend/A32/translate/impl/thumb32_multiply.cpp frontend/A32/translate/impl/thumb32_parallel.cpp diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index d7b8b953..cd61274d 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -279,7 +279,7 @@ INST(thumb32_USAD8, "USAD8", "111110110111nnnn1111dd INST(thumb32_USADA8, "USADA8", "111110110111nnnnaaaadddd0000mmmm") // Long Multiply, Long Multiply Accumulate, and Divide -//INST(thumb32_SMULL, "SMULL", "111110111000------------0000----") +INST(thumb32_SMULL, "SMULL", "111110111000nnnnllllhhhh0000mmmm") //INST(thumb32_SDIV, "SDIV", "111110111001------------1111----") //INST(thumb32_UMULL, "UMULL", "111110111010------------0000----") //INST(thumb32_UDIV, "UDIV", "111110111011------------1111----") diff --git a/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp b/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp new file mode 100644 index 00000000..921d8638 --- /dev/null +++ b/src/frontend/A32/translate/impl/thumb32_long_multiply.cpp @@ -0,0 +1,30 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2021 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#include "frontend/A32/translate/impl/translate_thumb.h" + +namespace Dynarmic::A32 { + +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(); + } + + if (dHi == dLo) { + return UnpredictableInstruction(); + } + + const auto n64 = ir.SignExtendWordToLong(ir.GetRegister(n)); + const auto m64 = ir.SignExtendWordToLong(ir.GetRegister(m)); + const auto result = ir.Mul(n64, m64); + const auto lo = ir.LeastSignificantWord(result); + const auto hi = ir.MostSignificantWord(result).result; + + ir.SetRegister(dLo, lo); + ir.SetRegister(dHi, hi); + 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 24b449cc..7599bca9 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -116,6 +116,9 @@ struct ThumbTranslatorVisitor final { bool thumb32_BLX_imm(Imm<11> hi, Imm<11> lo); bool thumb32_UDF(); + // thumb32 long multiply, long multiply accumulate, and divide instructions + bool thumb32_SMULL(Reg n, Reg dLo, Reg dHi, Reg m); + // thumb32 miscellaneous instructions bool thumb32_CLZ(Reg n, Reg d, Reg m); bool thumb32_QADD(Reg n, Reg d, Reg m);