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

ff: refactor find_naf and add unit tests #896

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tcoratger
Copy link
Contributor

Description

closes: #XXXX


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the GitHub PR explorer

@tcoratger tcoratger requested review from a team as code owners November 28, 2024 08:03
@tcoratger tcoratger requested review from z-tech, weikengchen and tyshko-rostyslav and removed request for a team November 28, 2024 08:03
Comment on lines 158 to 178
while num.iter().any(|&x| x != 0) {
let z = if num[0] & 1 == 1 {
let z = 2 - (num[0] % 4) as i8;
// Choose the appropriate operation: subtract (sbb) if z >= 0, otherwise add (adc).
let op = if z >= 0 { sbb } else { adc };
num.iter_mut()
.zip(ark_std::iter::once(&(z.abs() as u64)).chain(ark_std::iter::repeat(&0)))
.fold(0, |carry, (a, b)| op(a, *b, carry));
z
} else {
z = 0;
}
0
};

res.push(z);
div2(&mut num);

// Perform an in-place division of `num` by 2, using bit-shifting.
num.iter_mut().rev().fold(0, |carry, x| {
let next_carry = *x << 63;
*x = (*x >> 1) | carry;
next_carry
});
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the PR! I think I like the old code structure slightly better since it separates out the arithmetic logic from the algorithm logic. I do like the new implementations of the arithmetic better, so maybe we can go back to the old code structure but with the new arithmetic impls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, I've also added a more complete documentation inside the function for the reader to understand the various operations that are performed.

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