[PATCH v2 0/5] libstdc++: Implement std::layout_left_padded.
Tomasz Kaminski
tkaminsk@redhat.com
Tue Sep 23 06:39:12 GMT 2025
On Mon, Sep 22, 2025 at 7:40 AM Luc Grosheintz <luc.grosheintz@gmail.com>
wrote:
>
>
> On 9/11/25 3:58 PM, Luc Grosheintz wrote:
> >
> >
> > On 9/11/25 14:41, Tomasz Kaminski wrote:
> >> On Thu, Sep 11, 2025 at 1:50 PM Luc Grosheintz <
> luc.grosheintz@gmail.com>
> >> wrote:
> >>
> >>> Changes since v1:
> >>>
> >>> - Use cmp_* when comparing two integers of differnt types.
> >>> - Remove the FTM submdspan and replace it with an unofficial
> >>> purely internal FTM called padded_layouts.
> >>> - Make __get_static_stride consteval.
> >>> - Make __is_*_padded_layout only available inside
> >>> __glibcxx_padded_layout regions.
> >>> - Use size_t for __least_multiple_at_least.
> >>> - Implement checks (mandate and prerequisite) for representable
> >>> padded
> >>> static stride.
> >>> - Implement checks for representable padded "size", i.e. the product
> >>> of padded extents. This product might be larger than the
> >>> required_span_size, but the standard requires the product to be
> >>> representable (not just required_span_size).
> >>> - New overload for __static_extents(__begin, __end).
> >>> - Remove the double checked prerequisite.
> >>> - Skip some calculations for static first stride (2x).
> >>> - Replace array<..., ...> with _Stride.
> >>> - s/_S_stride_type/_Stride
> >>> - Test additional cases for default ctor.
> >>> - Rename ConversionRule::Conventional to Regular.
> >>> - Remove empty file testsuite/mdspan/layouts/debug/padded_neg.cc.
> >>> - Ensure all tests are run.
> >>> - Test remaining prerequisite in mapping(layout_stride).
> >>>
> >>> I also noticed that some of the changes can be split into separate
> >>> commits.
> >>>
> >> Hi,
> >> The first four patches LGTM, however I will put them in one patch,
> >> that just least all made changes, they are really small.
> >> I do not think I will be able to review layout_left_padded today fully,
> >> and I will continue review in two weeks. I will post a partial notes
> >> marking them as so.
> >
> > Thank you for the reviews. Sorry for reacting slowly, but it might be
> > easiest to postpone the review. I'll likely be able to make progress
> > on layout_right_padded (now that many things are cleared up).
> >
> > The right-padded layout will likely require that I generalize certain
> > concepts, e.g. a "padded stride" instead of a first/last stride.
> >
>
> Earlier last week, I implemented the layout_right_padded. It's
> essentially identical if one replaces
> s/0/rank-1/
> s/1/rank-2/
>
> (more or less). One can avoid duplicating the entire logic
> for checking mandates/prerequisites by creating a object
> "storage" that contains the _M_stride and _M_extents.
>
We could then also provide enough interface for this storage object,
so it could be used with indexing operators, if we make them templated
on just typename _Extents. I think just having an extent function that
would return
adjusted for stride will be sufficient.
I think we could do something similar with representable size and empty,
for storage object:
__static_extents -> drop the leftmost/rightmost extent
__dynamic_extents -> drop the leftmost/rightmost extent
__padded_extents -> return:
* integral_constant<size_t, 1> for non-padded layouts, this way we can
always
add it, but it will not affect computation
* integral_constant<size_t, X> for padded with static strides
* size_t for padded with dynamic stride
Or __padded_extents could return:
extents<IndexType> const& for extents, just have constexpr inline global
variable that we would return address off,
extents<IndexType, X> const& for padded storage.
>
> The padded tests all get indented, because one needs to pass
> in the layout template; and some other changes to make it
> work for both layouts.
>
> Since a lot of code changes/moves around, how would you like
> to review it:
>
> 1. A v3 with just the fixes for layout_left_padded. Then
> a refactor commit. Followed by layout_right_padded?
>
> 2. Squash the refactoring into the v3 of layout_left_padded.
> Then add layout_right_padded?
>
If the suggestion above would allow us to merge a lot of the now separate
code,
I would prefer squashed refactoring of v3 of layout_left padded.
>
> >>
> >>
> >>>
> >>> Luc Grosheintz (5):
> >>> libstdc++: Refactor layout mapping tests to use a concept.
> >>> libstdc++: Fix bug in layout mapping tests.
> >>> libstdc++: Prepare mapping layout tests for left padded.
> >>> libstdc++: Refactor __mdspan::__static_quotient.
> >>> libstdc++: Implement std::layout_left_padded.
> >>>
> >>> libstdc++-v3/include/bits/version.def | 10 +
> >>> libstdc++-v3/include/bits/version.h | 9 +
> >>> libstdc++-v3/include/std/mdspan | 541 +++++++++++++++-
> >>> libstdc++-v3/src/c++23/std.cc.in | 8 +-
> >>> .../mdspan/layouts/class_mandate_neg.cc | 1 +
> >>> .../23_containers/mdspan/layouts/ctors.cc | 61 +-
> >>> .../mdspan/layouts/debug/padded_neg.cc | 22 +
> >>> .../23_containers/mdspan/layouts/empty.cc | 12 +-
> >>> .../23_containers/mdspan/layouts/mapping.cc | 204 ++++--
> >>> .../23_containers/mdspan/layouts/padded.cc | 611
> ++++++++++++++++++
> >>> .../mdspan/layouts/padded_neg.cc | 280 ++++++++
> >>> 11 files changed, 1692 insertions(+), 67 deletions(-)
> >>> create mode 100644
> >>> libstdc++-v3/testsuite/23_containers/mdspan/layouts/debug/padded_neg.cc
> >>> create mode 100644
> >>> libstdc++-v3/testsuite/23_containers/mdspan/layouts/padded.cc
> >>> create mode 100644
> >>> libstdc++-v3/testsuite/23_containers/mdspan/layouts/padded_neg.cc
> >>>
> >>> --
> >>> 2.50.1
> >>>
> >>>
> >>
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250923/dd48a174/attachment.htm>
More information about the Libstdc++
mailing list