@@ -736,25 +736,6 @@ static bool interp__builtin_expect(InterpState &S, CodePtr OpPC,
736736 return true ;
737737}
738738
739- // / rotateleft(value, amount)
740- static bool interp__builtin_rotate (InterpState &S, CodePtr OpPC,
741- const InterpFrame *Frame,
742- const CallExpr *Call, bool Right) {
743- APSInt Amount = popToAPSInt (S, Call->getArg (1 ));
744- APSInt Value = popToAPSInt (S, Call->getArg (0 ));
745-
746- APSInt Result;
747- if (Right)
748- Result = APSInt (Value.rotr (Amount.urem (Value.getBitWidth ())),
749- /* IsUnsigned=*/ true );
750- else // Left.
751- Result = APSInt (Value.rotl (Amount.urem (Value.getBitWidth ())),
752- /* IsUnsigned=*/ true );
753-
754- pushInteger (S, Result, Call->getType ());
755- return true ;
756- }
757-
758739static bool interp__builtin_ffs (InterpState &S, CodePtr OpPC,
759740 const InterpFrame *Frame,
760741 const CallExpr *Call) {
@@ -3160,7 +3141,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
31603141 case Builtin::BI_rotl:
31613142 case Builtin::BI_lrotl:
31623143 case Builtin::BI_rotl64:
3163- return interp__builtin_rotate (S, OpPC, Frame, Call, /* Right=*/ false );
3144+ return interp__builtin_elementwise_int_binop (
3145+ S, OpPC, Call, [](const APSInt &Value, const APSInt &Amount) -> APInt {
3146+ return Value.rotl (Amount);
3147+ });
31643148
31653149 case Builtin::BI__builtin_rotateright8:
31663150 case Builtin::BI__builtin_rotateright16:
@@ -3171,7 +3155,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
31713155 case Builtin::BI_rotr:
31723156 case Builtin::BI_lrotr:
31733157 case Builtin::BI_rotr64:
3174- return interp__builtin_rotate (S, OpPC, Frame, Call, /* Right=*/ true );
3158+ return interp__builtin_elementwise_int_binop (
3159+ S, OpPC, Call, [](const APSInt &Value, const APSInt &Amount) -> APInt {
3160+ return Value.rotr (Amount);
3161+ });
31753162
31763163 case Builtin::BI__builtin_ffs:
31773164 case Builtin::BI__builtin_ffsl:
0 commit comments