Skip to content
Merged
40 changes: 20 additions & 20 deletions clang/include/clang/Basic/BuiltinsX86.td
Original file line number Diff line number Diff line change
Expand Up @@ -1219,15 +1219,15 @@ let Features = "avx512f", Attributes = [NoThrow, RequiredVectorWidth<512>] in {
def scatterdiv16si : X86Builtin<"void(void *, unsigned char, _Vector<8, long long int>, _Vector<8, int>, _Constant int)">;
}

let Features = "avx512dq", Attributes = [NoThrow, Const] in {
let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def knotqi : X86Builtin<"unsigned char(unsigned char)">;
}

let Features = "avx512f", Attributes = [NoThrow, Const] in {
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr] in {
def knothi : X86Builtin<"unsigned short(unsigned short)">;
}

let Features = "avx512bw", Attributes = [NoThrow, Const] in {
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def knotsi : X86Builtin<"unsigned int(unsigned int)">;
def knotdi : X86Builtin<"unsigned long long int(unsigned long long int)">;
}
Expand Down Expand Up @@ -3076,51 +3076,51 @@ let Features = "avx512dq", Attributes = [NoThrow, Const, RequiredVectorWidth<128
def fpclassss_mask : X86Builtin<"unsigned char(_Vector<4, float>, _Constant int, unsigned char)">;
}

let Features = "avx512dq", Attributes = [NoThrow, Const] in {
let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def kaddqi : X86Builtin<"unsigned char(unsigned char, unsigned char)">;
def kaddhi : X86Builtin<"unsigned short(unsigned short, unsigned short)">;
}

let Features = "avx512bw", Attributes = [NoThrow, Const] in {
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def kaddsi : X86Builtin<"unsigned int(unsigned int, unsigned int)">;
def kadddi : X86Builtin<"unsigned long long int(unsigned long long int, unsigned long long int)">;
}

let Features = "avx512dq", Attributes = [NoThrow, Const] in {
let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def kandqi : X86Builtin<"unsigned char(unsigned char, unsigned char)">;
}

let Features = "avx512f", Attributes = [NoThrow, Const] in {
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr] in {
def kandhi : X86Builtin<"unsigned short(unsigned short, unsigned short)">;
}

let Features = "avx512bw", Attributes = [NoThrow, Const] in {
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def kandsi : X86Builtin<"unsigned int(unsigned int, unsigned int)">;
def kanddi : X86Builtin<"unsigned long long int(unsigned long long int, unsigned long long int)">;
}

let Features = "avx512dq", Attributes = [NoThrow, Const] in {
let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def kandnqi : X86Builtin<"unsigned char(unsigned char, unsigned char)">;
}

let Features = "avx512f", Attributes = [NoThrow, Const] in {
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr] in {
def kandnhi : X86Builtin<"unsigned short(unsigned short, unsigned short)">;
}

let Features = "avx512bw", Attributes = [NoThrow, Const] in {
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def kandnsi : X86Builtin<"unsigned int(unsigned int, unsigned int)">;
def kandndi : X86Builtin<"unsigned long long int(unsigned long long int, unsigned long long int)">;
}

let Features = "avx512dq", Attributes = [NoThrow, Const] in {
let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def korqi : X86Builtin<"unsigned char(unsigned char, unsigned char)">;
}

let Features = "avx512f", Attributes = [NoThrow, Const] in {
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr] in {
def korhi : X86Builtin<"unsigned short(unsigned short, unsigned short)">;
}

let Features = "avx512bw", Attributes = [NoThrow, Const] in {
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def korsi : X86Builtin<"unsigned int(unsigned int, unsigned int)">;
def kordi : X86Builtin<"unsigned long long int(unsigned long long int, unsigned long long int)">;
}
Expand Down Expand Up @@ -3160,28 +3160,28 @@ let Features = "avx512f", Attributes = [NoThrow, Const] in {
def kunpckhi : X86Builtin<"unsigned short(unsigned short, unsigned short)">;
}

let Features = "avx512dq", Attributes = [NoThrow, Const] in {
let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def kxnorqi : X86Builtin<"unsigned char(unsigned char, unsigned char)">;
}

let Features = "avx512f", Attributes = [NoThrow, Const] in {
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr] in {
def kxnorhi : X86Builtin<"unsigned short(unsigned short, unsigned short)">;
}

