-
Notifications
You must be signed in to change notification settings - Fork 15k
[Headers][X86] Allow AVX512 masked arithmetic intrinsics to be used in constexpr #162816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3598,6 +3598,27 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, | |||||
| return APInt::getAllOnes(DstBits); | ||||||
| }); | ||||||
|
|
||||||
| case clang::X86::BI__builtin_ia32_selectss_128: | ||||||
| case clang::X86::BI__builtin_ia32_selectsd_128: { | ||||||
| const unsigned N = | ||||||
| Call->getArg(1)->getType()->getAs<VectorType>()->getNumElements(); | ||||||
|
|
||||||
| const Pointer &W = S.Stk.pop<Pointer>(); | ||||||
| const Pointer &A = S.Stk.pop<Pointer>(); | ||||||
| APSInt U = popToAPSInt(S, Call->getArg(0)); | ||||||
| const Pointer &Dst = S.Stk.peek<Pointer>(); | ||||||
|
|
||||||
| const bool TakeA0 = U.getZExtValue() & 1ULL; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| for (unsigned i = 0; i < N; ++i) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Dst.elem<Floating>(i) = W.elem<Floating>(i); | ||||||
| if (TakeA0) | ||||||
| Dst.elem<Floating>(0) = A.elem<Floating>(0); | ||||||
|
|
||||||
| Dst.initializeAllElements(); | ||||||
| return true; | ||||||
| } | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a function for this. |
||||||
|
|
||||||
| case clang::X86::BI__builtin_ia32_vprotbi: | ||||||
| case clang::X86::BI__builtin_ia32_vprotdi: | ||||||
| case clang::X86::BI__builtin_ia32_vprotqi: | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11705,6 +11705,23 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { | |
| return Success(APValue(ResultElements.data(), SourceLen), E); | ||
| }; | ||
|
|
||
| auto EvalSelectScalar = [&](unsigned Len) -> std::optional<APValue> { | ||
| APSInt Mask; | ||
| APValue AVal, WVal; | ||
| if (!EvaluateInteger(E->getArg(0), Mask, Info) || | ||
| !EvaluateAsRValue(Info, E->getArg(1), AVal) || | ||
| !EvaluateAsRValue(Info, E->getArg(2), WVal)) | ||
| return std::nullopt; | ||
|
|
||
| const bool TakeA0 = (Mask.getZExtValue() & 1u) != 0; | ||
| SmallVector<APValue, 4> Res; | ||
| Res.reserve(Len); | ||
| Res.push_back(TakeA0 ? AVal.getVectorElt(0) : WVal.getVectorElt(0)); | ||
| for (unsigned i = 1; i < Len; ++i) | ||
| Res.push_back(WVal.getVectorElt(i)); | ||
| return APValue(Res.data(), Res.size()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just return Success / false? |
||
| }; | ||
|
|
||
| switch (E->getBuiltinCallee()) { | ||
| default: | ||
| return false; | ||
|
|
@@ -11933,6 +11950,16 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { | |
| return APInt((Src).trunc(DstBits)); | ||
| return APInt::getAllOnes(DstBits); | ||
| }); | ||
| case clang::X86::BI__builtin_ia32_selectss_128: { | ||
| if (auto V = EvalSelectScalar(4)) | ||
| return Success(*V, E); | ||
| return false; | ||
| } | ||
| case clang::X86::BI__builtin_ia32_selectsd_128: { | ||
| if (auto V = EvalSelectScalar(2)) | ||
| return Success(*V, E); | ||
| return false; | ||
| } | ||
| case clang::X86::BI__builtin_ia32_pmuldq128: | ||
| case clang::X86::BI__builtin_ia32_pmuldq256: | ||
| case clang::X86::BI__builtin_ia32_pmuldq512: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.