[PATCH] libstdc++: Resolve integer type mismatches in stdx::simd [PR122981]
Matthias Kretz <[email protected]>
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.libstdc++.devel |
|---|---|
| Organization | GSI Helmholtz Center for Heavy Ion Research |
| Message-ID | <[email protected]> |
Tested on x86_64, powerpc64 (le and be), aarch64, arm-none-eabi, and arm- linux-gnueabi. OK for trunk and backports? This supersedes Torbjörn SVENSSON's patch. Thanks Torbjörn for the important hint that int32_t is not an alias for int on arm-none-eabi! ---------------- 8< --------------- From: Matthias Kretz <[email protected]> Conversions from generic vector to ARM vector are rejected when the value type is not equal. Since arm-none-eabi defines int32_t as long rather than int, a generic int vector passed as int32x2_t argument is ill-formed. With this patch, use the intN_t aliases in general: for the central __int_for_sizeof meta function and when bitcasting vectors in the NEON popcount implementation. This solution avoids unnecessary reinterpretation of generic vectors as ARM vectors, keeping it a tiny bit more type safe. libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__int_for_sizeof): Return int32_t, int8_t, int16_t, and int64_t, rather than int, signed char, short, long, and long long. * include/experimental/bits/simd_neon.h (_S_popcount): Cast elements to int8_t, int16_t, int32_t, or int64_t, rather than signed char, short, int, or long. Signed-off-by: Matthias Kretz <[email protected]> --- libstdc++-v3/include/experimental/bits/simd.h | 18 ++++++++---------- .../include/experimental/bits/simd_neon.h | 8 ++++---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/ include/experimental/bits/simd.h index 5b3f622c6ea..69085859819 100644 --- a/libstdc++-v3/include/experimental/bits/simd.h +++ b/libstdc++-v3/include/experimental/bits/simd.h @@ -608,16 +608,14 @@ struct __is_bitmask __int_for_sizeof() { static_assert(_Bytes > 0); - if constexpr (_Bytes == sizeof(int)) - return int(); - else if constexpr (_Bytes == sizeof(_SChar)) - return _SChar(); - else if constexpr (_Bytes == sizeof(short)) - return short(); - else if constexpr (_Bytes == sizeof(long)) - return long(); - else if constexpr (_Bytes == sizeof(_LLong)) - return _LLong(); + if constexpr (_Bytes == sizeof(int32_t)) + return int32_t(); + else if constexpr (_Bytes == sizeof(int8_t)) + return int8_t(); + else if constexpr (_Bytes == sizeof(int16_t)) + return int16_t(); + else if constexpr (_Bytes == sizeof(int64_t)) + return int64_t(); #ifdef __SIZEOF_INT128__ else if constexpr (_Bytes == sizeof(__int128)) return __int128(); diff --git a/libstdc++-v3/include/experimental/bits/simd_neon.h b/libstdc++- v3/include/experimental/bits/simd_neon.h index 8fabee7f328..e032a1ea535 100644 --- a/libstdc++-v3/include/experimental/bits/simd_neon.h +++ b/libstdc++-v3/include/experimental/bits/simd_neon.h @@ -480,27 +480,27 @@ _S_popcount(simd_mask<_Tp, _Abi> __k) { if constexpr (sizeof(_Tp) == 1) { - const auto __s8 = __vector_bitcast<_SChar>(__k._M_data); + const auto __s8 = __vector_bitcast<int8_t>(__k._M_data); int8x8_t __tmp = __lo64(__s8) + __hi64z(__s8); return -vpadd_s8(vpadd_s8(vpadd_s8(__tmp, int8x8_t()), int8x8_t()), int8x8_t())[0]; } else if constexpr (sizeof(_Tp) == 2) { - const auto __s16 = __vector_bitcast<short>(__k._M_data); + const auto __s16 = __vector_bitcast<int16_t>(__k._M_data); int16x4_t __tmp = __lo64(__s16) + __hi64z(__s16); return -vpadd_s16(vpadd_s16(__tmp, int16x4_t()), int16x4_t())[0]; } else if constexpr (sizeof(_Tp) == 4) { - const auto __s32 = __vector_bitcast<int>(__k._M_data); + const auto __s32 = __vector_bitcast<int32_t>(__k._M_data); int32x2_t __tmp = __lo64(__s32) + __hi64z(__s32); return -vpadd_s32(__tmp, int32x2_t())[0]; } else if constexpr (sizeof(_Tp) == 8) { static_assert(sizeof(__k) == 16); - const auto __s64 = __vector_bitcast<long>(__k._M_data); + const auto __s64 = __vector_bitcast<int64_t>(__k._M_data); return -(__s64[0] + __s64[1]); } } -- ────────────────────────────────────────────────────────────────────────── Dr. Matthias Kretz https://mattkretz.github.io GSI Helmholtz Center for Heavy Ion Research https://gsi.de std::simd ──────────────────────────────────────────────────────────────────────────