chfast / intx

Extended precision integer C++ library
Apache License 2.0
122 stars 34 forks source link

addc/subc optimizations #253

Closed chfast closed 2 years ago

chfast commented 2 years ago

Use compiler builtins to implement addc and subc primitives. This mostly benefits GCC (clang is able to match respective patterns without builtins).

codecov-commenter commented 2 years ago

Codecov Report

Merging #253 (c348241) into master (b05e8a1) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #253   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         1911      1958   +47     
=========================================
+ Hits          1911      1958   +47     
Flag Coverage Δ
32bit 100.00% <100.00%> (ø)
gcc 99.48% <92.42%> (-0.52%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
test/unittests/test_builtins.cpp 100.00% <ø> (ø)
test/unittests/test_uint256.cpp 100.00% <ø> (ø)
include/intx/intx.hpp 100.00% <100.00%> (ø)
test/experimental/addmod.hpp 100.00% <100.00%> (ø)
yperbasis commented 2 years ago

According to Wiki, there are 2 different conventions for subtraction: carry & borrow. x86 uses borrow & ARM uses carry. I'm not sure which convention __builtin_subcll uses. Is there good documentation for it anywhere?

chfast commented 2 years ago

According to Wiki, there are 2 different conventions for subtraction: carry & borrow. x86 uses borrow & ARM uses carry. I'm not sure which convention __builtin_subcll uses. Is there good documentation for it anywhere?

Oh, interesting. This is "sub with borrow" then although the name may suggest otherwise. And looks this is not very well optimized on ARM maybe because of the reversed carry bit.

https://godbolt.org/z/sPsahE4f9