-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add bit accessor methods #122
Conversation
Signed-off-by: Andrew Whitehead <[email protected]>
Signed-off-by: Andrew Whitehead <[email protected]>
893a472
to
3b74461
Compare
I've updated this PR to only add |
@@ -25,7 +25,7 @@ impl<const LIMBS: usize> UInt<LIMBS> { | |||
// Sometimes an increase is too far, especially with large | |||
// powers, and then takes a long time to walk back. The upper | |||
// bound is based on bit size, so saturate on that. | |||
let res = Limb::ct_cmp(Limb(xn.bits() as Word), Limb(max_bits as Word)) - 1; | |||
let res = Limb::ct_cmp(Limb(xn.bits_vartime() as Word), Limb(max_bits as Word)) - 1; |
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.
This use of bits_vartime
seems a little concerning after the renaming? @tarcieri
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.
cc @mikelodder7
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.
Seems okay for now. Not a clear direction yet going forward
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.
It seems like this method should probably use a prospective constant-time implementation of bits
?
I can open a tracking issue
Signed-off-by: Andrew Whitehead <[email protected]>
fb04760
to
b78a6fc
Compare
Looks good now, thanks! |
This adds
UInt::bit_vartime(index)
for accessing the value of the bit at a given index. It's trivial to cast the result to u8 or bool so I leave that up to the caller, to avoid casting the value twice.For consistency and accuracy,
bits
is renamed tobits_vartime
.