Rollup merge of #138228 - TDecking:master, r=jhpratt
Use `disjoint_bitor` inside `borrowing_sub` This makes the definition of `borrowing_sub` consistent with that of `carrying_add`.
This commit is contained in:
commit
2460fc68b9
1 changed files with 8 additions and 3 deletions
|
|
@ -2533,15 +2533,20 @@ macro_rules! uint_impl {
|
|||
#[doc = concat!("assert_eq!((diff1, diff0), (3, ", stringify!($SelfT), "::MAX));")]
|
||||
/// ```
|
||||
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
|
||||
#[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
|
||||
#[must_use = "this returns the result of the operation, \
|
||||
without modifying the original"]
|
||||
#[inline]
|
||||
pub const fn borrowing_sub(self, rhs: Self, borrow: bool) -> (Self, bool) {
|
||||
// note: longer-term this should be done via an intrinsic, but this has been shown
|
||||
// to generate optimal code for now, and LLVM doesn't have an equivalent intrinsic
|
||||
let (a, b) = self.overflowing_sub(rhs);
|
||||
let (c, d) = a.overflowing_sub(borrow as $SelfT);
|
||||
(c, b | d)
|
||||
let (a, c1) = self.overflowing_sub(rhs);
|
||||
let (b, c2) = a.overflowing_sub(borrow as $SelfT);
|
||||
// SAFETY: Only one of `c1` and `c2` can be set.
|
||||
// For c1 to be set we need to have underflowed, but if we did then
|
||||
// `a` is nonzero, which means that `c2` cannot possibly
|
||||
// underflow because it's subtracting at most `1` (since it came from `bool`)
|
||||
(b, unsafe { intrinsics::disjoint_bitor(c1, c2) })
|
||||
}
|
||||
|
||||
/// Calculates `self` - `rhs` with a signed `rhs`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue