public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Fix conversion of simd to vector builtin
@ 2024-04-22 15:30 Matthias Kretz
  2024-04-22 16:04 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Matthias Kretz @ 2024-04-22 15:30 UTC (permalink / raw)
  To: gcc-patches, libstdc++

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

Tested on x86_64-linux-gnu, powerpc64le-linux-gnu, aarch64-linux-gnu, arm-
linux-gnueabihf

OK for trunk and backports?

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

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

libstdc++-v3/ChangeLog:

	PR libstdc++/114803
	* include/experimental/bits/simd_builtin.h
	(_SimdBase2::operator __vector_type_t): There is no __builtin()
	function in _SimdWrapper, instead use its conversion operator.
	* testsuite/experimental/simd/pr114803_vecbuiltin_cvt.cc: New
	test.
---
 .../include/experimental/bits/simd_builtin.h  |   2 +-
 .../simd/pr114803_vecbuiltin_cvt.cc           | 105 ++++++++++++++++++
 2 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/experimental/simd/
pr114803_vecbuiltin_cvt.cc

diff --git a/libstdc++-v3/include/experimental/bits/simd_builtin.h b/libstdc+
+-v3/include/experimental/bits/simd_builtin.h
index 49c7c7e1c70..4ceeb423894 100644
--- a/libstdc++-v3/include/experimental/bits/simd_builtin.h
+++ b/libstdc++-v3/include/experimental/bits/simd_builtin.h
@@ -841,7 +841,7 @@ struct _SimdBase2
 
       _GLIBCXX_SIMD_ALWAYS_INLINE explicit
       operator __vector_type_t<_Tp, _Np>() const
-      { return static_cast<const simd<_Tp, _Abi>*>(this)-
>_M_data.__builtin(); }
+      { return __data(*static_cast<const simd<_Tp, _Abi>*>(this)); }
     };
 
     struct _SimdBase1
diff --git a/libstdc++-v3/testsuite/experimental/simd/
pr114803_vecbuiltin_cvt.cc b/libstdc++-v3/testsuite/experimental/simd/
pr114803_vecbuiltin_cvt.cc
new file mode 100644
index 00000000000..103dd19394c
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/simd/pr114803_vecbuiltin_cvt.cc
@@ -0,0 +1,105 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <experimental/simd>
+
+template <typename T>
+  void
+  maybe_test()
+  {
+    using V = std::experimental::simd<T, 
std::experimental::simd_abi::_VecBuiltin<16>>;
+    if constexpr (std::is_destructible_v<V>)
+      {
+	using V2 [[gnu::vector_size(16)]] = T;
+	V x = {};
+	V2 x2 = static_cast<V2>(x);
+	x = static_cast<V>(x2);
+	for (unsigned i = 0; i < V::size(); ++i)
+	  {
+	    if (x2[i] != 0)
+	      __builtin_abort();
+	  }
+#ifdef __SSE__
+	if constexpr (std::is_same_v<T, float>)
+	  x = static_cast<V>(static_cast<__m128>(x));
+	else if constexpr (std::is_same_v<T, double>)
+	  x = static_cast<V>(static_cast<__m128d>(x));
+	else if constexpr (std::is_integral_v<T>)
+	  x = static_cast<V>(static_cast<__m128i>(x));
+#elif __ALTIVEC__
+	if constexpr (std::is_same_v<T, float>)
+	  x = static_cast<V>(static_cast<__vector float>(x));
+#ifdef __VSX__
+	else if constexpr (std::is_same_v<T, double>)
+	  x = static_cast<V>(static_cast<__vector double>(x));
+#endif
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 
sizeof(signed char)
+			     && std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<__vector signed char>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 
sizeof(signed char))
+	  x = static_cast<V>(static_cast<__vector unsigned char>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 
sizeof(short)
+			     && std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<__vector signed short>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 
sizeof(short))
+	  x = static_cast<V>(static_cast<__vector unsigned short>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == sizeof(int)
+			     && std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<__vector signed int>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == sizeof(int))
+	  x = static_cast<V>(static_cast<__vector unsigned int>(x));
+#ifdef __VSX__
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == sizeof(long 
long)
+			     && std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<__vector signed long long>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == sizeof(long 
long))
+	  x = static_cast<V>(static_cast<__vector unsigned long long>(x));
+#endif
+#elif __ARM_NEON
+	if constexpr (std::is_same_v<T, float>)
+	  x = static_cast<V>(static_cast<float32x4_t>(x));
+#ifdef __aarch64__
+	else if constexpr (std::is_same_v<T, double>)
+	  x = static_cast<V>(static_cast<float64x2_t>(x));
+#endif
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 1 && 
std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<int8x16_t>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 1)
+	  x = static_cast<V>(static_cast<uint8x16_t>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 2 && 
std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<int16x8_t>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 2)
+	  x = static_cast<V>(static_cast<uint16x8_t>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 4 && 
std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<int32x4_t>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 4)
+	  x = static_cast<V>(static_cast<uint32x4_t>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 8 && 
std::is_signed_v<T>)
+	  x = static_cast<V>(static_cast<int64x2_t>(x));
+	else if constexpr (std::is_integral_v<T> && sizeof(T) == 8)
+	  x = static_cast<V>(static_cast<uint64x2_t>(x));
+#endif
+      }
+  }
+
+int main()
+{
+  maybe_test<char>();
+  maybe_test<wchar_t>();
+  maybe_test<char16_t>();
+  maybe_test<char32_t>();
+
+  maybe_test<signed char>();
+  maybe_test<unsigned char>();
+  maybe_test<short>();
+  maybe_test<unsigned short>();
+  maybe_test<int>();
+  maybe_test<unsigned int>();
+  maybe_test<long>();
+  maybe_test<unsigned long>();
+  maybe_test<long long>();
+  maybe_test<unsigned long long>();
+  maybe_test<float>();
+  maybe_test<double>();
+  maybe_test<long double>();
+}
-- 
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
 stdₓ::simd
──────────────────────────────────────────────────────────────────────────


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2024-04-22 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 15:30 [PATCH] libstdc++: Fix conversion of simd to vector builtin Matthias Kretz
2024-04-22 16:04 ` 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).