[PATCH v2 5/8] libstdc++: Improve nearly fully dynamic extents in mdspan.
Tomasz Kaminski
tkaminsk@redhat.com
Tue Aug 5 07:41:55 GMT 2025
On Sun, Aug 3, 2025 at 11:08 PM Luc Grosheintz <luc.grosheintz@gmail.com>
wrote:
> 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 (__all_dynamic): Add arguments __begin
> and __end.
> (__fwd_prods): Relax condition for fully-dynamic extents to
> cover (dyn, ..., dyn, X).
> (__rev_partial_prods): Analogous for (X, dyn, ..., dyn).
>
> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
> ---
> libstdc++-v3/include/std/mdspan | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/mdspan
> b/libstdc++-v3/include/std/mdspan
> index 49e3969134b..ccf1028466f 100644
> --- a/libstdc++-v3/include/std/mdspan
> +++ b/libstdc++-v3/include/std/mdspan
> @@ -49,12 +49,13 @@ namespace std _GLIBCXX_VISIBILITY(default)
> _GLIBCXX_BEGIN_NAMESPACE_VERSION
> namespace __mdspan
> {
> +
> template<array _Extents>
> consteval bool
> - __all_dynamic()
> + __all_dynamic(size_t __begin = 0, size_t __end = _Extents.size())
>
I removed this change.
> {
> - for(auto __ext : _Extents)
> - if (__ext != dynamic_extent)
> + for(size_t __i = __begin; __i < __end; ++__i)
> + if (_Extents[__i] != dynamic_extent)
> return false;
> return true;
> }
> @@ -469,7 +470,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<__sta_exts>(0, __rank-1))
>
With my previous change to pass span to __all_dynamic, replacing this wiht:
else if constexpr (__all_dynamic(std::span(__sta_exts).first(__rank-1)))
> return __extents_prod(__exts, 1, 0, __r);
> else
> {
> @@ -488,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<__sta_exts>(1, __rank))
>
else if constexpr
(__all_dynamic(std::span(__sta_exts).last(__rank-1)))
> return __extents_prod(__exts, 1, __r + 1, __rank);
> else
> {
> --
> 2.50.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250805/1d51fca6/attachment-0001.htm>
More information about the Libstdc++
mailing list