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

arithmetic: Rewrite limbs_reduce_once. #2435

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

arithmetic: Rewrite limbs_reduce_once. #2435

wants to merge 1 commit into from

Conversation

briansmith
Copy link
Owner

Move the function to arithmetic from limb. This is step towards moving all arithmetic out of limb.

Change the signature so that the reduction is done separately instead of in-place. It was already being done separately in bigint and it costs very little, if anything, to do the same in the other caller in ec.

Optimize the implementation to take advantage of the fact that r and a do not alias each other. To do so, replace LIMBS_reduce_once with two separate helper functions, LIMBS_sub and LIMBS_cmov.

As part of doing this, ensure we're not passing any empty slices to the relevant C code.

git difftool HEAD^1:src/limb.rs src/arithmetic/limbs/reduce_once.rs

@briansmith briansmith self-assigned this Mar 3, 2025
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.58%. Comparing base (a5220ab) to head (290b36f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2435   +/-   ##
=======================================
  Coverage   96.57%   96.58%           
=======================================
  Files         178      181    +3     
  Lines       21607    21653   +46     
  Branches      533      533           
=======================================
+ Hits        20868    20913   +45     
  Misses        626      626           
- Partials      113      114    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Move the function to `arithmetic` from `limb`. This is step towards
moving all arithmetic out of `limb`.

Change the signature so that the reduction is done separately instead
of in-place. It was already being done separately in `bigint` and it
costs very little, if anything, to do the same in the other caller in
`ec`.

Optimize the implementation to take advantage of the fact that `r`
and `a` do not alias each other. To do so, replace
`LIMBS_reduce_once` with two separate helper functions, `LIMBS_sub`
and `LIMBS_cmov`.

As part of doing this, ensure we're not passing any empty slices to
the relevant C code.

```
git difftool HEAD^1:src/limb.rs src/arithmetic/limbs/reduce_once.rs
```
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.

1 participant