@@ -3003,35 +3003,6 @@ static bool interp__builtin_x86_insert_subvector(InterpState &S, CodePtr OpPC,
30033003 return true ;
30043004}
30053005
3006- static bool interp__builtin_ia32_psign_op (InterpState &S, CodePtr OpPC,
3007- const CallExpr *Call) {
3008- assert (Call->getNumArgs () == 2 );
3009-
3010- const Pointer &B = S.Stk .pop <Pointer>();
3011- const Pointer &A = S.Stk .pop <Pointer>();
3012- const Pointer &Result = S.Stk .peek <Pointer>();
3013-
3014- unsigned ResultLen = A.getNumElems ();
3015- QualType ElemQT = getElemType (A);
3016- OptPrimType ElemT = S.getContext ().classify (ElemQT);
3017- unsigned ElemBitWidth = S.getASTContext ().getTypeSize (ElemQT);
3018- bool ResultElemUnsigned = ElemQT->isUnsignedIntegerOrEnumerationType ();
3019-
3020- INT_TYPE_SWITCH_NO_BOOL (*ElemT, {
3021- for (unsigned I = 0 ; I != ResultLen; ++I) {
3022- APSInt AElem = A.elem <T>(I).toAPSInt ();
3023- APSInt BElem = B.elem <T>(I).toAPSInt ();
3024- APSInt ResultElem =
3025- (BElem.isNegative () ? -AElem
3026- : BElem.isZero () ? APSInt (ElemBitWidth, ResultElemUnsigned)
3027- : AElem);
3028- Result.elem <T>(I) = static_cast <T>(ResultElem);
3029- }
3030- });
3031- Result.initializeAllElements ();
3032- return true ;
3033- }
3034-
30353006static bool interp__builtin_ia32_pternlog (InterpState &S, CodePtr OpPC,
30363007 const CallExpr *Call, bool MaskZ) {
30373008 assert (Call->getNumArgs () == 5 );
@@ -3665,7 +3636,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
36653636 case X86::BI__builtin_ia32_psignw256:
36663637 case X86::BI__builtin_ia32_psignd128:
36673638 case X86::BI__builtin_ia32_psignd256:
3668- return interp__builtin_ia32_psign_op (S, OpPC, Call);
3639+ return interp__builtin_elementwise_int_binop (
3640+ S, OpPC, Call, [](const APSInt &AElem, const APSInt &BElem) -> APInt {
3641+ return BElem.isNegative () ? static_cast <const APInt &>(-AElem)
3642+ : BElem.isZero () ? APInt (AElem.getBitWidth (), 0 )
3643+ : static_cast <const APInt &>(AElem);
3644+ });
36693645
36703646 case clang::X86::BI__builtin_ia32_pavgb128:
36713647 case clang::X86::BI__builtin_ia32_pavgw128:
0 commit comments