diff options
author | Dean Rasheed <dean.a.rasheed@gmail.com> | 2025-08-07 09:20:02 +0100 |
---|---|---|
committer | Dean Rasheed <dean.a.rasheed@gmail.com> | 2025-08-07 09:20:02 +0100 |
commit | d9bb8ef093d62763cfd19d37e6bb8182998a3f88 (patch) | |
tree | 0933d54d3165fe573e142cb14965998855b79e5d /src/backend/utils/adt/arrayutils.c | |
parent | 572c0f1b0e2a9ed61816239f59d568217079bb8c (diff) |
Optimise non-native 128-bit addition in int128.h.
On platforms without native 128-bit integer support, simplify the test
for carry in int128_add_uint64() by noting that the low-part addition
is unsigned integer arithmetic, which is just modular arithmetic.
Therefore the test for carry can simply be written as "new value < old
value" (i.e., a test for modular wrap-around). This can then be made
branchless so that on modern compilers it produces the same machine
instructions as native 128-bit addition, making it significantly
simpler and faster.
Similarly, the test for carry in int128_add_int64() can be written in
much the same way, but with an extra term to compensate for the sign
of the value being added. Again, on modern compilers this leads to
branchless code, often identical to the native 128-bit integer
addition machine code.
Author: Dean Rasheed <dean.a.rasheed@gmail.com>
Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Discussion: https://postgr.es/m/CAEZATCWgBMc9ZwKMYqQpaQz2X6gaamYRB+RnMsUNcdMcL2Mj_w@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/arrayutils.c')
0 files changed, 0 insertions, 0 deletions