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 add to avoid overflow check #520

Merged
merged 2 commits into from
Aug 31, 2023
Merged

Optimize add to avoid overflow check #520

merged 2 commits into from
Aug 31, 2023

Conversation

schouhy
Copy link
Contributor

@schouhy schouhy commented Aug 2, 2023

Optimize add to avoid overflow check

Type of change

  • Optimization

Checklist

  • Linked to Github Issue
  • Unit tests added
  • This change requires new documentation.
    • Documentation has been added/updated.
  • This change is an Optimization
    • Benchmarks added/run

@schouhy schouhy requested review from ajgara and a team as code owners August 2, 2023 19:32
@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2023

Codecov Report

Merging #520 (b04d4c9) into main (d95c83c) will decrease coverage by 0.04%.
The diff coverage is 80.00%.

@@            Coverage Diff             @@
##             main     #520      +/-   ##
==========================================
- Coverage   94.51%   94.48%   -0.04%     
==========================================
  Files          62       62              
  Lines        8949     8951       +2     
==========================================
- Hits         8458     8457       -1     
- Misses        491      494       +3     
Files Changed Coverage Δ
...src/field/fields/montgomery_backed_prime_fields.rs 93.16% <80.00%> (-0.39%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Oppen
Copy link
Member

Oppen commented Aug 2, 2023

Two suggestions:

  1. Make modulus_has_one_spare_bit #[inline(always)];
  2. Evaluate to a const before the if guard, so we can be sure it's always evaluated at compile time.
    Point 2 is because a const fn is not intrinsically always evaluated as a constant, but it signals that it can be used to create constants. By storing the result into a const you guarantee that, so then the correct branch is known at compile-time to always be taken and thus the check and the other branch get removed by the compiler.

@MauroToscano MauroToscano added this pull request to the merge queue Aug 31, 2023
Merged via the queue into main with commit 4aa2613 Aug 31, 2023
6 of 7 checks passed
@MauroToscano MauroToscano deleted the optimize-add branch August 31, 2023 15:11
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.

5 participants