From: Jonathan Wakely <jwakely@redhat.com>
To: Matthias Kretz <m.kretz@gsi.de>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Fix conversion of simd to vector builtin
Date: Mon, 22 Apr 2024 17:04:12 +0100 [thread overview]
Message-ID: <CACb0b4mHafEejaA7_DRWj6P4b8v0r+nVc7bj4PoqAF1q7Ud2tA@mail.gmail.com> (raw)
In-Reply-To: <14471703.uLZWGnKmhe@centauriprime>
On Mon, 22 Apr 2024 at 16:30, Matthias Kretz <m.kretz@gsi.de> wrote:
>
> Tested on x86_64-linux-gnu, powerpc64le-linux-gnu, aarch64-linux-gnu, arm-
> linux-gnueabihf
>
> OK for trunk and backports?
OK
>
> ----------------------------- 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
> ──────────────────────────────────────────────────────────────────────────
>
prev parent reply other threads:[~2024-04-22 16:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 15:30 Matthias Kretz
2024-04-22 16:04 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACb0b4mHafEejaA7_DRWj6P4b8v0r+nVc7bj4PoqAF1q7Ud2tA@mail.gmail.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=m.kretz@gsi.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).