let Features = "avx512bw", Attributes = [NoThrow, Const] in {
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def kxnorsi : X86Builtin<"unsigned int(unsigned int, unsigned int)">;
def kxnordi : X86Builtin<"unsigned long long int(unsigned long long int, unsigned long long int)">;
}

let Features = "avx512dq", Attributes = [NoThrow, Const] in {
let Features = "avx512dq", Attributes = [NoThrow, Const, Constexpr] in {
def kxorqi : X86Builtin<"unsigned char(unsigned char, unsigned char)">;
}

let Features = "avx512f", Attributes = [NoThrow, Const] in {
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr] in {
def kxorhi : X86Builtin<"unsigned short(unsigned short, unsigned short)">;
}

let Features = "avx512bw", Attributes = [NoThrow, Const] in {
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr] in {
def kxorsi : X86Builtin<"unsigned int(unsigned int, unsigned int)">;
def kxordi : X86Builtin<"unsigned long long int(unsigned long long int, unsigned long long int)">;
}
Expand Down
64 changes: 64 additions & 0 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,16 @@ static bool interp__builtin_abs(InterpState &S, CodePtr OpPC,
return true;
}

static bool interp__builtin_knot(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const CallExpr *Call) {
APSInt Val =
popToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(0)->getType()));
APInt Result = ~Val;
pushInteger(S, APSInt(std::move(Result), true), Call->getType());
return true;
}

static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const CallExpr *Call) {
Expand Down Expand Up @@ -3607,6 +3617,60 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case X86::BI__builtin_ia32_selectpd_512:
return interp__builtin_select(S, OpPC, Call);

case X86::BI__builtin_ia32_kandqi:
case X86::BI__builtin_ia32_kandhi:
case X86::BI__builtin_ia32_kandsi:
case X86::BI__builtin_ia32_kanddi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
[](const APSInt &LHS, const APSInt &RHS) { return LHS & RHS; });

case X86::BI__builtin_ia32_kandnqi:
case X86::BI__builtin_ia32_kandnhi:
case X86::BI__builtin_ia32_kandnsi:
case X86::BI__builtin_ia32_kandndi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
[](const APSInt &LHS, const APSInt &RHS) { return ~LHS & RHS; });

case X86::BI__builtin_ia32_korqi:
case X86::BI__builtin_ia32_korhi:
case X86::BI__builtin_ia32_korsi:
case X86::BI__builtin_ia32_kordi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
[](const APSInt &LHS, const APSInt &RHS) { return LHS | RHS; });

case X86::BI__builtin_ia32_kxnorqi:
case X86::BI__builtin_ia32_kxnorhi:
case X86::BI__builtin_ia32_kxnorsi:
case X86::BI__builtin_ia32_kxnordi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
[](const APSInt &LHS, const APSInt &RHS) { return ~(LHS ^ RHS); });

case X86::BI__builtin_ia32_kxorqi:
case X86::BI__builtin_ia32_kxorhi:
case X86::BI__builtin_ia32_kxorsi:
case X86::BI__builtin_ia32_kxordi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
[](const APSInt &LHS, const APSInt &RHS) { return LHS ^ RHS; });

case X86::BI__builtin_ia32_knotqi:
case X86::BI__builtin_ia32_knothi:
case X86::BI__builtin_ia32_knotsi:
case X86::BI__builtin_ia32_knotdi:
return interp__builtin_knot(S, OpPC, Frame, Call);

case X86::BI__builtin_ia32_kaddqi:
case X86::BI__builtin_ia32_kaddhi:
case X86::BI__builtin_ia32_kaddsi:
case X86::BI__builtin_ia32_kadddi:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call,
[](const APSInt &LHS, const APSInt &RHS) { return LHS + RHS; });

