diff options
| author | bors <bors@rust-lang.org> | 2021-08-04 12:58:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-04 12:58:31 +0000 |
| commit | 7f3dc0464422ebadf3b8647f591bcf6e3107e805 (patch) | |
| tree | a59cd1b4392ab4df27811595393a1d1fe523feeb /library/core/src | |
| parent | 87d713ff2b000e3827ebb8be974b280188fac783 (diff) | |
| parent | a3fb1d618823ccab589fbca2b6d4cc3619900bc1 (diff) | |
| download | rust-7f3dc0464422ebadf3b8647f591bcf6e3107e805.tar.gz rust-7f3dc0464422ebadf3b8647f591bcf6e3107e805.zip | |
Auto merge of #87150 - rusticstuff:simplify_wrapping_neg, r=m-ou-se
Make wrapping_neg() use wrapping_sub(), #[inline(always)] This is a follow-up change to the fix for #75598. It simplifies the implementation of wrapping_neg() for all integer types by just calling 0.wrapping_sub(self) and always inlines it. This leads to much less assembly code being emitted for opt-level≤1 and thus much better performance for debug-compiled code. Background is [this discussion on the internals forum](https://internals.rust-lang.org/t/why-does-rust-generate-10x-as-much-unoptimized-assembly-as-gcc/14930).
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/num/int_macros.rs | 4 | ||||
| -rw-r--r-- | library/core/src/num/uint_macros.rs | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 6e8f753ce50..0bc646995c7 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1132,9 +1132,9 @@ macro_rules! int_impl { /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] - #[inline] + #[inline(always)] pub const fn wrapping_neg(self) -> Self { - self.overflowing_neg().0 + (0 as $SelfT).wrapping_sub(self) } /// Panic-free bitwise shift-left; yields `self << mask(rhs)`, where `mask` removes diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 91f07c63aa9..ae113a47e95 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1246,9 +1246,9 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "num_wrapping", since = "1.2.0")] #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] - #[inline] + #[inline(always)] pub const fn wrapping_neg(self) -> Self { - self.overflowing_neg().0 + (0 as $SelfT).wrapping_sub(self) } /// Panic-free bitwise shift-left; yields `self << mask(rhs)`, |
