Improve mac_digit bounds checking
By starting with `split_at_mut`, the hot multiplication loop runs with no bounds checking at all! The remaining carry loop has a slightly simpler check for when the remaining iterator runs dry.
This commit is contained in:
parent
bcd76c55e8
commit
05dc87c041
|
@ -227,16 +227,16 @@ fn mac_digit(acc: &mut [BigDigit], b: &[BigDigit], c: BigDigit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut carry = 0;
|
let mut carry = 0;
|
||||||
|
let (a_lo, a_hi) = acc.split_at_mut(b.len());
|
||||||
|
|
||||||
for (i, bi) in b.iter().enumerate() {
|
for (a, &b) in a_lo.iter_mut().zip(b) {
|
||||||
acc[i] = mac_with_carry(acc[i], *bi, c, &mut carry);
|
*a = mac_with_carry(*a, b, c, &mut carry);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut i = b.len();
|
let mut a = a_hi.iter_mut();
|
||||||
|
|
||||||
while carry != 0 {
|
while carry != 0 {
|
||||||
acc[i] = adc(acc[i], 0, &mut carry);
|
let a = a.next().expect("carry overflow during multiplication!");
|
||||||
i += 1;
|
*a = adc(*a, 0, &mut carry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue