Skip to content

Optimize add and sub#115

Merged
chfast merged 7 commits intomasterfrom
add_optimization
Nov 18, 2019
Merged

Optimize add and sub#115
chfast merged 7 commits intomasterfrom
add_optimization

Conversation

@chfast
Copy link
Owner

@chfast chfast commented Nov 17, 2019

This rewrites the add_with_carry() for uint128 to a bit more efficient form (easier to consume by compilers).
Also subtraction is implemented in the analogous way to additions, instead of reusing addition.

GCC9:

Comparing test/intx-bench-master to test/intx-bench
Benchmark                           Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------
binary_op256<add>                +0.0007         +0.0007          7186          7191          7186          7191
binary_op256<inline_add>         -0.1695         -0.1695          2317          1924          2317          1924
binary_op256<sub>                -0.1624         -0.1625          8707          7293          8707          7292
binary_op256<inline_sub>         -0.4819         -0.4818          4041          2094          4041          2094
binary_op512<inline_add>         -0.2374         -0.2376          6874          5242          6874          5241
binary_op512<add>                -0.1954         -0.1954          9001          7242          9001          7242
binary_op512<inline_sub>         -0.4907         -0.4907         10430          5312         10430          5312
binary_op512<sub>                -0.1773         -0.1774         12260         10086         12259         10084

Clang9:

Comparing test/intx-bench-master to test/intx-bench
Benchmark                           Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------
binary_op256<add>                -0.0524         -0.0503          7908          7493          7890          7493
binary_op256<inline_add>         -0.0452         -0.0431          1973          1884          1969          1884
binary_op256<sub>                -0.1284         -0.1258          8552          7454          8527          7454
binary_op256<inline_sub>         -0.3132         -0.3114          2783          1911          2776          1911
binary_op512<inline_add>         -0.5603         -0.5585          9824          4319          9783          4319
binary_op512<add>                -0.0133         -0.0108         11674         11519         11644         11519
binary_op512<inline_sub>         -0.3870         -0.3880          7972          4886          7965          4874
binary_op512<sub>                -0.0672         -0.0692         11794         11001         11794         10978

@codecov-io
Copy link

codecov-io commented Nov 18, 2019

Codecov Report

Merging #115 into master will increase coverage by 2.09%.
The diff coverage is 46.66%.

@@            Coverage Diff            @@
##           master    #115      +/-   ##
=========================================
+ Coverage    64.3%   66.4%   +2.09%     
=========================================
  Files          11      11              
  Lines        1496    1518      +22     
  Branches      166     167       +1     
=========================================
+ Hits          962    1008      +46     
+ Misses        482     458      -24     
  Partials       52      52

@chfast chfast merged commit aacf8ee into master Nov 18, 2019
@chfast chfast deleted the add_optimization branch November 18, 2019 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants