On Wed, 4 Nov 2026 at 07:44, Jonathan Wakely <[email protected]> wrote:
>
>
>
> On Tue, 3 Nov 2026, 18:39 Jakub Jelinek, <[email protected]> wrote:
>>
>> On Tue, Nov 03, 2026 at 06:23:19PM +0000, Jonathan Wakely wrote:
>> > On Tue, 3 Nov 2026 at 15:38, Jakub Jelinek <[email protected]> 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.
>
>
> I wasn't thinking that we'd actually use a data member of the wider type, but 
> because wide_result is trivially copyable you could memcpy or bit_cast 
> wide_result<uint32_t> into a uint64_t. The value of the uin64_t world only be 
> correct if the high and low parts are in the right order, the value of the 
> uint64_t would be wrong.

Sorry for the garbled sentence, typed on my phone before I was properly awake.

I meant to say the value of the uin64_t would only be correct if the
high and low parts are in the right order.



>
>
>
>> 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
>>

Reply via email to