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) {