Skip to content

Commit 8306114

Browse files
committed
[clang][x86] Add constexpr support for _mm_cvtsi32_ss/_mm_cvt_si2ss/_mm_cvtsi64_ss SSE1 intrinsics
Followup to #111001
1 parent 8a849a2 commit 8306114

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

clang/lib/Headers/xmmintrin.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,9 +1618,8 @@ _mm_cvtt_ps2pi(__m128 __a)
16181618
/// \returns A 128-bit vector of [4 x float] whose lower 32 bits contain the
16191619
/// converted value of the second operand. The upper 96 bits are copied from
16201620
/// the upper 96 bits of the first operand.
1621-
static __inline__ __m128 __DEFAULT_FN_ATTRS
1622-
_mm_cvtsi32_ss(__m128 __a, int __b)
1623-
{
1621+
static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR _mm_cvtsi32_ss(__m128 __a,
1622+
int __b) {
16241623
__a[0] = __b;
16251624
return __a;
16261625
}
@@ -1641,9 +1640,8 @@ _mm_cvtsi32_ss(__m128 __a, int __b)
16411640
/// \returns A 128-bit vector of [4 x float] whose lower 32 bits contain the
16421641
/// converted value of the second operand. The upper 96 bits are copied from
16431642
/// the upper 96 bits of the first operand.
1644-
static __inline__ __m128 __DEFAULT_FN_ATTRS
1645-
_mm_cvt_si2ss(__m128 __a, int __b)
1646-
{
1643+
static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR _mm_cvt_si2ss(__m128 __a,
1644+
int __b) {
16471645
return _mm_cvtsi32_ss(__a, __b);
16481646
}
16491647

@@ -1665,9 +1663,8 @@ _mm_cvt_si2ss(__m128 __a, int __b)
16651663
/// \returns A 128-bit vector of [4 x float] whose lower 32 bits contain the
16661664
/// converted value of the second operand. The upper 96 bits are copied from
16671665
/// the upper 96 bits of the first operand.
1668-
static __inline__ __m128 __DEFAULT_FN_ATTRS
1669-
_mm_cvtsi64_ss(__m128 __a, long long __b)
1670-
{
1666+
static __inline__ __m128 __DEFAULT_FN_ATTRS_CONSTEXPR
1667+
_mm_cvtsi64_ss(__m128 __a, long long __b) {
16711668
__a[0] = __b;
16721669
return __a;
16731670
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,15 @@ void test_constexpr() {
948948
constexpr __m128 v_mm_movelh_ps = _mm_movelh_ps(k1, k2);
949949
static_assert(v_mm_movelh_ps[0] == +1.0f && v_mm_movelh_ps[1] == +0.0f && v_mm_movelh_ps[2] == +8.0f && v_mm_movelh_ps[3] == +4.0f);
950950

951+
constexpr __m128 v_mm_cvtsi32_ss = _mm_cvtsi32_ss(k1, 42);
952+
static_assert(v_mm_cvtsi32_ss[0] == 42.0f && v_mm_cvtsi32_ss[1] == +0.0f && v_mm_cvtsi32_ss[2] == +2.0f && v_mm_cvtsi32_ss[3] == +4.0f);
953+
954+
constexpr __m128 v_mm_cvt_si2ss = _mm_cvt_si2ss(k2, -99);
955+
static_assert(v_mm_cvt_si2ss[0] == -99.0f && v_mm_cvt_si2ss[1] == +4.0f && v_mm_cvt_si2ss[2] == +2.0f && v_mm_cvt_si2ss[3] == +1.0f);
956+
957+
constexpr __m128 v_mm_cvtsi64_ss = _mm_cvtsi64_ss(k3, 555);
958+
static_assert(v_mm_cvtsi64_ss[0] == 555.0f && v_mm_cvtsi64_ss[1] == -5.0f && v_mm_cvtsi64_ss[2] == +6.0f && v_mm_cvtsi64_ss[3] == +7.0f);
959+
951960
static_assert(_mm_cvtss_f32(k2) == +8.0f);
952961
}
953962

0 commit comments

Comments
 (0)