From d96c8c662b1d63bc8976abacb2f83ffc9e140d86 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 1 Feb 2021 15:35:09 -0500 Subject: [PATCH] thumb32: Implement QDSUB --- src/frontend/A32/decoder/thumb32.h | 2 +- src/frontend/A32/translate/impl/thumb32_misc.cpp | 16 ++++++++++++++++ .../A32/translate/impl/translate_thumb.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/thumb32.h b/src/frontend/A32/decoder/thumb32.h index a4213209..96ab0e8f 100644 --- a/src/frontend/A32/decoder/thumb32.h +++ b/src/frontend/A32/decoder/thumb32.h @@ -278,7 +278,7 @@ std::optional>> DecodeThumb32(u32 //INST(&V::thumb32_QADD, "QADD", "111110101000----1111----1000----"), //INST(&V::thumb32_QDADD, "QDADD", "111110101000----1111----1001----"), //INST(&V::thumb32_QSUB, "QSUB", "111110101000----1111----1010----"), - //INST(&V::thumb32_QDSUB, "QDSUB", "111110101000----1111----1011----"), + INST(&V::thumb32_QDSUB, "QDSUB", "111110101000nnnn1111dddd1011mmmm"), INST(&V::thumb32_REV, "REV", "111110101001nnnn1111dddd1000mmmm"), INST(&V::thumb32_REV16, "REV16", "111110101001nnnn1111dddd1001mmmm"), INST(&V::thumb32_RBIT, "RBIT", "111110101001nnnn1111dddd1010mmmm"), diff --git a/src/frontend/A32/translate/impl/thumb32_misc.cpp b/src/frontend/A32/translate/impl/thumb32_misc.cpp index 0d856c50..f443139f 100644 --- a/src/frontend/A32/translate/impl/thumb32_misc.cpp +++ b/src/frontend/A32/translate/impl/thumb32_misc.cpp @@ -19,6 +19,22 @@ bool ThumbTranslatorVisitor::thumb32_CLZ(Reg n, Reg d, Reg m) { return true; } +bool ThumbTranslatorVisitor::thumb32_QDSUB(Reg n, Reg d, Reg m) { + if (d == Reg::PC || n == Reg::PC || m == Reg::PC) { + return UnpredictableInstruction(); + } + + const auto reg_m = ir.GetRegister(m); + const auto reg_n = ir.GetRegister(n); + const auto doubled_n = ir.SignedSaturatedAdd(reg_n, reg_n); + ir.OrQFlag(doubled_n.overflow); + + const auto result = ir.SignedSaturatedSub(reg_m, doubled_n.result); + ir.SetRegister(d, result.result); + ir.OrQFlag(result.overflow); + return true; +} + bool ThumbTranslatorVisitor::thumb32_RBIT(Reg n, Reg d, Reg m) { if (m != n || d == 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 d5a8f63f..e9ab940f 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -118,6 +118,7 @@ struct ThumbTranslatorVisitor final { // thumb32 miscellaneous instructions bool thumb32_CLZ(Reg n, Reg d, Reg m); + bool thumb32_QDSUB(Reg n, Reg d, Reg m); bool thumb32_RBIT(Reg n, Reg d, Reg m); bool thumb32_REV(Reg n, Reg d, Reg m); bool thumb32_REV16(Reg n, Reg d, Reg m);