]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Improve nearly fully dynamic extents in mdspan.
authorLuc Grosheintz <luc.grosheintz@gmail.com>
Sun, 3 Aug 2025 20:57:27 +0000 (22:57 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Thu, 21 Aug 2025 08:20:57 +0000 (10:20 +0200)
One previous commit optimized fully dynamic extents; and another
refactored __size such that __fwd_prod is valid for __r = 0, ..., rank
(exclusive).

Therefore, by noticing that __rev_prod (and __fwd_prod) never accesses
the first (or last) extent, one can avoid pre-computing partial products
of static extents in those cases, if all other extents are dynamic.

We check that the size of the reference object file decreases further
and the .rodata sections for

  __fwd_prod<dyn, ..., dyn, 11>
  __rev_prod<3, dyn, ..., dyn>

are absent.

libstdc++-v3/ChangeLog:

* include/std/mdspan (__fwd_prods): Relax condition for fully-dynamic
extents to cover (dyn, ..., dyn, X).
(__rev_partial_prods): Analogous for (X, dyn, ..., dyn).

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
libstdc++-v3/include/std/mdspan

index d98b91d441927f054424cd179e342e9e6b900f78..a9168af4accec8ab3193f726b1eb7e7fa2c24a1d 100644 (file)
@@ -469,7 +469,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          return 1;
        else if constexpr (__rank == 2)
          return __r == 0 ? 1 : __exts.extent(0);
-       else if constexpr (__all_dynamic(__sta_exts))
+       else if constexpr (__all_dynamic(std::span(__sta_exts).first(__rank-1)))
          return __extents_prod(__exts, 1, 0, __r);
        else
          {
@@ -489,7 +489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          return 1;
        else if constexpr (__rank == 2)
          return __r == 0 ? __exts.extent(1) : 1;
-       else if constexpr (__all_dynamic(__sta_exts))
+       else if constexpr (__all_dynamic(std::span(__sta_exts).last(__rank-1)))
          return __extents_prod(__exts, 1, __r + 1, __rank);
        else
          {