Date: Wed, 14 Jan 2026 15:49:36 +0100
> On 14 Jan 2026, at 11:29, Lénárd Szolnoki via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On 14 January 2026 10:04:23 GMT, "Hans Åberg via Std-Proposals" <std-proposals_at_[hidden]> wrote:
>>
>>> On 14 Jan 2026, at 10:43, Jan Schultke <janschultke_at_[hidden]> wrote:
>>>
>>> Yes, that is how I discovered it was much faster. It is a template, essentially an implementation of div_wide in this proposal:
>>> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3161r4.html#functions.div_wide
>>>
>>> LLVM implements it with a loop. I made recursive templates, removing the loop and all multiplications except one per halfword.
>>>
>>> Tiago Freire has a copy which might be used for a reference implementation, in case you would like to add requirements that compilers have it, not merely being optional.
>>>
>>> If you have an optimization opportunity that LLVM does not take, why don't you make an LLVM PR or bug report instead of a C++ proposal?
>>
>> The optimizations are not a part of a C++ proposal, clearly, since the standard does not make such statements. There is usually a requirement of at least one fairly efficient implementation, leaving it open for improvements, and that is what I indicated.
>>
>> The LLVM code is in C, so templates won't help there. They seem happy with what they have.
>
> LLVM is written C++, not that it matters. It could be written in Python and still emit efficient assembly.
It is this one:
https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/udivmodti4.c
>
> On 14 January 2026 10:04:23 GMT, "Hans Åberg via Std-Proposals" <std-proposals_at_[hidden]> wrote:
>>
>>> On 14 Jan 2026, at 10:43, Jan Schultke <janschultke_at_[hidden]> wrote:
>>>
>>> Yes, that is how I discovered it was much faster. It is a template, essentially an implementation of div_wide in this proposal:
>>> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3161r4.html#functions.div_wide
>>>
>>> LLVM implements it with a loop. I made recursive templates, removing the loop and all multiplications except one per halfword.
>>>
>>> Tiago Freire has a copy which might be used for a reference implementation, in case you would like to add requirements that compilers have it, not merely being optional.
>>>
>>> If you have an optimization opportunity that LLVM does not take, why don't you make an LLVM PR or bug report instead of a C++ proposal?
>>
>> The optimizations are not a part of a C++ proposal, clearly, since the standard does not make such statements. There is usually a requirement of at least one fairly efficient implementation, leaving it open for improvements, and that is what I indicated.
>>
>> The LLVM code is in C, so templates won't help there. They seem happy with what they have.
>
> LLVM is written C++, not that it matters. It could be written in Python and still emit efficient assembly.
It is this one:
https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/udivmodti4.c
Received on 2026-01-14 14:49:58
