public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Fix type of first argument to vec_cntm call
@ 2023-05-24 15:04 Matthias Kretz
  2023-05-24 16:18 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Matthias Kretz @ 2023-05-24 15:04 UTC (permalink / raw)
  To: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 1417 bytes --]

OK for master and backports? (also a long-standing bug that didn't surface 
until the new constexpr test was added)

tested on powerpc64le-linux-gnu

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

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

libstdc++-v3/ChangeLog:

	PR libstdc++/109949
	* include/experimental/bits/simd.h (__intrinsic_type): If
	__ALTIVEC__ is defined, map gnu::vector_size types to their
	corresponding __vector T types without losing unsignedness of
	integer types. Also prefer long long over long.
	* include/experimental/bits/simd_ppc.h (_S_popcount): Cast mask
	object to the expected unsigned vector type.
---
 libstdc++-v3/include/experimental/bits/simd.h | 39 ++++++++++++++++---
 .../include/experimental/bits/simd_ppc.h      |  3 +-
 2 files changed, 36 insertions(+), 6 deletions(-)


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

[-- Attachment #2: 0001-libstdc-Fix-type-of-first-argument-to-vec_cntm-call.patch --]
[-- Type: text/x-patch, Size: 2295 bytes --]

diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h
index d1f388310f9..26f08f83ab0 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -2466,11 +2466,40 @@ struct __intrinsic_type<_Tp, _Bytes, enable_if_t<__is_vectorizable_v<_Tp> && _By
 		  "no __intrinsic_type support for 64-bit floating point on PowerPC w/o VSX");
 #endif
 
-    using type =
-      typename __intrinsic_type_impl<
-		 conditional_t<is_floating_point_v<_Tp>,
-			       conditional_t<_S_is_ldouble, double, _Tp>,
-			       __int_for_sizeof_t<_Tp>>>::type;
+    static constexpr auto __element_type()
+    {
+      if constexpr (is_floating_point_v<_Tp>)
+	{
+	  if constexpr (_S_is_ldouble)
+	    return double {};
+	  else
+	    return _Tp {};
+	}
+      else if constexpr (is_signed_v<_Tp>)
+	{
+	  if constexpr (sizeof(_Tp) == sizeof(_SChar))
+	    return _SChar {};
+	  else if constexpr (sizeof(_Tp) == sizeof(short))
+	    return short {};
+	  else if constexpr (sizeof(_Tp) == sizeof(int))
+	    return int {};
+	  else if constexpr (sizeof(_Tp) == sizeof(_LLong))
+	    return _LLong {};
+	}
+      else
+	{
+	  if constexpr (sizeof(_Tp) == sizeof(_UChar))
+	    return _UChar {};
+	  else if constexpr (sizeof(_Tp) == sizeof(_UShort))
+	    return _UShort {};
+	  else if constexpr (sizeof(_Tp) == sizeof(_UInt))
+	    return _UInt {};
+	  else if constexpr (sizeof(_Tp) == sizeof(_ULLong))
+	    return _ULLong {};
+	}
+    }
+
+    using type = typename __intrinsic_type_impl<decltype(__element_type())>::type;
   };
 #endif // __ALTIVEC__
 
diff --git a/libstdc++-v3/include/experimental/bits/simd_ppc.h b/libstdc++-v3/include/experimental/bits/simd_ppc.h
index eca1b34241b..2ea7234bd99 100644
--- a/libstdc++-v3/include/experimental/bits/simd_ppc.h
+++ b/libstdc++-v3/include/experimental/bits/simd_ppc.h
@@ -130,7 +130,8 @@ _S_popcount(simd_mask<_Tp, _Abi> __k)
 	const auto __kv = __as_vector(__k);
 	if constexpr (__have_power10vec)
 	  {
-	    return vec_cntm(__to_intrin(__kv), 1);
+	    using _Intrin = __intrinsic_type16_t<make_unsigned_t<__int_for_sizeof_t<_Tp>>>;
+	    return vec_cntm(reinterpret_cast<_Intrin>(__kv), 1);
 	  }
 	else if constexpr (sizeof(_Tp) >= sizeof(int))
 	  {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libstdc++: Fix type of first argument to vec_cntm call
  2023-05-24 15:04 [PATCH] libstdc++: Fix type of first argument to vec_cntm call Matthias Kretz
@ 2023-05-24 16:18 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2023-05-24 16:18 UTC (permalink / raw)
  To: Matthias Kretz; +Cc: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 1665 bytes --]

On Wed, 24 May 2023 at 16:06, Matthias Kretz via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:

> OK for master and backports? (also a long-standing bug that didn't surface
> until the new constexpr test was added)
>

OK for all


>
> tested on powerpc64le-linux-gnu
>
> ------------- 8< -----------------
>
> Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/109949
>         * include/experimental/bits/simd.h (__intrinsic_type): If
>         __ALTIVEC__ is defined, map gnu::vector_size types to their
>         corresponding __vector T types without losing unsignedness of
>         integer types. Also prefer long long over long.
>         * include/experimental/bits/simd_ppc.h (_S_popcount): Cast mask
>         object to the expected unsigned vector type.
> ---
>  libstdc++-v3/include/experimental/bits/simd.h | 39 ++++++++++++++++---
>  .../include/experimental/bits/simd_ppc.h      |  3 +-
>  2 files changed, 36 insertions(+), 6 deletions(-)
>
>
> --
> ──────────────────────────────────────────────────────────────────────────
>  Dr. Matthias Kretz                           https://mattkretz.github.io
>  GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
>  stdₓ::simd
> ──────────────────────────────────────────────────────────────────────────

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-24 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-24 15:04 [PATCH] libstdc++: Fix type of first argument to vec_cntm call Matthias Kretz
2023-05-24 16:18 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).