case Builtin::BI__builtin_elementwise_fshl:
return interp__builtin_elementwise_triop(S, OpPC, Call,
llvm::APIntOps::fshl);
Expand Down
73 changes: 73 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13588,6 +13588,20 @@ static bool getBuiltinAlignArguments(const CallExpr *E, EvalInfo &Info,

bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
unsigned BuiltinOp) {

auto HandleMaskBinOp =
[&](llvm::function_ref<APSInt(const APSInt &, const APSInt &)> Fn)
-> bool {
APValue LHS, RHS;
if (!Evaluate(LHS, Info, E->getArg(0)) ||
!Evaluate(RHS, Info, E->getArg(1)))
return false;

APSInt ResultInt = Fn(LHS.getInt(), RHS.getInt());

return Success(APValue(ResultInt), E);
};

switch (BuiltinOp) {
default:
return false;
Expand Down Expand Up @@ -14687,6 +14701,65 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
Result.setBitVal(P++, Val[I]);
return Success(Result, E);
}

case X86::BI__builtin_ia32_kandqi:
case X86::BI__builtin_ia32_kandhi:
case X86::BI__builtin_ia32_kandsi:
case X86::BI__builtin_ia32_kanddi: {
return HandleMaskBinOp(
[](const APSInt &LHS, const APSInt &RHS) { return LHS & RHS; });
}

case X86::BI__builtin_ia32_kandnqi:
case X86::BI__builtin_ia32_kandnhi:
case X86::BI__builtin_ia32_kandnsi:
case X86::BI__builtin_ia32_kandndi: {
return HandleMaskBinOp(
[](const APSInt &LHS, const APSInt &RHS) { return ~LHS & RHS; });
}

case X86::BI__builtin_ia32_korqi:
case X86::BI__builtin_ia32_korhi:
case X86::BI__builtin_ia32_korsi:
case X86::BI__builtin_ia32_kordi: {
return HandleMaskBinOp(
[](const APSInt &LHS, const APSInt &RHS) { return LHS | RHS; });
}

case X86::BI__builtin_ia32_kxnorqi:
case X86::BI__builtin_ia32_kxnorhi:
case X86::BI__builtin_ia32_kxnorsi:
case X86::BI__builtin_ia32_kxnordi: {
return HandleMaskBinOp(
[](const APSInt &LHS, const APSInt &RHS) { return ~(LHS ^ RHS); });
}

case X86::BI__builtin_ia32_kxorqi:
case X86::BI__builtin_ia32_kxorhi:
case X86::BI__builtin_ia32_kxorsi:
case X86::BI__builtin_ia32_kxordi: {
return HandleMaskBinOp(
[](const APSInt &LHS, const APSInt &RHS) { return LHS ^ RHS; });
}

case X86::BI__builtin_ia32_knotqi:
case X86::BI__builtin_ia32_knothi:
case X86::BI__builtin_ia32_knotsi:
case X86::BI__builtin_ia32_knotdi: {
APSInt Val;
if (!EvaluateInteger(E->getArg(0), Val, Info))
return false;
APSInt Result = ~Val;
return Success(APValue(Result), E);
}

case X86::BI__builtin_ia32_kaddqi:
case X86::BI__builtin_ia32_kaddhi:
case X86::BI__builtin_ia32_kaddsi:
case X86::BI__builtin_ia32_kadddi: {
return HandleMaskBinOp(
[](const APSInt &LHS, const APSInt &RHS) { return LHS + RHS; });
}
}
}

Expand Down
62 changes: 28 additions & 34 deletions clang/lib/Headers/avx512bwintrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,68 +32,63 @@ typedef unsigned long long __mmask64;
#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
#endif

