1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::U256;
use core::mem::MaybeUninit;
#[inline]
pub fn sub2(r: &mut U256, a: &U256) {
let (lo, carry) = r.low().overflowing_sub(*a.low());
*r.low_mut() = lo;
*r.high_mut() = r.high().wrapping_sub(carry as _).wrapping_sub(*a.high());
}
#[inline]
pub fn sub3(r: &mut MaybeUninit<U256>, a: &U256, b: &U256) {
let (lo, carry) = a.low().overflowing_sub(*b.low());
let hi = a.high().wrapping_sub(carry as _).wrapping_sub(*b.high());
unsafe {
r.as_mut_ptr().write(U256::from_words(hi, lo));
}
}
#[inline]
pub fn subc(r: &mut MaybeUninit<U256>, a: &U256, b: &U256) -> bool {
let (lo, carry_lo) = a.low().overflowing_sub(*b.low());
let (hi, carry_c) = a.high().overflowing_sub(carry_lo as _);
let (hi, carry_hi) = hi.overflowing_sub(*b.high());
unsafe {
r.as_mut_ptr().write(U256::from_words(hi, lo));
}
carry_c || carry_hi
}