From e1b4ff1068e2e988dcc11101ae3fd471d332defb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 10 Apr 2019 15:05:56 -0400 Subject: [PATCH] simd_scalar_shift_by_immediate: Migrate SQSHL implementation to file-scope function This will allow it to be reused for the implementation of UQSHL. --- .../impl/simd_scalar_shift_by_immediate.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp b/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp index 57a3d146..1135ad88 100644 --- a/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp +++ b/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp @@ -30,6 +30,22 @@ enum class FloatConversionDirection { FloatToFixed, }; +bool SaturatingShiftLeft(TranslatorVisitor& v, Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { + if (immh == 0b0000) { + return v.UnallocatedEncoding(); + } + + const size_t esize = 8U << Common::HighestSetBit(immh.ZeroExtend()); + const size_t shift_amount = concatenate(immh, immb).ZeroExtend() - esize; + + const IR::U128 operand = v.ir.ZeroExtendToQuad(v.V_scalar(esize, Vn)); + const IR::U128 shift = v.ir.ZeroExtendToQuad(v.I(esize, shift_amount)); + const IR::U128 result = v.ir.VectorSignedSaturatedShiftLeft(esize, operand, shift); + + v.ir.SetQ(Vd, result); + return true; +} + bool ShiftRight(TranslatorVisitor& v, Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd, ShiftExtraBehavior behavior, Signedness signedness) { if (!immh.Bit<3>()) { @@ -254,19 +270,7 @@ bool TranslatorVisitor::SRI_1(Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { } bool TranslatorVisitor::SQSHL_imm_1(Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { - if (immh == 0b0000) { - return UnallocatedEncoding(); - } - - const size_t esize = 8U << Common::HighestSetBit(immh.ZeroExtend()); - const size_t shift_amount = concatenate(immh, immb).ZeroExtend() - esize; - - const IR::U128 operand = ir.ZeroExtendToQuad(V_scalar(esize, Vn)); - const IR::U128 shift = ir.ZeroExtendToQuad(I(esize, shift_amount)); - const IR::U128 result = ir.VectorSignedSaturatedShiftLeft(esize, operand, shift); - - ir.SetQ(Vd, result); - return true; + return SaturatingShiftLeft(*this, immh, immb, Vn, Vd); } bool TranslatorVisitor::SQSHRN_1(Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) {