From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7857) id 1CCAB3857722; Tue, 6 Jun 2023 13:45:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CCAB3857722 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686059128; bh=GnLuoV/jjJfL4u+xrLojZFaw768WxPOmEX6MPHKXUC8=; h=From:To:Subject:Date:From; b=E8zKu2fZUqwpfIXUSb5X0cC1B7CXSrHulw8KF3DhG7VTpyE0h9JsNtWYNiZpbEf+G ROhWjgFn00YXmgM9HKIqSl+1QwgkbTk0nlJa6e5Yd6WHT1OhkANH6fDLC8MVHDamyF WwJQgUpOePRPjIZlc4EGcrwqYwnWmKope4u27QrQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Matthias Kretz To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-1578] libstdc++: Avoid vector casts while still avoiding PR90424 X-Act-Checkin: gcc X-Git-Author: Matthias Kretz X-Git-Refname: refs/heads/master X-Git-Oldrev: 27e45b7597d6fb1a71927d658a0294797b720c0a X-Git-Newrev: 9165ede56ababd6471e7a2ce4eab30f3d5129e14 Message-Id: <20230606134528.1CCAB3857722@sourceware.org> Date: Tue, 6 Jun 2023 13:45:28 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9165ede56ababd6471e7a2ce4eab30f3d5129e14 commit r14-1578-g9165ede56ababd6471e7a2ce4eab30f3d5129e14 Author: Matthias Kretz Date: Fri Jun 2 21:33:04 2023 +0200 libstdc++: Avoid vector casts while still avoiding PR90424 Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/109822 * include/experimental/bits/simd_builtin.h (_S_store): Rewrite to avoid casts to other vector types. Implement store as succession of power-of-2 sized memcpy to avoid PR90424. Diff: --- .../include/experimental/bits/simd_builtin.h | 40 ++++++++-------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/libstdc++-v3/include/experimental/bits/simd_builtin.h b/libstdc++-v3/include/experimental/bits/simd_builtin.h index 64ef6efaf8c..6ccc2fcec9c 100644 --- a/libstdc++-v3/include/experimental/bits/simd_builtin.h +++ b/libstdc++-v3/include/experimental/bits/simd_builtin.h @@ -1295,6 +1295,18 @@ struct _CommonImplBuiltin // }}} // _S_store {{{ + template + _GLIBCXX_SIMD_INTRINSIC static void + _S_memcpy(char* __dst, const char* __src) + { + if constexpr (_Bytes > 0) + { + constexpr size_t _Ns = std::__bit_floor(_Bytes); + __builtin_memcpy(__dst, __src, _Ns); + _S_memcpy<_Bytes - _Ns>(__dst + _Ns, __src + _Ns); + } + } + template _GLIBCXX_SIMD_INTRINSIC static void _S_store(_TV __x, void* __addr) @@ -1302,33 +1314,11 @@ struct _CommonImplBuiltin constexpr size_t _Bytes = _ReqBytes == 0 ? sizeof(__x) : _ReqBytes; static_assert(sizeof(__x) >= _Bytes); +#if !defined __clang__ && _GLIBCXX_SIMD_WORKAROUND_PR90424 if constexpr (__is_vector_type_v<_TV>) - { - using _Tp = typename _VectorTraits<_TV>::value_type; - constexpr size_t _Np = _Bytes / sizeof(_Tp); - static_assert(_Np * sizeof(_Tp) == _Bytes); - -#ifdef _GLIBCXX_SIMD_WORKAROUND_PR90424 - using _Up = conditional_t< - (is_integral_v<_Tp> || _Bytes < 4), - conditional_t<(sizeof(__x) > sizeof(long long)), long long, _Tp>, - float>; - const auto __v = __vector_bitcast<_Up>(__x); -#else // _GLIBCXX_SIMD_WORKAROUND_PR90424 - const __vector_type_t<_Tp, _Np> __v = __x; -#endif // _GLIBCXX_SIMD_WORKAROUND_PR90424 - - if constexpr ((_Bytes & (_Bytes - 1)) != 0) - { - constexpr size_t _MoreBytes = std::__bit_ceil(_Bytes); - alignas(decltype(__v)) char __tmp[_MoreBytes]; - __builtin_memcpy(__tmp, &__v, _MoreBytes); - __builtin_memcpy(__addr, __tmp, _Bytes); - } - else - __builtin_memcpy(__addr, &__v, _Bytes); - } + _S_memcpy<_Bytes>(reinterpret_cast(__addr), reinterpret_cast(&__x)); else +#endif // _GLIBCXX_SIMD_WORKAROUND_PR90424 __builtin_memcpy(__addr, &__x, _Bytes); }