Skip to content

Commit b78ab2f

Browse files
authored
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`.
2 parents c80286d + 8b7d3d3 commit b78ab2f

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

library/core/src/num/uint_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ macro_rules! uint_impl {
24452445
// to generate optimal code for now, and LLVM doesn't have an equivalent intrinsic
24462446
let (a, b) = self.overflowing_sub(rhs);
24472447
let (c, d) = a.overflowing_sub(borrow as $SelfT);
2448-
(c, b || d)
2448+
(c, b | d)
24492449
}
24502450

24512451
/// Calculates `self` - `rhs` with a signed `rhs`

tests/assembly/x86_64-bigint-add.rs tests/assembly/x86_64-bigint-helpers.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#![no_std]
77
#![feature(bigint_helper_methods)]
88

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

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

@@ -31,3 +31,24 @@ pub unsafe extern "sysv64" fn bigint_chain_carrying_add(
3131
}
3232
carry
3333
}
34+
35+
// CHECK-LABEL: bigint_chain_borrowing_sub:
36+
#[no_mangle]
37+
pub unsafe extern "sysv64" fn bigint_chain_borrowing_sub(
38+
dest: *mut u64,
39+
src1: *const u64,
40+
src2: *const u64,
41+
n: usize,
42+
mut carry: bool,
43+
) -> bool {
44+
// CHECK: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8]
45+
// CHECK: sbb [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8]
46+
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]]
47+
// CHECK: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16]
48+
// CHECK: sbb [[TEMP]], qword ptr [rdx + 8*[[IND]] + 16]
49+
// CHECK: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP]]
50+
for i in 0..n {
51+
(*dest.add(i), carry) = u64::borrowing_sub(*src1.add(i), *src2.add(i), carry);
52+
}
53+
carry
54+
}

0 commit comments

Comments
 (0)