diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-03 17:27:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-03 17:27:11 +0100 |
| commit | b78ab2fdc1ae11578bec633f8745d819ea526d90 (patch) | |
| tree | 4036a848ab06b97865cfc4b0858434bc8edd7ef0 | |
| parent | c80286d35ea9d82e6d97be38d64c5d58258712b6 (diff) | |
| parent | 8b7d3d396761f7fe4d609f9983bd196ef127e8c9 (diff) | |
| download | rust-b78ab2fdc1ae11578bec633f8745d819ea526d90.tar.gz rust-b78ab2fdc1ae11578bec633f8745d819ea526d90.zip | |
Rollup merge of #133796 - TDecking:borrowing-sub, r=tgross35
Update the definition of `borrowing_sub` Complementary PR to https://github.com/rust-lang/rust/pull/133674, which only updated `carrying_add`.
| -rw-r--r-- | library/core/src/num/uint_macros.rs | 2 | ||||
| -rw-r--r-- | tests/assembly/x86_64-bigint-helpers.rs (renamed from tests/assembly/x86_64-bigint-add.rs) | 25 |
2 files changed, 24 insertions, 3 deletions
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index c853db181ce..c79b2f7ad8e 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -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` diff --git a/tests/assembly/x86_64-bigint-add.rs b/tests/assembly/x86_64-bigint-helpers.rs index 4bcb9732c64..198e5543539 100644 --- a/tests/assembly/x86_64-bigint-add.rs +++ b/tests/assembly/x86_64-bigint-helpers.rs @@ -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. @@ -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 +} |
