[PATCH] libstdc++: Implement non-simd part of P3642R7 - Carry-less product: std::clmul
Jakub Jelinek
jakub@redhat.com
Tue Nov 3 18:39:36 GMT 2026
On Tue, Nov 03, 2026 at 06:23:19PM +0000, Jonathan Wakely wrote:
> On Tue, 3 Nov 2026 at 15:38, Jakub Jelinek <jakub@redhat.com> wrote:
> > + template<typename _Tp>
> > + class wide_result {
> > + public:
> > + constexpr wide_result(_Tp __high, _Tp __low) noexcept
> > + : _M_high(__high), _M_low(__low) {}
> > +
> > + constexpr _Tp high() const noexcept { return _M_high; }
> > + constexpr _Tp low() const noexcept { return _M_low; }
> > +
> > + friend constexpr bool operator==(const wide_result&,
> > + const wide_result&) = default;
> > + friend constexpr strong_ordering operator<=>(const wide_result&,
> > + const wide_result&)
> > + noexcept = default;
> > + private:
> > + _Tp _M_high, _M_low;
>
> LWG wanted this to be a class with private members rather than an
> aggregate with public members so that the high and low parts could be
> ordered optimally according to the target endianness, e.g. so that
> wide_result<uint64_t> would have the same layout as unsigned int128.
I don't see any advantages in doing that.
Sure, having the private bits actually be the twice as wide unsigned
type is an implementation option, but one then needs to specialize
those just for types that do have such a twice as wide type at all.
Also, given the way I've introduced __builtin_clmulg which returns
the low part and sets what optional third argument points at to the high
part, using that strategy actually would be pessimization, especially for
say unsigned _BitInt(31), having two unsigned _BitInt(31) parts is
then better over having to combine it into unsigned _BitInt(62).
And, without _BitInt there is no 2x wider type for unsigned __int128,
on 32-bit targets no 2x wider type for unsigned long long, on _BitInt
targets no 2x wider type for unsigned _BitInt(__BITINT_MAXWIDTH__ - 1)
etc.
I think it is fine if the standard allows the implementations to choose
what they want though.
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p3642r7.html#aggregate-type-std::wide_result
>
> Do we want to take advantage of that?
>
> I think we need static_assert(__is_unsigned_integer<_Tp>::value);
Ah, I've missed
"A specialization wide_result<T> is ill-formed unless T is an unsigned integer
type"
Should that be
static_assert(__is_unsigned_integer<_Tp>::value);
or instead
template<__unsigned_integer _Tp>
class wide_result ?
Jakub
More information about the Libstdc++
mailing list