public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
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++: Add missing constexpr to simd
Date: Mon, 22 May 2023 17:25:15 +0100	[thread overview]
Message-ID: <CACb0b4=jKUKnUbr8iMVRTQ1CkYtWj7DPR03Z3rk3y_CJSXcx2w@mail.gmail.com> (raw)
In-Reply-To: <116291317.nniJfEyVGO@minbar>

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

On Mon, 22 May 2023 at 16:36, Matthias Kretz via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:

> OK for trunk and backporting?
>
> regtested on x86_64-linux and aarch64-linux
>
> The constexpr API is only available with -std=gnu++XX (and proposed for
> C++26). The proposal is to have the complete simd API usable in constant
> expressions.
>
> This patch resolves several issues with using simd in constant
> expressions.
>
> Issues why constant_evaluated branches are necessary:
>

I note that using if (not __builtin_constant_evaluated()) will fail if
compiled with -fno-operator-names, which is why we don't use 'not', 'and',
etc. elsewhere in libstdc++. I don't know if (or why) anybody uses that
option though, so I don't think you need to hange anything in stdx::simd.




> * subscripting vector builtins is not allowed in constant expressions
>

Is that just because nobody made it work (yet)?


* if the implementation needs/uses memcpy
> * if the implementation would otherwise call SIMD intrinsics/builtins
>


The indentation looks off here and in the _M_set member function following
it:

     operator[](size_t __i) const noexcept
     {
       if constexpr (_S_tuple_size == 1)
  return _M_subscript_read(__i);
       else
- {
 #ifdef _GLIBCXX_SIMD_USE_ALIASING_LOADS
-  return reinterpret_cast<const __may_alias<_Tp>*>(this)[__i];
-#else
-  if constexpr (__is_scalar_abi<_Abi0>())
-    {
-      const _Tp* ptr = &first;
-      return ptr[__i];
-    }
-  else
-    return __i < simd_size_v<_Tp, _Abi0>
-     ? _M_subscript_read(__i)
-     : second[__i - simd_size_v<_Tp, _Abi0>];
+ if (not __builtin_is_constant_evaluated())
+ return reinterpret_cast<const __may_alias<_Tp>*>(this)[__i];
+      else
 #endif
+ if constexpr (__is_scalar_abi<_Abi0>())
+ {
+  const _Tp* ptr = &first;
+  return ptr[__i];
  }
+      else
+ return __i < simd_size_v<_Tp, _Abi0> ? _M_subscript_read(__i)
+     : second[__i - simd_size_v<_Tp, _Abi0>];
     }


Are the copyright years on
testsuite/experimental/simd/pr109261_constexpr_simd.cc correct, or just
copy&paste?

  reply	other threads:[~2023-05-22 16:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 15:36 Matthias Kretz
2023-05-22 16:25 ` Jonathan Wakely [this message]
2023-05-22 20:27   ` Matthias Kretz
2023-05-22 20:51     ` Jonathan Wakely
2023-05-23  7:30       ` [committed] " Matthias Kretz
2023-05-22 20:56   ` Marc Glisse

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='CACb0b4=jKUKnUbr8iMVRTQ1CkYtWj7DPR03Z3rk3y_CJSXcx2w@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).