From 16613ee06699ce7f6a490f12c44222aa610fc1a7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 3 Apr 2018 16:04:17 -0400 Subject: [PATCH] A64: Implement RSHRN/RSHRN2 --- src/frontend/A64/decoder/a64.inc | 2 +- .../impl/simd_shift_by_immediate.cpp | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/frontend/A64/decoder/a64.inc b/src/frontend/A64/decoder/a64.inc index 1992259d..122ed539 100644 --- a/src/frontend/A64/decoder/a64.inc +++ b/src/frontend/A64/decoder/a64.inc @@ -796,7 +796,7 @@ INST(SSRA_2, "SSRA", "0Q001 INST(SHL_2, "SHL", "0Q0011110IIIIiii010101nnnnnddddd") //INST(SQSHL_imm_2, "SQSHL (immediate)", "0Q0011110IIIIiii011101nnnnnddddd") INST(SHRN, "SHRN, SHRN2", "0Q0011110IIIIiii100001nnnnnddddd") -//INST(RSHRN, "RSHRN, RSHRN2", "0Q0011110IIIIiii100011nnnnnddddd") +INST(RSHRN, "RSHRN, RSHRN2", "0Q0011110IIIIiii100011nnnnnddddd") //INST(SQSHRN_2, "SQSHRN, SQSHRN2", "0Q0011110IIIIiii100101nnnnnddddd") //INST(SQRSHRN_2, "SQRSHRN, SQRSHRN2", "0Q0011110IIIIiii100111nnnnnddddd") INST(SSHLL, "SSHLL, SSHLL2", "0Q0011110IIIIiii101001nnnnnddddd") diff --git a/src/frontend/A64/translate/impl/simd_shift_by_immediate.cpp b/src/frontend/A64/translate/impl/simd_shift_by_immediate.cpp index 4e1fe051..06bc7475 100644 --- a/src/frontend/A64/translate/impl/simd_shift_by_immediate.cpp +++ b/src/frontend/A64/translate/impl/simd_shift_by_immediate.cpp @@ -91,6 +91,33 @@ bool TranslatorVisitor::SHRN(bool Q, Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { return true; } +bool TranslatorVisitor::RSHRN(bool Q, Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { + if (immh == 0b0000) { + return DecodeError(); + } + + if (immh.Bit<3>()) { + return ReservedValue(); + } + + const size_t esize = 8 << Common::HighestSetBit(immh.ZeroExtend()); + const size_t source_esize = 2 * esize; + const size_t part = Q ? 1 : 0; + + const u8 shift_amount = static_cast(source_esize - concatenate(immh, immb).ZeroExtend()); + const u64 round_const = 1ULL << (shift_amount - 1); + + const IR::U128 operand = ir.GetQ(Vn); + const IR::U128 round_operand = ir.VectorBroadcast(source_esize, I(source_esize, round_const)); + const IR::U128 rounded_value = ir.VectorAdd(source_esize, operand, round_operand); + + const IR::U128 result = ir.VectorNarrow(source_esize, + ir.VectorLogicalShiftRight(source_esize, rounded_value, shift_amount)); + + Vpart(64, Vd, part, result); + return true; +} + bool TranslatorVisitor::SSHLL(bool Q, Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { if (immh == 0b0000) { return DecodeError();