Skip to content

Commit e3e5517

Browse files
committed
[clang][x86] Enable _mm_movehdup_ps, _mm_moveldup_ps and _mm_movedup_pd in constant expressions
These just wrap generic shuffles
1 parent 9fd15ad commit e3e5517

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

clang/lib/Headers/pmmintrin.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
__min_vector_width__(128)))
2828
#endif
2929

30+
#if defined(__cplusplus) && (__cplusplus >= 201103L)
31+
#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
32+
#else
33+
#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
34+
#endif
35+
3036
/// Loads data from an unaligned memory location to elements in a 128-bit
3137
/// vector.
3238
///
@@ -128,7 +134,7 @@ _mm_hsub_ps(__m128 __a, __m128 __b)
128134
/// destination.
129135
/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
130136
/// values.
131-
static __inline__ __m128 __DEFAULT_FN_ATTRS
137+
static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR
132138
_mm_movehdup_ps(__m128 __a)
133139
{
134140
return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 1, 1, 3, 3);
@@ -149,7 +155,7 @@ _mm_movehdup_ps(__m128 __a)
149155
/// destination.
150156
/// \returns A 128-bit vector of [4 x float] containing the moved and duplicated
151157
/// values.
152-
static __inline__ __m128 __DEFAULT_FN_ATTRS
158+
static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR
153159
_mm_moveldup_ps(__m128 __a)
154160
{
155161
return __builtin_shufflevector((__v4sf)__a, (__v4sf)__a, 0, 0, 2, 2);
@@ -250,7 +256,7 @@ _mm_hsub_pd(__m128d __a, __m128d __b)
250256
/// [127:64] and [63:0] of the destination.
251257
/// \returns A 128-bit vector of [2 x double] containing the moved and
252258
/// duplicated values.
253-
static __inline__ __m128d __DEFAULT_FN_ATTRS
259+
static __inline__ __m128d __DEFAULT_FN_ATTRS_CONSTEXPR
254260
_mm_movedup_pd(__m128d __a)
255261
{
256262
return __builtin_shufflevector((__v2df)__a, (__v2df)__a, 0, 0);
@@ -303,5 +309,6 @@ _mm_mwait(unsigned __extensions, unsigned __hints)
303309
}
304310

305311
#undef __DEFAULT_FN_ATTRS
312+
#undef __DEFAULT_FN_ATTRS_CONSTEXPR
306313

307314
#endif /* __PMMINTRIN_H */

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,22 @@ __m128 test_mm_moveldup_ps(__m128 A) {
7575
// CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x i32> <i32 0, i32 0, i32 2, i32 2>
7676
return _mm_moveldup_ps(A);
7777
}
78+
79+
// Test constexpr handling.
80+
#if defined(__cplusplus) && (__cplusplus >= 201103L)
81+
82+
void test_constexpr() {
83+
constexpr __m128d kd1 {+7.0,-7.0};
84+
constexpr __m128 kf1 {+1.0f,-1.0f,+2.0f,+4.0f};
85+
86+
constexpr __m128d v_mm_movedup_pd = _mm_movedup_pd(kd1);
87+
static_assert(v_mm_movedup_pd[0] == +7.0 && v_mm_movedup_pd[1] == +7.0);
88+
89+
constexpr __m128 v_mm_movehdup_ps = _mm_movehdup_ps(kf1);
90+
static_assert(v_mm_movehdup_ps[0] == -1.0f && v_mm_movehdup_ps[1] == -1.0f && v_mm_movehdup_ps[2] == +4.0f && v_mm_movehdup_ps[3] == +4.0f);
91+
92+
constexpr __m128 v_mm_moveldup_ps = _mm_moveldup_ps(kf1);
93+
static_assert(v_mm_moveldup_ps[0] == +1.0f && v_mm_moveldup_ps[1] == +1.0f && v_mm_moveldup_ps[2] == +2.0f && v_mm_moveldup_ps[3] == +2.0f);
94+
}
95+
96+
#endif

0 commit comments

Comments
 (0)