eth_pairings/
arithmetics.rs

1/// Calculate a - b - borrow, returning the result and modifying
2/// the borrow value.
3#[inline(always)]
4pub fn sbb(a: u64, b: u64, borrow: &mut u64) -> u64 {
5    let tmp = (1u128 << 64) + u128::from(a) - u128::from(b) - u128::from(*borrow);
6
7    *borrow = if tmp >> 64 == 0 { 1 } else { 0 };
8
9    tmp as u64
10}
11
12/// Calculate a + b + carry, returning the sum and modifying the
13/// carry value.
14#[inline(always)]
15pub fn adc(a: u64, b: u64, carry: &mut u64) -> u64 {
16    let tmp = u128::from(a) + u128::from(b) + u128::from(*carry);
17
18    *carry = (tmp >> 64) as u64;
19
20    tmp as u64
21}
22
23/// Calculate a + (b * c) + carry, returning the least significant digit
24/// and setting carry to the most significant digit.
25#[inline(always)]
26pub fn mac_with_carry(a: u64, b: u64, c: u64, carry: &mut u64) -> u64 {
27    let tmp = (u128::from(a)) + u128::from(b) * u128::from(c) + u128::from(*carry);
28
29    *carry = (tmp >> 64) as u64;
30
31    tmp as u64
32}