Skip to content

Commit 5c58df9

Browse files
committed
Draft
1 parent c422881 commit 5c58df9

File tree

5 files changed

+84
-56
lines changed

5 files changed

+84
-56
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,17 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<128>] in {
124124
}
125125

126126
let Features = "ssse3" in {
127-
def pmulhrsw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
128-
def psignb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
129-
def psignw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
130-
def psignd128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
127+
def pmulhrsw128
128+
: X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
131129
}
132130

133131
let Features = "ssse3", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
132+
def psignb128
133+
: X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
134+
def psignw128
135+
: X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
136+
def psignd128
137+
: X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
134138
def pmaddubsw128 : X86Builtin<"_Vector<8, short>(_Vector<16, char>, _Vector<16, char>)">;
135139
def pshufb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
136140
}
@@ -609,10 +613,9 @@ let Features = "avx2", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] i
609613

610614
def pmovmskb256 : X86Builtin<"int(_Vector<32, char>)">;
611615
def pmulhrsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
612-
def psadbw256 : X86Builtin<"_Vector<4, long long int>(_Vector<32, char>, _Vector<32, char>)">;
613-
def psignb256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>)">;
614-
def psignw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
615-
def psignd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
616+
def psadbw256
617+
: X86Builtin<
618+
"_Vector<4, long long int>(_Vector<32, char>, _Vector<32, char>)">;
616619
def psllw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<8, short>)">;
617620
def pslldqi256_byteshift : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Constant int)">;
618621
def pslld256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<4, int>)">;
@@ -682,7 +685,15 @@ let Features = "avx2", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWi
682685
def phsubw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
683686
def phsubd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
684687
def phsubsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
685-
688+
689+
def psignb256
690+
: X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>)">;
691+
def psignw256
692+
: X86Builtin<
693+
"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
694+
def psignd256
695+
: X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
696+
686697
def pshuflw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Constant int)">;
687698
def pshufhw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Constant int)">;
688699
def pshufd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Constant int)">;

clang/lib/AST/ExprConstant.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12206,6 +12206,37 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1220612206
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
1220712207
}
1220812208

12209+
case X86::BI__builtin_ia32_psignb128:
12210+
case X86::BI__builtin_ia32_psignb256:
12211+
case X86::BI__builtin_ia32_psignw128:
12212+
case X86::BI__builtin_ia32_psignw256:
12213+
case X86::BI__builtin_ia32_psignd128:
12214+
case X86::BI__builtin_ia32_psignd256: {
12215+
APValue ASource, BSource;
12216+
if (!EvaluateAsRValue(Info, E->getArg(0), ASource) ||
12217+
!EvaluateAsRValue(Info, E->getArg(1), BSource))
12218+
return false;
12219+
unsigned SourceLen = ASource.getVectorLength();
12220+
const VectorType *VT = E->getArg(0)->getType()->castAs<VectorType>();
12221+
QualType ElemT = VT->getElementType();
12222+
unsigned ElemBitWidth = Info.Ctx.getTypeSize(ElemT);
12223+
QualType ResultElemT = E->getType()->castAs<VectorType>()->getElementType();
12224+
bool ResultElemUnsigned = ResultElemT->isUnsignedIntegerOrEnumerationType();
12225+
12226+
SmallVector<APValue, 16> Result;
12227+
Result.reserve(SourceLen);
12228+
for (unsigned I = 0; I != SourceLen; ++I) {
12229+
APSInt &AElem = ASource.getVectorElt(I).getInt();
12230+
APSInt &BElem = BSource.getVectorElt(I).getInt();
12231+
APSInt ResultElem =
12232+
(BElem.isNegative() ? -AElem
12233+
: BElem.isZero() ? APSInt(ElemBitWidth, ResultElemUnsigned)
12234+
: AElem);
12235+
Result.emplace_back(ResultElem);
12236+
}
12237+
return Success(APValue(Result.data(), Result.size()), E);
12238+
}
12239+
1220912240
case X86::BI__builtin_ia32_blendvpd:
1221012241
case X86::BI__builtin_ia32_blendvpd256:
1221112242
case X86::BI__builtin_ia32_blendvps:

