1use crate::big_digit::{BigDigit, DoubleBigDigit, BITS};
23// Add with carry:
4#[inline]
5pub fn adc(a: BigDigit, b: BigDigit, acc: &mut DoubleBigDigit) -> BigDigit {
6*acc += a as DoubleBigDigit;
7*acc += b as DoubleBigDigit;
8let lo = *acc as BigDigit;
9*acc >>= BITS;
10 lo
11}
1213// Only for the Add impl:
14#[inline]
15pub fn __add2(a: &mut [BigDigit], b: &[BigDigit]) -> BigDigit {
16debug_assert!(a.len() >= b.len());
1718let mut carry = 0;
19let (a_lo, a_hi) = a.split_at_mut(b.len());
2021for (a, b) in a_lo.iter_mut().zip(b) {
22*a = adc(*a, *b, &mut carry);
23 }
2425if carry != 0 {
26for a in a_hi {
27*a = adc(*a, 0, &mut carry);
28if carry == 0 {
29break;
30 }
31 }
32 }
3334 carry as BigDigit
35}
3637/// /Two argument addition of raw slices:
38/// a += b
39///
40/// The caller _must_ ensure that a is big enough to store the result - typically this means
41/// resizing a to max(a.len(), b.len()) + 1, to fit a possible carry.
42pub fn add2(a: &mut [BigDigit], b: &[BigDigit]) {
43let carry = __add2(a, b);
4445debug_assert!(carry == 0);
46}