]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix type of first argument to vec_cntm call
authorMatthias Kretz <m.kretz@gsi.de>
Wed, 24 May 2023 14:43:07 +0000 (16:43 +0200)
committerMatthias Kretz <m.kretz@gsi.de>
Wed, 24 May 2023 19:34:16 +0000 (21:34 +0200)
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
libstdc++-v3/include/experimental/bits/simd_ppc.h

index d1f388310f912b1525150751b4dd9a95dcda752a..26f08f83ab0005dc921579335bb1510842288f2c 100644 (file)
@@ -2466,11 +2466,40 @@ template <typename _Tp, size_t _Bytes>
                  "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__
 
index eca1b34241bb4efdbbb6490550750d81aee248b3..2ea7234bd99f4d3e8c22a410c823ff451df2e309 100644 (file)
@@ -130,7 +130,8 @@ template <typename _Abi, typename>
        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))
          {