[PATCH] libstdc++: Implement non-simd part of P3642R7 - Carry-less product: std::clmul
Jakub Jelinek
jakub@redhat.com
Tue Nov 3 19:06:33 GMT 2026
On Tue, Nov 03, 2026 at 07:52:50PM +0100, Tomasz Kaminski wrote:
> 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.
> >
> The context here, is that the same layout was originally suggested to allow
> bitcasting/memcpy into a wider integer type. We didn't want to guarantee
> using a,
> and instead suggested adding a member function that would allow extraction
> of low and high combined in single type. I would imagine something like:
> template<typename W = implementation-defined>
> W wide() { };
> W should have a default argument only if a type at least twice as wide as T
> exists.
>
> I think this function could compile to fewer instructions for some
> combination of W and T,
> if we order the _M_high and _M_low members according to endianess of target,
> without combining them into a single member.
It depends on how the user is going to use it.
If it is two separate fields and that is how the builtin produces those,
then it is cheaper to construct it as two separate fields. If user uses it
as two separate fields (so checks .low() and .high() separately), then
paying the extra cost of combining the two parts into one is wasted.
If user uses the hypothetical wide() on it, then that would be likely
cheaper if it is just one private wider field, but then low() and high()
will be slower.
Anyway, given experimental C++29 support for a while, we can change it if
needed depending on what will be most useful to users.
Anyway, if there is a 2x wider type and user knows what it is, they can
always just use std::clmul<that_2xwider_type>.
> > Should that be
> > static_assert(__is_unsigned_integer<_Tp>::value);
> >
> static_assert.
Changed in my copy.
Jakub
More information about the Libstdc++
mailing list