From 97383b4116ea63486eb5bfb0a7140871bed75fb4 Mon Sep 17 00:00:00 2001 From: Matthias Kretz Date: Wed, 22 Mar 2023 08:12:08 +0100 Subject: [PATCH] libstdc++: Add missing trait is_simd_flag_type Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (is_simd_flag_type): New. (_IsSimdFlagType): New. (copy_from, copy_to, load ctors): Constrain _Flags using _IsSimdFlagType. --- libstdc++-v3/include/experimental/bits/simd.h | 52 ++++++++++++++++++++------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h index 4df4466..224153f 100644 --- a/libstdc++-v3/include/experimental/bits/simd.h +++ b/libstdc++-v3/include/experimental/bits/simd.h @@ -2837,6 +2837,32 @@ template } // namespace simd_abi // traits {{{1 +template + struct is_simd_flag_type + : false_type + {}; + +template <> + struct is_simd_flag_type + : true_type + {}; + +template <> + struct is_simd_flag_type + : true_type + {}; + +template + struct is_simd_flag_type> + : __bool_constant<(_Np > 0) and __has_single_bit(_Np)> + {}; + +template + inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value; + +template >> + using _IsSimdFlagType = _Tp; + // is_abi_tag {{{2 template > struct is_abi_tag : false_type {}; @@ -3308,7 +3334,7 @@ template template [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _V - copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _Flags) const&& + copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) const&& { return {__private_init, _Impl::_S_masked_load(__data(_M_value), __data(_M_k), @@ -3317,7 +3343,7 @@ template template _GLIBCXX_SIMD_INTRINSIC void - copy_to(_LoadStorePtr<_Up, value_type>* __mem, _Flags) const&& + copy_to(_LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) const&& { _Impl::_S_masked_store(__data(_M_value), _Flags::template _S_apply<_V>(__mem), @@ -3363,12 +3389,12 @@ template template [[nodiscard]] _GLIBCXX_SIMD_INTRINSIC _V - copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _Flags) const&& + copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) const&& { return _M_k ? static_cast<_V>(__mem[0]) : _M_value; } template _GLIBCXX_SIMD_INTRINSIC void - copy_to(_LoadStorePtr<_Up, value_type>* __mem, _Flags) const&& + copy_to(_LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) const&& { if (_M_k) __mem[0] = _M_value; @@ -3466,7 +3492,7 @@ template // intentionally hides const_where_expression::copy_from template _GLIBCXX_SIMD_INTRINSIC void - copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _Flags) && + copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) && { __data(_M_value) = _Impl::_S_masked_load(__data(_M_value), __data(_M_k), _Flags::template _S_apply<_Tp>(__mem)); @@ -3529,7 +3555,7 @@ template // intentionally hides const_where_expression::copy_from template _GLIBCXX_SIMD_INTRINSIC void - copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _Flags) && + copy_from(const _LoadStorePtr<_Up, value_type>* __mem, _IsSimdFlagType<_Flags>) && { if (_M_k) _M_value = __mem[0]; } }; @@ -4574,12 +4600,12 @@ template // load constructor {{{ template _GLIBCXX_SIMD_ALWAYS_INLINE - simd_mask(const value_type* __mem, _Flags) + simd_mask(const value_type* __mem, _IsSimdFlagType<_Flags>) : _M_data(_Impl::template _S_load<_Ip>(_Flags::template _S_apply(__mem))) {} template _GLIBCXX_SIMD_ALWAYS_INLINE - simd_mask(const value_type* __mem, simd_mask __k, _Flags) + simd_mask(const value_type* __mem, simd_mask __k, _IsSimdFlagType<_Flags>) : _M_data{} { _M_data = _Impl::_S_masked_load(_M_data, __k._M_data, @@ -4590,14 +4616,14 @@ template // loads [simd_mask.load] {{{ template _GLIBCXX_SIMD_ALWAYS_INLINE void - copy_from(const value_type* __mem, _Flags) + copy_from(const value_type* __mem, _IsSimdFlagType<_Flags>) { _M_data = _Impl::template _S_load<_Ip>(_Flags::template _S_apply(__mem)); } // }}} // stores [simd_mask.store] {{{ template _GLIBCXX_SIMD_ALWAYS_INLINE void - copy_to(value_type* __mem, _Flags) const + copy_to(value_type* __mem, _IsSimdFlagType<_Flags>) const { _Impl::_S_store(_M_data, _Flags::template _S_apply(__mem)); } // }}} @@ -5210,7 +5236,7 @@ template // load constructor template _GLIBCXX_SIMD_ALWAYS_INLINE - simd(const _Up* __mem, _Flags) + simd(const _Up* __mem, _IsSimdFlagType<_Flags>) : _M_data( _Impl::_S_load(_Flags::template _S_apply(__mem), _S_type_tag)) {} @@ -5218,7 +5244,7 @@ template // loads [simd.load] template _GLIBCXX_SIMD_ALWAYS_INLINE void - copy_from(const _Vectorizable<_Up>* __mem, _Flags) + copy_from(const _Vectorizable<_Up>* __mem, _IsSimdFlagType<_Flags>) { _M_data = static_cast( _Impl::_S_load(_Flags::template _S_apply(__mem), _S_type_tag)); @@ -5227,7 +5253,7 @@ template // stores [simd.store] template _GLIBCXX_SIMD_ALWAYS_INLINE void - copy_to(_Vectorizable<_Up>* __mem, _Flags) const + copy_to(_Vectorizable<_Up>* __mem, _IsSimdFlagType<_Flags>) const { _Impl::_S_store(_M_data, _Flags::template _S_apply(__mem), _S_type_tag); -- 2.7.4