Skip to content

Commit

Permalink
Some efficiency improvements in div_rem (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Mar 1, 2024
1 parent 0cb5cd0 commit 1c9da5b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/uint/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl<const LIMBS: usize> Uint<LIMBS> {
let mut i = Self::BITS;
let mut done = ConstChoice::FALSE;
loop {
let (mut r, borrow) = rem.sbb(&c, Limb::ZERO);
rem = Self::select(&r, &rem, ConstChoice::from_word_mask(borrow.0).or(done));
r = quo.bitor(&Self::ONE);
quo = Self::select(&r, &quo, ConstChoice::from_word_mask(borrow.0).or(done));
let (r, borrow) = rem.sbb(&c, Limb::ZERO);
let choice = ConstChoice::from_word_mask(borrow.0).or(done);
rem = Self::select(&r, &rem, choice);
quo = Self::select(&quo.bitor(&Self::ONE), &quo, choice);
if i == 0 {
break;
}
Expand Down Expand Up @@ -79,10 +79,10 @@ impl<const LIMBS: usize> Uint<LIMBS> {
let mut c = rhs.0.wrapping_shl_vartime(bd);

loop {
let (mut r, borrow) = rem.sbb(&c, Limb::ZERO);
rem = Self::select(&r, &rem, ConstChoice::from_word_mask(borrow.0));
r = quo.bitor(&Self::ONE);
quo = Self::select(&r, &quo, ConstChoice::from_word_mask(borrow.0));
let (r, borrow) = rem.sbb(&c, Limb::ZERO);
let choice = ConstChoice::from_word_mask(borrow.0);
rem = Self::select(&r, &rem, choice);
quo = Self::select(&quo.bitor(&Self::ONE), &quo, choice);
if bd == 0 {
break;
}
Expand Down

0 comments on commit 1c9da5b

Please sign in to comment.