Skip to content

Commit

Permalink
Merge pull request #316 from DaniPopes/perf-array-intoiter
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored Sep 30, 2023
2 parents d070e8b + 480da03 commit 567f786
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
}
let mut carry = 0_u128;
#[allow(clippy::cast_possible_truncation)] // Intentional
for (lhs, rhs) in self.limbs.iter_mut().zip(rhs.limbs) {
for (lhs, &rhs) in self.limbs.iter_mut().zip(rhs.as_limbs()) {
carry += u128::from(*lhs) + u128::from(rhs);
*lhs = carry as u64;
carry >>= 64;
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
let mut carry = 0_i128;
#[allow(clippy::cast_possible_truncation)] // Intentional
#[allow(clippy::cast_sign_loss)] // Intentional
for (lhs, rhs) in self.limbs.iter_mut().zip(rhs.limbs) {
for (lhs, &rhs) in self.limbs.iter_mut().zip(rhs.as_limbs()) {
carry += i128::from(*lhs) - i128::from(rhs);
*lhs = carry as u64;
carry >>= 64; // Sign extending shift
Expand Down
2 changes: 1 addition & 1 deletion src/base_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
}

// Add digit to result
let overflow = addmul_nx1(&mut result.limbs, &power.limbs, digit);
let overflow = addmul_nx1(&mut result.limbs, power.as_limbs(), digit);
if overflow != 0 || result.limbs[LIMBS - 1] > Self::MASK {
return Err(BaseConvertError::Overflow);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ macro_rules! impl_bit_op {
for Uint<BITS, LIMBS>
{
fn $fn_assign(&mut self, rhs: &Uint<BITS, LIMBS>) {
for (limb, rhs) in self.limbs.iter_mut().zip(rhs.limbs) {
for (limb, &rhs) in self.limbs.iter_mut().zip(rhs.as_limbs()) {
u64::$fn_assign(limb, rhs);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/modular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
// Alternatively we could use `alloca`, but that is blocked on
// See <https://github.com/rust-lang/rust/issues/48055>
let mut product = vec![0; crate::nlimbs(2 * BITS)];
let overflow = algorithms::addmul(&mut product, &self.limbs, &rhs.limbs);
let overflow = algorithms::addmul(&mut product, self.as_limbs(), rhs.as_limbs());
debug_assert!(!overflow);

// Compute modulus using `div_rem`.
Expand Down Expand Up @@ -152,10 +152,10 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
assert_eq!(inv.wrapping_mul(modulus.limbs[0]), u64::MAX);
let mut result = Self::ZERO;
algorithms::mul_redc(
&self.limbs,
&other.limbs,
self.as_limbs(),
other.as_limbs(),
&mut result.limbs,
&modulus.limbs,
modulus.as_limbs(),
inv,
);
debug_assert!(result < modulus);
Expand Down
2 changes: 1 addition & 1 deletion src/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
assert_eq!(BITS_RES, BITS + BITS_RHS);
assert_eq!(LIMBS_RES, nlimbs(BITS_RES));
let mut result = Uint::<BITS_RES, LIMBS_RES>::ZERO;
algorithms::addmul(&mut result.limbs, &self.limbs, &rhs.limbs);
algorithms::addmul(&mut result.limbs, self.as_limbs(), rhs.as_limbs());
if LIMBS_RES > 0 {
debug_assert!(result.limbs[LIMBS_RES - 1] <= Uint::<BITS_RES, LIMBS_RES>::MASK);
}
Expand Down

0 comments on commit 567f786

Please sign in to comment.