[1/8] libstdc++: Simplify three helper functions into one

Message ID 7492903.EvYhyI6sBW@minbar
State Repeat Merge
Headers
Series std::experimental::simd patchset |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Matthias Kretz Feb. 23, 2023, 8:49 a.m. UTC
  Broadcast is a very common function. This should reduce compile-time
effort.

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

libstdc++-v3/ChangeLog:

	PR libstdc++/108030
	* include/experimental/bits/simd.h (__vector_broadcast):
	Implement via __vector_broadcast_impl instead of
	__call_with_n_evaluations + 2 lambdas.
	(__vector_broadcast_impl): New.
---
 libstdc++-v3/include/experimental/bits/simd.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)


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

Comments

Jonathan Wakely Feb. 23, 2023, 11:05 a.m. UTC | #1
On Thu, 23 Feb 2023 at 08:53, Matthias Kretz via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
>
>
> Broadcast is a very common function. This should reduce compile-time
> effort.

OK for all branches.

> Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/108030
>         * include/experimental/bits/simd.h (__vector_broadcast):
>         Implement via __vector_broadcast_impl instead of
>         __call_with_n_evaluations + 2 lambdas.
>         (__vector_broadcast_impl): New.
> ---
>  libstdc++-v3/include/experimental/bits/simd.h | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
>
> --
> ──────────────────────────────────────────────────────────────────────────
>  Dr. Matthias Kretz                           https://mattkretz.github.io
>  GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
>  stdₓ::simd
> ──────────────────────────────────────────────────────────────────────────
  

Patch

diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h
index 2f615d13b73..7482d109291 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -1798,15 +1798,15 @@  __to_intrin(_Tp __x)
 
 // }}}
 // __vector_broadcast{{{
+template <size_t _Np, typename _Tp, size_t... _I>
+  _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np>
+  __vector_broadcast_impl(_Tp __x, index_sequence<_I...>)
+  { return __vector_type_t<_Tp, _Np>{((void)_I, __x)...}; }
+
 template <size_t _Np, typename _Tp>
   _GLIBCXX_SIMD_INTRINSIC constexpr __vector_type_t<_Tp, _Np>
   __vector_broadcast(_Tp __x)
-  {
-    return __call_with_n_evaluations<_Np>(
-      [](auto... __xx) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA {
-	return __vector_type_t<_Tp, _Np>{__xx...};
-      }, [&__x](int) _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA { return __x; });
-  }
+  { return __vector_broadcast_impl<_Np, _Tp>(__x, make_index_sequence<_Np>()); }
 
 // }}}
 // __generate_vector{{{