-
Notifications
You must be signed in to change notification settings - Fork 256
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
base: master
Are you sure you want to change the base?
Conversation
ff/src/biginteger/arithmetic.rs
Outdated
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 | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.
Pending
section inCHANGELOG.md
Files changed
in the GitHub PR explorer