libstdc++: Add missing trait is_simd_flag_type

Message ID 5441527.e9J7NaK4W3@minbar
State Accepted
Headers
Series libstdc++: Add missing trait is_simd_flag_type |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Matthias Kretz March 28, 2023, 10:40 a.m. UTC
  I don't know how, but I forgot to implement the 
is_simd_flag_type trait. This fixes it.

No new check-simd failures on x86_64-pc-linux-gnu

--------------- 8< ------------------

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

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(-)


--
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
 stdₓ::simd
──────────────────────────────────────────────────────────────────────────
  

Comments

Jonathan Wakely March 28, 2023, 1:41 p.m. UTC | #1
On Tue, 28 Mar 2023 at 11:41, Matthias Kretz via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> I don't know how, but I forgot to implement the
> is_simd_flag_type trait. This fixes it.
>
> No new check-simd failures on x86_64-pc-linux-gnu

OK

>
> --------------- 8< ------------------
>
> Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
>
> 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(-)
>
>
> --
> ──────────────────────────────────────────────────────────────────────────
>  Dr. Matthias Kretz                           https://mattkretz.github.io
>  GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
>  stdₓ::simd
> ──────────────────────────────────────────────────────────────────────────
  

Patch

diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h
index 4df446654ac..224153ffbaf 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -2837,6 +2837,32 @@  __determine_native_abi()
 } // namespace simd_abi
 
 // traits {{{1
+template <typename _Tp>
+  struct is_simd_flag_type
+  : false_type
+  {};
+
+template <>
+  struct is_simd_flag_type<element_aligned_tag>
+  : true_type
+  {};
+
+template <>
+  struct is_simd_flag_type<vector_aligned_tag>
+  : true_type
+  {};
+
+template <size_t _Np>
+  struct is_simd_flag_type<overaligned_tag<_Np>>
+  : __bool_constant<(_Np > 0) and __has_single_bit(_Np)>
+  {};
+
+template <typename _Tp>
+  inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value;
+
+template <typename _Tp, typename = enable_if_t<is_simd_flag_type_v<_Tp>>>
+  using _IsSimdFlagType = _Tp;
+
 // is_abi_tag {{{2
 template <typename _Tp, typename = void_t<>>
   struct is_abi_tag : false_type {};
@@ -3308,7 +3334,7 @@  __get_lvalue(const const_where_expression& __x)
 
     template <typename _Up, typename _Flags>
       [[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 @@  __get_lvalue(const const_where_expression& __x)
 
     template <typename _Up, typename _Flags>
       _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 @@  __get_lvalue(const const_where_expression& __x)
 
     template <typename _Up, typename _Flags>
       [[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 <typename _Up, typename _Flags>
       _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 @@  static_assert(
     // intentionally hides const_where_expression::copy_from
     template <typename _Up, typename _Flags>
       _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 @@  where_expression(const _M& __kk, _Tp& dd)
     // intentionally hides const_where_expression::copy_from
     template <typename _Up, typename _Flags>
       _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 @@  simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __x)
     // load constructor {{{
     template <typename _Flags>
       _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<simd_mask>(__mem))) {}
 
     template <typename _Flags>
       _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 @@  simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __x)
     // loads [simd_mask.load] {{{
     template <typename _Flags>
       _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<simd_mask>(__mem)); }
 
     // }}}
     // stores [simd_mask.store] {{{
     template <typename _Flags>
       _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<simd_mask>(__mem)); }
 
     // }}}
@@ -5210,7 +5236,7 @@  simd(const simd<_Up, _A2>& __x)
     // load constructor
     template <typename _Up, typename _Flags>
       _GLIBCXX_SIMD_ALWAYS_INLINE
-      simd(const _Up* __mem, _Flags)
+      simd(const _Up* __mem, _IsSimdFlagType<_Flags>)
       : _M_data(
 	  _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag))
       {}
@@ -5218,7 +5244,7 @@  simd(const simd<_Up, _A2>& __x)
     // loads [simd.load]
     template <typename _Up, typename _Flags>
       _GLIBCXX_SIMD_ALWAYS_INLINE void
-      copy_from(const _Vectorizable<_Up>* __mem, _Flags)
+      copy_from(const _Vectorizable<_Up>* __mem, _IsSimdFlagType<_Flags>)
       {
 	_M_data = static_cast<decltype(_M_data)>(
 	  _Impl::_S_load(_Flags::template _S_apply<simd>(__mem), _S_type_tag));
@@ -5227,7 +5253,7 @@  simd(const simd<_Up, _A2>& __x)
     // stores [simd.store]
     template <typename _Up, typename _Flags>
       _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<simd>(__mem),
 			_S_type_tag);