static __inline __mmask32 __DEFAULT_FN_ATTRS
_knot_mask32(__mmask32 __M)
{
static __inline __mmask32
__DEFAULT_FN_ATTRS_CONSTEXPR _knot_mask32(__mmask32 __M) {
return __builtin_ia32_knotsi(__M);
}

static __inline __mmask64 __DEFAULT_FN_ATTRS _knot_mask64(__mmask64 __M) {
static __inline __mmask64 __DEFAULT_FN_ATTRS_CONSTEXPR
_knot_mask64(__mmask64 __M) {
return __builtin_ia32_knotdi(__M);
}

static __inline__ __mmask32 __DEFAULT_FN_ATTRS
_kand_mask32(__mmask32 __A, __mmask32 __B)
{
static __inline__ __mmask32 __DEFAULT_FN_ATTRS_CONSTEXPR
_kand_mask32(__mmask32 __A, __mmask32 __B) {
return (__mmask32)__builtin_ia32_kandsi((__mmask32)__A, (__mmask32)__B);
}

static __inline__ __mmask64 __DEFAULT_FN_ATTRS _kand_mask64(__mmask64 __A,
__mmask64 __B) {
static __inline__ __mmask64 __DEFAULT_FN_ATTRS_CONSTEXPR
_kand_mask64(__mmask64 __A, __mmask64 __B) {
return (__mmask64)__builtin_ia32_kanddi((__mmask64)__A, (__mmask64)__B);
}

static __inline__ __mmask32 __DEFAULT_FN_ATTRS
_kandn_mask32(__mmask32 __A, __mmask32 __B)
{
static __inline__ __mmask32 __DEFAULT_FN_ATTRS_CONSTEXPR
_kandn_mask32(__mmask32 __A, __mmask32 __B) {
return (__mmask32)__builtin_ia32_kandnsi((__mmask32)__A, (__mmask32)__B);
}

static __inline__ __mmask64 __DEFAULT_FN_ATTRS _kandn_mask64(__mmask64 __A,
__mmask64 __B) {
static __inline__ __mmask64 __DEFAULT_FN_ATTRS_CONSTEXPR
_kandn_mask64(__mmask64 __A, __mmask64 __B) {
return (__mmask64)__builtin_ia32_kandndi((__mmask64)__A, (__mmask64)__B);
}

static __inline__ __mmask32 __DEFAULT_FN_ATTRS
_kor_mask32(__mmask32 __A, __mmask32 __B)
{
static __inline__ __mmask32 __DEFAULT_FN_ATTRS_CONSTEXPR
_kor_mask32(__mmask32 __A, __mmask32 __B) {
return (__mmask32)__builtin_ia32_korsi((__mmask32)__A, (__mmask32)__B);
}

static __inline__ __mmask64 __DEFAULT_FN_ATTRS _kor_mask64(__mmask64 __A,
__mmask64 __B) {
static __inline__ __mmask64 __DEFAULT_FN_ATTRS_CONSTEXPR
_kor_mask64(__mmask64 __A, __mmask64 __B) {
return (__mmask64)__builtin_ia32_kordi((__mmask64)__A, (__mmask64)__B);
}

static __inline__ __mmask32 __DEFAULT_FN_ATTRS
_kxnor_mask32(__mmask32 __A, __mmask32 __B)
{
static __inline__ __mmask32 __DEFAULT_FN_ATTRS_CONSTEXPR
_kxnor_mask32(__mmask32 __A, __mmask32 __B) {
return (__mmask32)__builtin_ia32_kxnorsi((__mmask32)__A, (__mmask32)__B);
}

static __inline__ __mmask64 __DEFAULT_FN_ATTRS _kxnor_mask64(__mmask64 __A,
__mmask64 __B) {
static __inline__ __mmask64 __DEFAULT_FN_ATTRS_CONSTEXPR
_kxnor_mask64(__mmask64 __A, __mmask64 __B) {
return (__mmask64)__builtin_ia32_kxnordi((__mmask64)__A, (__mmask64)__B);
}

static __inline__ __mmask32 __DEFAULT_FN_ATTRS
_kxor_mask32(__mmask32 __A, __mmask32 __B)
{
static __inline__ __mmask32 __DEFAULT_FN_ATTRS_CONSTEXPR
_kxor_mask32(__mmask32 __A, __mmask32 __B) {
return (__mmask32)__builtin_ia32_kxorsi((__mmask32)__A, (__mmask32)__B);
}

static __inline__ __mmask64 __DEFAULT_FN_ATTRS _kxor_mask64(__mmask64 __A,
__mmask64 __B) {
static __inline__ __mmask64 __DEFAULT_FN_ATTRS_CONSTEXPR
_kxor_mask64(__mmask64 __A, __mmask64 __B) {
return (__mmask64)__builtin_ia32_kxordi((__mmask64)__A, (__mmask64)__B);
}

Expand Down Expand Up @@ -165,14 +160,13 @@ _ktest_mask64_u8(__mmask64 __A, __mmask64 __B, unsigned char *__C) {
return (unsigned char)__builtin_ia32_ktestzdi(__A, __B);
}

static __inline__ __mmask32 __DEFAULT_FN_ATTRS
_kadd_mask32(__mmask32 __A, __mmask32 __B)
{
static __inline__ __mmask32 __DEFAULT_FN_ATTRS_CONSTEXPR
_kadd_mask32(__mmask32 __A, __mmask32 __B) {
return (__mmask32)__builtin_ia32_kaddsi((__mmask32)__A, (__mmask32)__B);
}

static __inline__ __mmask64 __DEFAULT_FN_ATTRS _kadd_mask64(__mmask64 __A,
__mmask64 __B) {
static __inline__ __mmask64 __DEFAULT_FN_ATTRS_CONSTEXPR
_kadd_mask64(__mmask64 __A, __mmask64 __B) {
return (__mmask64)__builtin_ia32_kadddi((__mmask64)__A, (__mmask64)__B);
}

Expand Down
Loading