Date: Wed, 14 Jan 2026 10:46:12 +0100
> On 14 Jan 2026, at 00:26, Thiago Macieira <thiago_at_[hidden]> wrote:
>
> On Tuesday, 13 January 2026 13:53:58 Pacific Standard Time Hans Åberg wrote:
>>> In fact, the answer you gave has absolutely nothing to do with Marcin's
>>> statement. Marcin said that if the compiler implements support for 256-bit
>>> integers, then it won't need to expand and instantiate templates, which in
>>> -O0 mode means there are no non-inlined inline functions.
>>
>> But that is the very point: the templates recurse down half-words until
>> there is an implementation. So in your example, it will just call the
>> 256-bit specialized function that is implemented.
>
> And again you're missing the point: why can the template do this but the
> compiler-provided implementation can't?
If you have 256-bit integers, but not the 2-by-1 word division, div_wide in the proposal below, then templates can supply that by 128-bit words. Similarly, if you do not have full 2-word multiplication, mul_wide in the proposal below, then the templates can supply them.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3161r4.html#functions.div_wide
Then, if you want to implement modular integers for a type fitting into 256 bits, then one way to do that is by first using a 2-word result multiplication (mul_wide), and then use a 2-by-1 word division (div_wide) dividing with the modulus to compute the remainder.
>
> On Tuesday, 13 January 2026 13:53:58 Pacific Standard Time Hans Åberg wrote:
>>> In fact, the answer you gave has absolutely nothing to do with Marcin's
>>> statement. Marcin said that if the compiler implements support for 256-bit
>>> integers, then it won't need to expand and instantiate templates, which in
>>> -O0 mode means there are no non-inlined inline functions.
>>
>> But that is the very point: the templates recurse down half-words until
>> there is an implementation. So in your example, it will just call the
>> 256-bit specialized function that is implemented.
>
> And again you're missing the point: why can the template do this but the
> compiler-provided implementation can't?
If you have 256-bit integers, but not the 2-by-1 word division, div_wide in the proposal below, then templates can supply that by 128-bit words. Similarly, if you do not have full 2-word multiplication, mul_wide in the proposal below, then the templates can supply them.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3161r4.html#functions.div_wide
Then, if you want to implement modular integers for a type fitting into 256 bits, then one way to do that is by first using a 2-word result multiplication (mul_wide), and then use a 2-by-1 word division (div_wide) dividing with the modulus to compute the remainder.
Received on 2026-01-14 09:46:28
