Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize ADDMOD for elliptic curve context #206

Merged
merged 2 commits into from
Dec 17, 2021
Merged

Optimize ADDMOD for elliptic curve context #206

merged 2 commits into from
Dec 17, 2021

Conversation

chfast
Copy link
Owner

@chfast chfast commented Mar 15, 2021

No description provided.

@chfast chfast force-pushed the addmod branch 2 times, most recently from f0a743f to 3249565 Compare August 23, 2021 14:43
@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2021

Codecov Report

Merging #206 (2cb85bc) into master (f0dafad) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #206   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         9    +1     
  Lines         1792      1847   +55     
=========================================
+ Hits          1792      1847   +55     
Flag Coverage Δ
32bit 100.00% <100.00%> (ø)
gcc 100.00% <100.00%> (ø)

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

Impacted Files Coverage Δ
include/intx/intx.hpp 100.00% <100.00%> (ø)
test/experimental/addmod.hpp 100.00% <100.00%> (ø)
test/unittests/test_intx.cpp 100.00% <100.00%> (ø)

@chfast chfast force-pushed the addmod branch 3 times, most recently from 44755cf to 2670a82 Compare December 17, 2021 10:22
@chfast chfast changed the title Optimize ADDMOD Optimize ADDMOD for elliptic curve context Dec 17, 2021
@chfast chfast marked this pull request as ready for review December 17, 2021 10:23
In elliptic curve context the x and y arguments are already reduced
modulo mod. Here we can pick up similar condition and provide optimized
implementation for such case. This case is 2x faster with little
overhead for other cases.

Based on holiman/uint256#86.
// Fast path for mod >= 2^192, with x and y at most slightly bigger than mod.
// This is always the case when x and y are already reduced modulo mod.
// Based on https://github.com/holiman/uint256/pull/86.
if ((mod[3] != 0) && (x[3] <= mod[3]) && (y[3] <= mod[3]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this handle the mod[4] != 0 case? i.e. shouldn't it be (mod[4] | mod[3]) != 0?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no mod[4]. The mod[3] is the most significant word.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, phew :)

@chfast chfast merged commit 81b7bbd into master Dec 17, 2021
@chfast chfast deleted the addmod branch December 17, 2021 13:03
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.

3 participants