[PATCH] libstdc++: Improve simd::cat implementation strategy
Tomasz Kaminski
tkaminsk@redhat.com
Mon Feb 23 08:44:09 GMT 2026
On Mon, Feb 23, 2026 at 9:27 AM Matthias Kretz <MatthiasKretz@gmx.net>
wrote:
> Tomasz Kaminski [Monday, 23 February 2026 09:19:12 CET]:
> > > I do not think that this should be a separate overload and another if
> > > constexpr branch
> > > In the default implementation.
> >
> > That's what I initially did. It was horrible because I need to extract
> the
> > first element and the remaining pack from __rest... to do so. I could
> make
> > the function take 3 arguments + pack, but then I'd need an overload for
> the
> > 2-arg case, which would the duplicate the implementation.
> > What I could do is call a 3-arg + pack function/lambda from the
> constexpr-if
> > branch, but personally I find the overload simpler (and hopefully cheaper
> > to compile).
> > I think you are already using pack indexing in the implementation of
> > simd_mask, so I do not see a problem here: if (sizeof...(rest) > 0) and
> > _N0 > __Ns...[0].
>
> __Ns...[0] is already something that needs to go the next nested
> constexpr-if:
>
> if constexpr (__has_single_bit(unsigned(_N0)) && sizeof...(__rest) >= 2 &&
> _N0
> > _N1)
> {
> static constexpr array __tmp {_Ns...};
> constexpr auto& [_N2, ..._N3s] = __tmp;
> if constexpr (_N0 >= (_N1 + _N2))
> {
> const auto& [__c, ...__ds] = std::tie(__rest...);
> return __vec_concat_sized<_N0, _N1 + _N2, _N3s...>(
> __a, __vec_concat_sized<_N1, _N2>(__b, __c), __ds...);
> }
> }
> else { ... }
>
> And now I need to duplicate the else branch or remove the 'else'
> altogether
> and have the code in the else branch unconditionally "visible".
>
OK, that makes sense.
>
> --
> ──────────────────────────────────────────────────────────────────────────
> Dr. Matthias Kretz https://mattkretz.github.io
> GSI Helmholtz Center for Heavy Ion Research https://gsi.de
> std::simd
> ──────────────────────────────────────────────────────────────────────────
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20260223/a7d79366/attachment-0001.htm>
More information about the Libstdc++
mailing list