aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Kretz <m.kretz@gsi.de>2023-05-26 12:23:44 +0200
committerMatthias Kretz <m.kretz@gsi.de>2023-05-30 16:19:07 +0200
commit668d43502f465d48adbc1fe2956b979f36657e5f (patch)
tree0ecc26e88b2b83f088b12b6327b7263bb4107e38
parent3e2689e568425f14d6728504ad6f5d32b90320ad (diff)
downloadgcc-668d43502f465d48adbc1fe2956b979f36657e5f.zip
gcc-668d43502f465d48adbc1fe2956b979f36657e5f.tar.gz
gcc-668d43502f465d48adbc1fe2956b979f36657e5f.tar.bz2
libstdc++: Correct NTTP and simd_mask ctor call
Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: PR libstdc++/109822 * include/experimental/bits/simd.h (to_native): Use int NTTP as specified in PTS2. (to_compatible): Likewise. Add missing tag to call mask generator ctor. * testsuite/experimental/simd/pr109822_cast_functions.cc: New test.
-rw-r--r--libstdc++-v3/include/experimental/bits/simd.h7
-rw-r--r--libstdc++-v3/testsuite/experimental/simd/pr109822_cast_functions.cc63
2 files changed, 67 insertions, 3 deletions
diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h
index 26f08f8..f94b836 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -3304,7 +3304,7 @@ template <typename _Tp, int _Np>
return {__mem, vector_aligned};
}
-template <typename _Tp, size_t _Np>
+template <typename _Tp, int _Np>
_GLIBCXX_SIMD_INTRINSIC
enable_if_t<(_Np == native_simd_mask<_Tp>::size()), native_simd_mask<_Tp>>
to_native(const fixed_size_simd_mask<_Tp, _Np>& __x)
@@ -3315,7 +3315,7 @@ template <typename _Tp, size_t _Np>
}
// to_compatible {{{2
-template <typename _Tp, size_t _Np>
+template <typename _Tp, int _Np>
_GLIBCXX_SIMD_INTRINSIC enable_if_t<(_Np == simd<_Tp>::size()), simd<_Tp>>
to_compatible(const simd<_Tp, simd_abi::fixed_size<_Np>>& __x)
{
@@ -3324,12 +3324,13 @@ template <typename _Tp, size_t _Np>
return {__mem, vector_aligned};
}
-template <typename _Tp, size_t _Np>
+template <typename _Tp, int _Np>
_GLIBCXX_SIMD_INTRINSIC
enable_if_t<(_Np == simd_mask<_Tp>::size()), simd_mask<_Tp>>
to_compatible(const simd_mask<_Tp, simd_abi::fixed_size<_Np>>& __x)
{
return simd_mask<_Tp>(
+ __private_init,
[&](auto __i) constexpr _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { return __x[__i]; });
}
diff --git a/libstdc++-v3/testsuite/experimental/simd/pr109822_cast_functions.cc b/libstdc++-v3/testsuite/experimental/simd/pr109822_cast_functions.cc
new file mode 100644
index 0000000..3deafbf
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/simd/pr109822_cast_functions.cc
@@ -0,0 +1,63 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <experimental/simd>
+
+namespace stdx = std::experimental;
+
+template <typename T, typename V>
+ void
+ test01()
+ {
+ using M = typename V::mask_type;
+ [[maybe_unused]] auto x = to_fixed_size(V());
+ [[maybe_unused]] auto k = to_fixed_size(M());
+ if constexpr (stdx::simd<T>::size() == V::size())
+ {
+ [[maybe_unused]] auto xx = to_compatible(x);
+ [[maybe_unused]] auto kk = to_compatible(k);
+ x = to_fixed_size(xx);
+ k = to_fixed_size(kk);
+ }
+ if constexpr (stdx::native_simd<T>::size() == V::size())
+ {
+ [[maybe_unused]] auto xx = to_native(x);
+ [[maybe_unused]] auto kk = to_native(k);
+ x = to_fixed_size(xx);
+ k = to_fixed_size(kk);
+ }
+ }
+
+template <typename T>
+ void
+ iterate_abis()
+ {
+ test01<T, stdx::simd<T, stdx::simd_abi::scalar>>();
+ test01<T, stdx::simd<T>>();
+ test01<T, stdx::native_simd<T>>();
+ test01<T, stdx::fixed_size_simd<T, 3>>();
+ test01<T, stdx::fixed_size_simd<T, stdx::simd_abi::max_fixed_size<T> - 4>>();
+ }
+
+int
+main()
+{
+ iterate_abis<char>();
+ iterate_abis<wchar_t>();
+ iterate_abis<char16_t>();
+ iterate_abis<char32_t>();
+
+ iterate_abis<signed char>();
+ iterate_abis<unsigned char>();
+ iterate_abis<short>();
+ iterate_abis<unsigned short>();
+ iterate_abis<int>();
+ iterate_abis<unsigned int>();
+ iterate_abis<long>();
+ iterate_abis<unsigned long>();
+ iterate_abis<long long>();
+ iterate_abis<unsigned long long>();
+ iterate_abis<float>();
+ iterate_abis<double>();
+ iterate_abis<long double>();
+}