Skip to content

Commit f7a016e

Browse files
committed
Iterate in forward direction to help with cache
1 parent bb06987 commit f7a016e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/uint/shl.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ impl<const LIMBS: usize> Uint<LIMBS> {
4343
let shift_num = (shift / Limb::BITS) as usize;
4444
let rem = shift % Limb::BITS;
4545

46-
let mut i = LIMBS;
47-
while i > shift_num {
48-
i -= 1;
46+
let mut i = shift_num;
47+
while i < LIMBS {
4948
limbs[i] = self.limbs[i - shift_num];
49+
i += 1;
5050
}
5151

5252
if rem == 0 {
@@ -55,6 +55,7 @@ impl<const LIMBS: usize> Uint<LIMBS> {
5555

5656
let mut carry = Limb::ZERO;
5757

58+
let mut i = shift_num;
5859
while i < LIMBS {
5960
let shifted = limbs[i].shl(rem);
6061
let new_carry = limbs[i].shr(Limb::BITS - rem);
@@ -104,15 +105,15 @@ impl<const LIMBS: usize> Uint<LIMBS> {
104105
let rshift = nz.if_true_u32(Limb::BITS - shift);
105106
let carry = nz.if_true_word(self.limbs[LIMBS - 1].0.wrapping_shr(Word::BITS - shift));
106107

107-
let mut i = LIMBS - 1;
108-
while i > 0 {
108+
limbs[0] = Limb(self.limbs[0].0 << lshift);
109+
let mut i = 1;
110+
while i < LIMBS {
109111
let mut limb = self.limbs[i].0 << lshift;
110112
let hi = self.limbs[i - 1].0 >> rshift;
111113
limb |= nz.if_true_word(hi);
112114
limbs[i] = Limb(limb);
113-
i -= 1
115+
i += 1
114116
}
115-
limbs[0] = Limb(self.limbs[0].0 << lshift);
116117

117118
(Uint::<LIMBS>::new(limbs), Limb(carry))
118119
}

0 commit comments

Comments
 (0)