From c60cf921ee0401243e709c7861eb9c332cc7d300 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 1 Feb 2021 15:29:52 -0500 Subject: [PATCH] thumb32: Implement REV --- src/frontend/A32/decoder/thumb32.h | 2 +- src/frontend/A32/translate/impl/thumb32_misc.cpp | 11 +++++++++++ src/frontend/A32/translate/impl/translate_thumb.h | 1 + tests/A32/fuzz_thumb.cpp | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/thumb32.h b/src/frontend/A32/decoder/thumb32.h index 862ca7c1..a4213209 100644 --- a/src/frontend/A32/decoder/thumb32.h +++ b/src/frontend/A32/decoder/thumb32.h @@ -279,7 +279,7 @@ std::optional>> DecodeThumb32(u32 //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_REV, "REV", "111110101001----1111----1000----"), + INST(&V::thumb32_REV, "REV", "111110101001nnnn1111dddd1000mmmm"), INST(&V::thumb32_REV16, "REV16", "111110101001nnnn1111dddd1001mmmm"), INST(&V::thumb32_RBIT, "RBIT", "111110101001nnnn1111dddd1010mmmm"), INST(&V::thumb32_REVSH, "REVSH", "111110101001nnnn1111dddd1011mmmm"), diff --git a/src/frontend/A32/translate/impl/thumb32_misc.cpp b/src/frontend/A32/translate/impl/thumb32_misc.cpp index dcf16b9d..0d856c50 100644 --- a/src/frontend/A32/translate/impl/thumb32_misc.cpp +++ b/src/frontend/A32/translate/impl/thumb32_misc.cpp @@ -44,6 +44,17 @@ bool ThumbTranslatorVisitor::thumb32_RBIT(Reg n, Reg d, Reg m) { return true; } +bool ThumbTranslatorVisitor::thumb32_REV(Reg n, Reg d, Reg m) { + if (m != n || d == Reg::PC || m == Reg::PC) { + return UnpredictableInstruction(); + } + + const auto result = ir.ByteReverseWord(ir.GetRegister(m)); + + ir.SetRegister(d, result); + return true; +} + bool ThumbTranslatorVisitor::thumb32_REV16(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 0965e28f..d5a8f63f 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -119,6 +119,7 @@ struct ThumbTranslatorVisitor final { // thumb32 miscellaneous instructions bool thumb32_CLZ(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); bool thumb32_REVSH(Reg n, Reg d, Reg m); bool thumb32_SEL(Reg n, Reg d, Reg m); diff --git a/tests/A32/fuzz_thumb.cpp b/tests/A32/fuzz_thumb.cpp index 5a4d87d0..e6b4dbd3 100644 --- a/tests/A32/fuzz_thumb.cpp +++ b/tests/A32/fuzz_thumb.cpp @@ -376,6 +376,13 @@ TEST_CASE("Fuzz Thumb32 instructions set", "[JitX64][Thumb][Thumb32]") { const auto n = Common::Bits<16, 19>(inst); return m == n && d != 15 && m != 15; }), + ThumbInstGen("111110101001nnnn1111dddd1000mmmm", // REV + [](u32 inst) { + const auto d = Common::Bits<8, 11>(inst); + const auto m = Common::Bits<0, 3>(inst); + const auto n = Common::Bits<16, 19>(inst); + return m == n && d != 15 && m != 15; + }), ThumbInstGen("111110101001nnnn1111dddd1001mmmm", // REV16 [](u32 inst) { const auto d = Common::Bits<8, 11>(inst);