C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Integer overflow arithmetic

From: Jan Schultke <janschultke_at_[hidden]>
Date: Sat, 17 Feb 2024 17:16:46 +0100
Even though you can implement it yourself in terms of div_wide, I'd
still argue that there should be a separate function that does it for
you. GCC and clang would likely implement that in terms of an __int128
division, which would be better for debug builds and constant
evaluations than having the user create their own wrapper function
which calls div_wide multiple times.

It's also not 100% obvious that you can use long division to implement
it in terms of div_wide. It may be obvious to the implementer, but not
to the user.

Note that for GCC and clang, both the signed 128-to-64-bit division
calls __modti3 and the unsigned counterpart calls __umodti3. It may be
difficult to achieve that kind of codegen when the optimizer has to
assemble multiple div_wide calls that collectively form a 128-bit
remainder operation.

Received on 2024-02-17 16:16:59