-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[X86][Clang] Add AVX512 Integer Comparison Intrinsics for constexpr Evaluation #164026
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
dbcb924
fec68e4
ee703e0
3b6e186
c3cdc21
151e23b
e96b79b
4895fd9
b8b4c35
69ca76f
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 |
---|---|---|
|
@@ -3101,6 +3101,68 @@ static bool interp__builtin_vec_set(InterpState &S, CodePtr OpPC, | |
return true; | ||
} | ||
|
||
static bool evalICmpImm(const uint8_t imm, const llvm::APSInt &A, | ||
const llvm::APSInt &B, bool IsUnsigned) { | ||
switch (imm & 0x7) { | ||
case 0x00: | ||
return (A == B); | ||
break; | ||
case 0x01: | ||
return IsUnsigned ? A.ult(B) : A.slt(B); | ||
break; | ||
case 0x02: | ||
return IsUnsigned ? A.ule(B) : A.sle(B); | ||
break; | ||
case 0x03: | ||
return false; | ||
break; | ||
case 0x04: | ||
return (A != B); | ||
break; | ||
case 0x05: | ||
return IsUnsigned ? A.ugt(B) : A.sgt(B); | ||
break; | ||
case 0x06: | ||
return IsUnsigned ? A.uge(B) : A.sge(B); | ||
break; | ||
case 0x07: | ||
return true; | ||
break; | ||
default: | ||
llvm_unreachable("Invalid Op"); | ||
} | ||
} | ||
|
||
static bool interp__builtin_cmp_mask(InterpState &S, CodePtr OpPC, | ||
const CallExpr *Call, unsigned ID, | ||
bool IsUnsigned) { | ||
assert(Call->getNumArgs() == 4); | ||
|
||
APSInt Mask = popToAPSInt(S, Call->getArg(3)); | ||
APSInt Opcode = popToAPSInt(S, Call->getArg(2)); | ||
unsigned CmpOp = static_cast<unsigned>(Opcode.getZExtValue()); | ||
const Pointer &RHS = S.Stk.pop<Pointer>(); | ||
const Pointer &LHS = S.Stk.pop<Pointer>(); | ||
|
||
assert(LHS.getNumElems() == RHS.getNumElems()); | ||
|
||
APInt RetMask = APInt::getZero(LHS.getNumElems()); | ||
unsigned VectorLen = LHS.getNumElems(); | ||
PrimType ElemT = LHS.getFieldDesc()->getPrimType(); | ||
|
||
for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) { | ||
INT_TYPE_SWITCH_NO_BOOL(ElemT, { | ||
RetMask.setBitVal(ElemNum, | ||
Mask[ElemNum] && | ||
evalICmpImm(CmpOp, LHS.elem<T>(ElemNum).toAPSInt(), | ||
RHS.elem<T>(ElemNum).toAPSInt(), | ||
IsUnsigned)); | ||
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. Just do APSInt A;
APSInt B;
TYPE_SWITCH_NO_BOOL(ElemT, {A = LHS.elem<T>().toAPSInt(); B = LHS.elem<T>().toAPSINt(); });
Rest of the code ? 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. I thought I should keep A and B const ref and : INT_TYPE_SWITCH_NO_BOOL(ElemT, {
const APSInt &A = ...;
const APSInt &B = ...;
});
bool Result = false;
... Woudnt work, do I just remove the const ref and do that? 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. Yes, they don't have to be const ref here, it's just a convention. |
||
}); | ||
} | ||
pushInteger(S, RetMask, Call->getType()); | ||
return true; | ||
} | ||
|
||
static bool interp__builtin_ia32_vpconflict(InterpState &S, CodePtr OpPC, | ||
const CallExpr *Call) { | ||
assert(Call->getNumArgs() == 1); | ||
|
@@ -4141,6 +4203,36 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, | |
case X86::BI__builtin_ia32_vec_set_v4di: | ||
return interp__builtin_vec_set(S, OpPC, Call, BuiltinID); | ||
|
||
case X86::BI__builtin_ia32_cmpb128_mask: | ||
case X86::BI__builtin_ia32_cmpw128_mask: | ||
case X86::BI__builtin_ia32_cmpd128_mask: | ||
case X86::BI__builtin_ia32_cmpq128_mask: | ||
case X86::BI__builtin_ia32_cmpb256_mask: | ||
case X86::BI__builtin_ia32_cmpw256_mask: | ||
case X86::BI__builtin_ia32_cmpd256_mask: | ||
case X86::BI__builtin_ia32_cmpq256_mask: | ||
case X86::BI__builtin_ia32_cmpb512_mask: | ||
case X86::BI__builtin_ia32_cmpw512_mask: | ||
case X86::BI__builtin_ia32_cmpd512_mask: | ||
case X86::BI__builtin_ia32_cmpq512_mask: | ||
return interp__builtin_cmp_mask(S, OpPC, Call, BuiltinID, | ||
/*IsUnsigned=*/false); | ||
|
||
case X86::BI__builtin_ia32_ucmpb128_mask: | ||
case X86::BI__builtin_ia32_ucmpw128_mask: | ||
case X86::BI__builtin_ia32_ucmpd128_mask: | ||
case X86::BI__builtin_ia32_ucmpq128_mask: | ||
case X86::BI__builtin_ia32_ucmpb256_mask: | ||
case X86::BI__builtin_ia32_ucmpw256_mask: | ||
case X86::BI__builtin_ia32_ucmpd256_mask: | ||
case X86::BI__builtin_ia32_ucmpq256_mask: | ||
case X86::BI__builtin_ia32_ucmpb512_mask: | ||
case X86::BI__builtin_ia32_ucmpw512_mask: | ||
case X86::BI__builtin_ia32_ucmpd512_mask: | ||
case X86::BI__builtin_ia32_ucmpq512_mask: | ||
return interp__builtin_cmp_mask(S, OpPC, Call, BuiltinID, | ||
/*IsUnsigned=*/true); | ||
|
||
default: | ||
S.FFDiag(S.Current->getLocation(OpPC), | ||
diag::note_invalid_subexpr_in_const_expr) | ||
|
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.
(style) no break after a return