diff mbox series

[4/8] libstdc++: Add missing constexpr on simd shift implementation

Message ID 2550642.Lt9SDvczpP@minbar
State New
Headers show
Series std::experimental::simd patchset | expand

Commit Message

Matthias Kretz Feb. 23, 2023, 8:49 a.m. UTC
Resolves -Wtautological-compare warnings about `if
(__builtin_is_constant_evaluated())` in the implementations of these
functions.

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

libstdc++-v3/ChangeLog:

	* include/experimental/bits/simd_x86.h (_S_bit_shift_left)
	(_S_bit_shift_right): Declare constexpr. The implementation was
	already expecting constexpr evaluation.
---
 libstdc++-v3/include/experimental/bits/simd_x86.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 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:07 a.m. UTC | #1
On Thu, 23 Feb 2023 at 08:55, Matthias Kretz via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
>
>
> Resolves -Wtautological-compare warnings about `if
> (__builtin_is_constant_evaluated())` in the implementations of these
> functions.

The 'inline' is redundant now, because these are unconditionally
constexpr which implies inline.

OK for all branches, with or without removing the 'inline'.


>
> Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
>
> libstdc++-v3/ChangeLog:
>
>         * include/experimental/bits/simd_x86.h (_S_bit_shift_left)
>         (_S_bit_shift_right): Declare constexpr. The implementation was
>         already expecting constexpr evaluation.
> ---
>  libstdc++-v3/include/experimental/bits/simd_x86.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
>
> --
> ──────────────────────────────────────────────────────────────────────────
>  Dr. Matthias Kretz                           https://mattkretz.github.io
>  GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
>  stdₓ::simd
> ──────────────────────────────────────────────────────────────────────────
Matthias Kretz Feb. 23, 2023, 11:33 a.m. UTC | #2
On Thursday, 23 February 2023 12:07:11 CET Jonathan Wakely wrote:
> On Thu, 23 Feb 2023 at 08:55, Matthias Kretz via Libstdc++
> 
> <libstdc++@gcc.gnu.org> wrote:
> > Resolves -Wtautological-compare warnings about `if
> > (__builtin_is_constant_evaluated())` in the implementations of these
> > functions.
> 
> The 'inline' is redundant now, because these are unconditionally
> constexpr which implies inline.

In the simd implementation I always have to make a conscious choice of 
always_inline vs. inline. Having the inline keyword there helps documenting 
that choice and helps revisiting all not-always_inline functions quickly.
diff mbox series

Patch

diff --git a/libstdc++-v3/include/experimental/bits/simd_x86.h b/libstdc++-v3/include/experimental/bits/simd_x86.h
index 897a67829d1..8872ca301b9 100644
--- a/libstdc++-v3/include/experimental/bits/simd_x86.h
+++ b/libstdc++-v3/include/experimental/bits/simd_x86.h
@@ -1526,7 +1526,7 @@  _S_modulus(_SimdWrapper<_Tp, _Np> __x, _SimdWrapper<_Tp, _Np> __y)
     // values.
   #ifndef _GLIBCXX_SIMD_NO_SHIFT_OPT
     template <typename _Tp, typename _TVT = _VectorTraits<_Tp>>
-      inline _GLIBCXX_CONST static typename _TVT::type
+      constexpr inline _GLIBCXX_CONST static typename _TVT::type
       _S_bit_shift_left(_Tp __xx, int __y)
       {
 	using _V = typename _TVT::type;
@@ -1631,7 +1631,7 @@  unsigned(
       }
 
     template <typename _Tp, typename _TVT = _VectorTraits<_Tp>>
-      inline _GLIBCXX_CONST static typename _TVT::type
+      constexpr inline _GLIBCXX_CONST static typename _TVT::type
       _S_bit_shift_left(_Tp __xx, typename _TVT::type __y)
       {
 	using _V = typename _TVT::type;
@@ -1800,7 +1800,7 @@  _mm512_cvtepi16_epi8(
     // _S_bit_shift_right {{{
 #ifndef _GLIBCXX_SIMD_NO_SHIFT_OPT
     template <typename _Tp, typename _TVT = _VectorTraits<_Tp>>
-      inline _GLIBCXX_CONST static typename _TVT::type
+      constexpr inline _GLIBCXX_CONST static typename _TVT::type
       _S_bit_shift_right(_Tp __xx, int __y)
       {
 	using _V = typename _TVT::type;
@@ -1850,7 +1850,7 @@  _S_bit_shift_right(_Tp __xx, int __y)
       }
 
     template <typename _Tp, typename _TVT = _VectorTraits<_Tp>>
-      inline _GLIBCXX_CONST static typename _TVT::type
+      constexpr inline _GLIBCXX_CONST static typename _TVT::type
       _S_bit_shift_right(_Tp __xx, typename _TVT::type __y)
       {
 	using _V = typename _TVT::type;