diff options
author | Matthias Kretz <m.kretz@gsi.de> | 2024-05-15 11:02:22 +0200 |
---|---|---|
committer | Matthias Kretz <m.kretz@gsi.de> | 2024-06-20 14:44:26 +0200 |
commit | f79b273d4145961133ef8b0344469e77425629f6 (patch) | |
tree | 1d9ef9f7c52f3adeeffe11a563150a1c7e07c56e | |
parent | fb067547e401940b433cf0d2ae30749b4c21492e (diff) | |
download | gcc-f79b273d4145961133ef8b0344469e77425629f6.zip gcc-f79b273d4145961133ef8b0344469e77425629f6.tar.gz gcc-f79b273d4145961133ef8b0344469e77425629f6.tar.bz2 |
libstdc++: Avoid MMX return types from __builtin_shufflevector
This resolves a regression on i686 that was introduced with
r15-429-gfb1649f8b4ad50.
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
libstdc++-v3/ChangeLog:
PR libstdc++/115247
* include/experimental/bits/simd.h (__as_vector): Don't use
vector_size(8) on __i386__.
(__vec_shuffle): Never return MMX vectors, widen to 16 bytes
instead.
(concat): Fix padding calculation to pick up widening logic from
__as_vector.
(cherry picked from commit 241a6cc88d866fb36bd35ddb3edb659453d6322e)
-rw-r--r-- | libstdc++-v3/include/experimental/bits/simd.h | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h index 6060629..2cc2807 100644 --- a/libstdc++-v3/include/experimental/bits/simd.h +++ b/libstdc++-v3/include/experimental/bits/simd.h @@ -1630,7 +1630,12 @@ template <typename _V> { static_assert(is_simd<_V>::value); using _Tp = typename _V::value_type; +#ifdef __i386__ + constexpr auto __bytes = sizeof(_Tp) == 8 ? 16 : sizeof(_Tp); + using _RV [[__gnu__::__vector_size__(__bytes)]] = _Tp; +#else using _RV [[__gnu__::__vector_size__(sizeof(_Tp))]] = _Tp; +#endif return _RV{__data(__x)}; } } @@ -2046,11 +2051,14 @@ template <typename _Tp, typename _TVT = _VectorTraits<_Tp>> // }}} // __vec_shuffle{{{ template <typename _T0, typename _T1, typename _Fun, size_t... _Is> - _GLIBCXX_SIMD_INTRINSIC constexpr auto + _GLIBCXX_SIMD_INTRINSIC constexpr + __vector_type_t<remove_reference_t<decltype(declval<_T0>()[0])>, sizeof...(_Is)> __vec_shuffle(_T0 __x, _T1 __y, index_sequence<_Is...> __seq, _Fun __idx_perm) { constexpr int _N0 = sizeof(__x) / sizeof(__x[0]); constexpr int _N1 = sizeof(__y) / sizeof(__y[0]); + using _Tp = remove_reference_t<decltype(declval<_T0>()[0])>; + using _RV [[maybe_unused]] = __vector_type_t<_Tp, sizeof...(_Is)>; #if __has_builtin(__builtin_shufflevector) #ifdef __clang__ // Clang requires _T0 == _T1 @@ -2070,14 +2078,23 @@ template <typename _T0, typename _T1, typename _Fun, size_t... _Is> }); else #endif - return __builtin_shufflevector(__x, __y, [=] { - constexpr int __j = __idx_perm(_Is); - static_assert(__j < _N0 + _N1); - return __j; - }()...); + { + const auto __r = __builtin_shufflevector(__x, __y, [=] { + constexpr int __j = __idx_perm(_Is); + static_assert(__j < _N0 + _N1); + return __j; + }()...); +#ifdef __i386__ + if constexpr (sizeof(__r) == sizeof(_RV)) + return __r; + else + return _RV {__r[_Is]...}; +#else + return __r; +#endif + } #else - using _Tp = __remove_cvref_t<decltype(__x[0])>; - return __vector_type_t<_Tp, sizeof...(_Is)> { + return _RV { [=]() -> _Tp { constexpr int __j = __idx_perm(_Is); static_assert(__j < _N0 + _N1); @@ -4310,9 +4327,9 @@ template <typename _Tp, typename... _As, typename = __detail::__odr_helper> __vec_shuffle(__as_vector(__xs)..., std::make_index_sequence<_RW::_S_full_size>(), [](int __i) { constexpr int __sizes[2] = {int(simd_size_v<_Tp, _As>)...}; - constexpr int __padding0 - = sizeof(__vector_type_t<_Tp, __sizes[0]>) / sizeof(_Tp) - - __sizes[0]; + constexpr int __vsizes[2] + = {int(sizeof(__as_vector(__xs)) / sizeof(_Tp))...}; + constexpr int __padding0 = __vsizes[0] - __sizes[0]; return __i >= _Np ? -1 : __i < __sizes[0] ? __i : __i + __padding0; })}; } |