Skip to content

Commit 7f68ad8

Browse files
committed
Apply feedback
1 parent b1b4415 commit 7f68ad8

File tree

2 files changed

+13
-54
lines changed

2 files changed

+13
-54
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
30353006
static 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:

clang/lib/AST/ExprConstant.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12250,30 +12250,13 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1225012250
case X86::BI__builtin_ia32_psignw128:
1225112251
case X86::BI__builtin_ia32_psignw256:
1225212252
case X86::BI__builtin_ia32_psignd128:
12253-
case X86::BI__builtin_ia32_psignd256: {
12254-
APValue ASource, BSource;
12255-
if (!EvaluateAsRValue(Info, E->getArg(0), ASource) ||
12256-
!EvaluateAsRValue(Info, E->getArg(1), BSource))
12257-
return false;
12258-
unsigned SourceLen = ASource.getVectorLength();
12259-
const VectorType *VT = E->getArg(0)->getType()->castAs<VectorType>();
12260-
QualType ElemQT = VT->getElementType();
12261-
unsigned ElemBitWidth = Info.Ctx.getTypeSize(ElemQT);
12262-
bool ResultElemUnsigned = ElemQT->isUnsignedIntegerOrEnumerationType();
12263-
12264-
SmallVector<APValue, 16> Result;
12265-
Result.reserve(SourceLen);
12266-
for (unsigned I = 0; I != SourceLen; ++I) {
12267-
APSInt &AElem = ASource.getVectorElt(I).getInt();
12268-
APSInt &BElem = BSource.getVectorElt(I).getInt();
12269-
APSInt ResultElem =
12270-
(BElem.isNegative() ? -AElem
12271-
: BElem.isZero() ? APSInt(ElemBitWidth, ResultElemUnsigned)
12272-
: AElem);
12273-
Result.emplace_back(ResultElem);
12274-
}
12275-
return Success(APValue(Result.data(), Result.size()), E);
12276-
}
12253+
case X86::BI__builtin_ia32_psignd256:
12254+
return EvaluateBinOpExpr(
12255+
[](const APSInt &AElem, const APSInt &BElem) -> APInt {
12256+
return BElem.isNegative() ? static_cast<const APInt &>(-AElem)
12257+
: BElem.isZero() ? APInt(AElem.getBitWidth(), 0)
12258+
: static_cast<const APInt &>(AElem);
12259+
});
1227712260

1227812261
case X86::BI__builtin_ia32_blendvpd:
1227912262
case X86::BI__builtin_ia32_blendvpd256:

0 commit comments

Comments
 (0)