Skip to content

Commit

Permalink
Unrolled build for rust-lang#133796
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#133796 - TDecking:borrowing-sub, r=tgross35

Update the definition of `borrowing_sub`

Complementary PR to rust-lang#133674, which only updated `carrying_add`.
  • Loading branch information
rust-timer authored Dec 3, 2024
2 parents 490b2cc + 8b7d3d3 commit b4f4d79
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ macro_rules! uint_impl {
// 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)
(c, b | d)
}

/// Calculates `self` - `rhs` with a signed `rhs`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#![no_std]
#![feature(bigint_helper_methods)]

// This checks that the `carrying_add` implementation successfully chains, to catch
// issues like <https://github.com/rust-lang/rust/issues/85532#issuecomment-2495119815>
// This checks that the `carrying_add` and `borrowing_sub` implementation successfully chain,
// to catch issues like <https://github.com/rust-lang/rust/issues/85532#issuecomment-2495119815>

// This forces the ABI to avoid the windows-vs-linux ABI differences.

Expand All @@ -31,3 +31,24 @@ pub unsafe extern "sysv64" fn bigint_chain_carrying_add(
}
carry
}

// CHECK-LABEL: bigint_chain_borrowing_sub:
#[no_mangle]
pub unsafe extern "sysv64" fn bigint_chain_borrowing_sub(
dest: *mut u64,
src1: *const u64,
src2: *const u64,
n: usize,
mut carry: bool,
) -> bool {
// CHECK: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8]
// CHECK: sbb [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]]
// CHECK: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16]
// CHECK: sbb [[TEMP]], qword ptr [rdx + 8*[[IND]] + 16]
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP]]
for i in 0..n {
(*dest.add(i), carry) = u64::borrowing_sub(*src1.add(i), *src2.add(i), carry);
}
carry
}

0 comments on commit b4f4d79

Please sign in to comment.