@@ -678,30 +678,6 @@ static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
678
678
return true ;
679
679
}
680
680
681
- static bool interp__builtin_parity (InterpState &S, CodePtr OpPC,
682
- const InterpFrame *Frame,
683
- const CallExpr *Call) {
684
- APSInt Val = popToAPSInt (S, Call->getArg (0 ));
685
- pushInteger (S, Val.popcount () % 2 , Call->getType ());
686
- return true ;
687
- }
688
-
689
- static bool interp__builtin_clrsb (InterpState &S, CodePtr OpPC,
690
- const InterpFrame *Frame,
691
- const CallExpr *Call) {
692
- APSInt Val = popToAPSInt (S, Call->getArg (0 ));
693
- pushInteger (S, Val.getBitWidth () - Val.getSignificantBits (), Call->getType ());
694
- return true ;
695
- }
696
-
697
- static bool interp__builtin_bitreverse (InterpState &S, CodePtr OpPC,
698
- const InterpFrame *Frame,
699
- const CallExpr *Call) {
700
- APSInt Val = popToAPSInt (S, Call->getArg (0 ));
701
- pushInteger (S, Val.reverseBits (), Call->getType ());
702
- return true ;
703
- }
704
-
705
681
static bool interp__builtin_classify_type (InterpState &S, CodePtr OpPC,
706
682
const InterpFrame *Frame,
707
683
const CallExpr *Call) {
@@ -736,16 +712,6 @@ static bool interp__builtin_expect(InterpState &S, CodePtr OpPC,
736
712
return true ;
737
713
}
738
714
739
- static bool interp__builtin_ffs (InterpState &S, CodePtr OpPC,
740
- const InterpFrame *Frame,
741
- const CallExpr *Call) {
742
- APSInt Value = popToAPSInt (S, Call->getArg (0 ));
743
-
744
- uint64_t N = Value.countr_zero ();
745
- pushInteger (S, N == Value.getBitWidth () ? 0 : N + 1 , Call->getType ());
746
- return true ;
747
- }
748
-
749
715
static bool interp__builtin_addressof (InterpState &S, CodePtr OpPC,
750
716
const InterpFrame *Frame,
751
717
const CallExpr *Call) {
@@ -3158,18 +3124,25 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
3158
3124
case Builtin::BI__builtin_parity:
3159
3125
case Builtin::BI__builtin_parityl:
3160
3126
case Builtin::BI__builtin_parityll:
3161
- return interp__builtin_parity (S, OpPC, Frame, Call);
3162
-
3127
+ return interp__builtin_elementwise_int_unaryop (
3128
+ S, OpPC, Call, [](const APSInt &Val) -> APInt {
3129
+ return APInt (Val.getBitWidth (), Val.popcount () % 2 );
3130
+ });
3163
3131
case Builtin::BI__builtin_clrsb:
3164
3132
case Builtin::BI__builtin_clrsbl:
3165
3133
case Builtin::BI__builtin_clrsbll:
3166
- return interp__builtin_clrsb (S, OpPC, Frame, Call);
3167
-
3134
+ return interp__builtin_elementwise_int_unaryop (
3135
+ S, OpPC, Call, [](const APSInt &Val) -> APInt {
3136
+ return APInt (Val.getBitWidth (),
3137
+ Val.getBitWidth () - Val.getSignificantBits ());
3138
+ });
3168
3139
case Builtin::BI__builtin_bitreverse8:
3169
3140
case Builtin::BI__builtin_bitreverse16:
3170
3141
case Builtin::BI__builtin_bitreverse32:
3171
3142
case Builtin::BI__builtin_bitreverse64:
3172
- return interp__builtin_bitreverse (S, OpPC, Frame, Call);
3143
+ return interp__builtin_elementwise_int_unaryop (
3144
+ S, OpPC, Call,
3145
+ [](const APSInt &Val) -> APInt { return Val.reverseBits (); });
3173
3146
3174
3147
case Builtin::BI__builtin_classify_type:
3175
3148
return interp__builtin_classify_type (S, OpPC, Frame, Call);
@@ -3209,7 +3182,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
3209
3182
case Builtin::BI__builtin_ffs:
3210
3183
case Builtin::BI__builtin_ffsl:
3211
3184
case Builtin::BI__builtin_ffsll:
3212
- return interp__builtin_ffs (S, OpPC, Frame, Call);
3185
+ return interp__builtin_elementwise_int_unaryop (
3186
+ S, OpPC, Call, [](const APSInt &Val) {
3187
+ return APInt (Val.getBitWidth (),
3188
+ Val.isZero () ? 0u : Val.countTrailingZeros () + 1u );
3189
+ });
3213
3190
3214
3191
case Builtin::BIaddressof:
3215
3192
case Builtin::BI__addressof:
0 commit comments