clang/lib/Headers/avx2intrin.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,10 +1978,9 @@ _mm256_shuffle_epi8(__m256i __a, __m256i __b) {
19781978
/// \param __b
19791979
/// A 256-bit integer vector].
19801980
/// \returns A 256-bit integer vector containing the result.
1981-
static __inline__ __m256i __DEFAULT_FN_ATTRS256
1982-
_mm256_sign_epi8(__m256i __a, __m256i __b)
1983-
{
1984-
return (__m256i)__builtin_ia32_psignb256((__v32qi)__a, (__v32qi)__b);
1981+
static __inline__ __m256i __DEFAULT_FN_ATTRS256_CONSTEXPR
1982+
_mm256_sign_epi8(__m256i __a, __m256i __b) {
1983+
return (__m256i)__builtin_ia32_psignb256((__v32qi)__a, (__v32qi)__b);
19851984
}
19861985

19871986
/// Sets each element of the result to the corresponding element of the
@@ -1999,10 +1998,9 @@ _mm256_sign_epi8(__m256i __a, __m256i __b)
19991998
/// \param __b
20001999
/// A 256-bit vector of [16 x i16].
20012000
/// \returns A 256-bit vector of [16 x i16] containing the result.
2002-
static __inline__ __m256i __DEFAULT_FN_ATTRS256
2003-
_mm256_sign_epi16(__m256i __a, __m256i __b)
2004-
{
2005-
return (__m256i)__builtin_ia32_psignw256((__v16hi)__a, (__v16hi)__b);
2001+
static __inline__ __m256i __DEFAULT_FN_ATTRS256_CONSTEXPR
2002+
_mm256_sign_epi16(__m256i __a, __m256i __b) {
2003+
return (__m256i)__builtin_ia32_psignw256((__v16hi)__a, (__v16hi)__b);
20062004
}
20072005

20082006
/// Sets each element of the result to the corresponding element of the
@@ -2020,10 +2018,9 @@ _mm256_sign_epi16(__m256i __a, __m256i __b)
20202018
/// \param __b
20212019
/// A 256-bit vector of [8 x i32].
20222020
/// \returns A 256-bit vector of [8 x i32] containing the result.
2023-
static __inline__ __m256i __DEFAULT_FN_ATTRS256
2024-
_mm256_sign_epi32(__m256i __a, __m256i __b)
2025-
{
2026-
return (__m256i)__builtin_ia32_psignd256((__v8si)__a, (__v8si)__b);
2021+
static __inline__ __m256i __DEFAULT_FN_ATTRS256_CONSTEXPR
2022+
_mm256_sign_epi32(__m256i __a, __m256i __b) {
2023+
return (__m256i)__builtin_ia32_psignd256((__v8si)__a, (__v8si)__b);
20272024
}
20282025

20292026
/// Shifts each 128-bit half of the 256-bit integer vector \a a left by

clang/lib/Headers/tmmintrin.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,9 @@ _mm_shuffle_pi8(__m64 __a, __m64 __b) {
642642
/// A 128-bit integer vector containing control bytes corresponding to
643643
/// positions in the destination.
644644
/// \returns A 128-bit integer vector containing the resultant values.
645-
static __inline__ __m128i __DEFAULT_FN_ATTRS
646-
_mm_sign_epi8(__m128i __a, __m128i __b)
647-
{
648-
return (__m128i)__builtin_ia32_psignb128((__v16qi)__a, (__v16qi)__b);
645+
static __inline__ __m128i __DEFAULT_FN_ATTRS_CONSTEXPR
646+
_mm_sign_epi8(__m128i __a, __m128i __b) {
647+
return (__m128i)__builtin_ia32_psignb128((__v16qi)__a, (__v16qi)__b);
649648
}
650649

651650
/// For each 16-bit integer in the first source operand, perform one of
@@ -668,10 +667,9 @@ _mm_sign_epi8(__m128i __a, __m128i __b)
668667
/// A 128-bit integer vector containing control words corresponding to
669668
/// positions in the destination.
670669
/// \returns A 128-bit integer vector containing the resultant values.
671-
static __inline__ __m128i __DEFAULT_FN_ATTRS
672-
_mm_sign_epi16(__m128i __a, __m128i __b)
673-
{
674-
return (__m128i)__builtin_ia32_psignw128((__v8hi)__a, (__v8hi)__b);
670+
static __inline__ __m128i __DEFAULT_FN_ATTRS_CONSTEXPR
671+
_mm_sign_epi16(__m128i __a, __m128i __b) {
672+
return (__m128i)__builtin_ia32_psignw128((__v8hi)__a, (__v8hi)__b);
675673
}
676674

677675
/// For each 32-bit integer in the first source operand, perform one of
@@ -694,10 +692,9 @@ _mm_sign_epi16(__m128i __a, __m128i __b)
694692
/// A 128-bit integer vector containing control doublewords corresponding to
695693
/// positions in the destination.
696694
/// \returns A 128-bit integer vector containing the resultant values.
697-
static __inline__ __m128i __DEFAULT_FN_ATTRS
698-
_mm_sign_epi32(__m128i __a, __m128i __b)
699-
{
700-
return (__m128i)__builtin_ia32_psignd128((__v4si)__a, (__v4si)__b);
695+
static __inline__ __m128i __DEFAULT_FN_ATTRS_CONSTEXPR
696+
_mm_sign_epi32(__m128i __a, __m128i __b) {
697+
return (__m128i)__builtin_ia32_psignd128((__v4si)__a, (__v4si)__b);
701698
}
702699

703700
/// For each 8-bit integer in the first source operand, perform one of
@@ -720,11 +717,10 @@ _mm_sign_epi32(__m128i __a, __m128i __b)
720717
/// A 64-bit integer vector containing control bytes corresponding to
721718
/// positions in the destination.
722719
/// \returns A 64-bit integer vector containing the resultant values.
723-
static __inline__ __m64 __DEFAULT_FN_ATTRS
724-
_mm_sign_pi8(__m64 __a, __m64 __b)
725-
{
726-
return __trunc64(__builtin_ia32_psignb128((__v16qi)__anyext128(__a),
727-
(__v16qi)__anyext128(__b)));
720+
static __inline__ __m64 __DEFAULT_FN_ATTRS_CONSTEXPR _mm_sign_pi8(__m64 __a,
721+
__m64 __b) {
722+
return __trunc64(__builtin_ia32_psignb128((__v16qi)__anyext128(__a),
723+
(__v16qi)__anyext128(__b)));
728724
}
729725

730726
/// For each 16-bit integer in the first source operand, perform one of
@@ -747,11 +743,10 @@ _mm_sign_pi8(__m64 __a, __m64 __b)
747743
/// A 64-bit integer vector containing control words corresponding to
748744
/// positions in the destination.
749745
/// \returns A 64-bit integer vector containing the resultant values.
750-
static __inline__ __m64 __DEFAULT_FN_ATTRS
751-
_mm_sign_pi16(__m64 __a, __m64 __b)
752-
{
753-
return __trunc64(__builtin_ia32_psignw128((__v8hi)__anyext128(__a),
754-
(__v8hi)__anyext128(__b)));
746+
static __inline__ __m64 __DEFAULT_FN_ATTRS_CONSTEXPR _mm_sign_pi16(__m64 __a,
747+
__m64 __b) {
748+
return __trunc64(__builtin_ia32_psignw128((__v8hi)__anyext128(__a),
749+
(__v8hi)__anyext128(__b)));
755750
}
756751

757752
/// For each 32-bit integer in the first source operand, perform one of
@@ -774,11 +769,10 @@ _mm_sign_pi16(__m64 __a, __m64 __b)
774769
/// A 64-bit integer vector containing two control doublewords corresponding
775770
/// to positions in the destination.
776771
/// \returns A 64-bit integer vector containing the resultant values.
777-
static __inline__ __m64 __DEFAULT_FN_ATTRS
778-
_mm_sign_pi32(__m64 __a, __m64 __b)
779-
{
780-
return __trunc64(__builtin_ia32_psignd128((__v4si)__anyext128(__a),
781-
(__v4si)__anyext128(__b)));
772+
static __inline__ __m64 __DEFAULT_FN_ATTRS_CONSTEXPR _mm_sign_pi32(__m64 __a,
773+
__m64 __b) {
774+
return __trunc64(__builtin_ia32_psignd128((__v4si)__anyext128(__a),
775+
(__v4si)__anyext128(__b)));
782776
}
783777

784778
#undef __anyext128

clang/test/CodeGen/X86/mmx-builtins.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --implicit-check-not=x86mmx
88
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --implicit-check-not=x86mmx
99

10-
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
11-
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
12-
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
13-
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
14-
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
15-
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +ssse3 -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
16-
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
17-
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=i386-apple-darwin -target-feature +ssse3 -fno-signed-char -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s --implicit-check-not=x86mmx
10+
1811

1912

2013
#include <immintrin.h>
@@ -597,11 +590,13 @@ __m64 test_mm_shuffle_pi16(__m64 a) {
597590
return _mm_shuffle_pi16(a, 3);
598591
}
599592
TEST_CONSTEXPR(match_v4hi(_mm_shuffle_pi16(((__m64)(__v4hi){0,1,2,3}), 3), 3,0,0,0));
593+
600594
__m64 test_mm_sign_pi8(__m64 a, __m64 b) {
601595
// CHECK-LABEL: test_mm_sign_pi8
602596
// CHECK: call <16 x i8> @llvm.x86.ssse3.psign.b.128(
603597
return _mm_sign_pi8(a, b);
604598
}
599+
TEST_CONSTEXPR(match_v8qi(_mm_sign_pi8((__m64)(__v8qi){0,0,0,0, 0,0,0,0}, (__m64)(__v8qi){0,0,0,0, 0,0,0,0}), 0,0,0,0, 0,0,0,0));
605600

606601
__m64 test_mm_sign_pi16(__m64 a, __m64 b) {
607602
// CHECK-LABEL: test_mm_sign_pi16

0 commit comments

Comments
 (0)