diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-29 22:16:43 +0100 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-29 22:32:13 +0100 |
| commit | 4a4186e4d1168f9faf3df019596bcf87f0a4dc2b (patch) | |
| tree | 85a487d67813efc99ffe2da973ceefb3caac1bfe /src/libcore/num | |
| parent | d8a0dd7ae88023bd09fa4b86c9ca1f6ed8095b43 (diff) | |
| download | rust-4a4186e4d1168f9faf3df019596bcf87f0a4dc2b.tar.gz rust-4a4186e4d1168f9faf3df019596bcf87f0a4dc2b.zip | |
Use LLVM intrinsics for saturating add/sub
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 7cf2317f4b3..f80f8392827 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -883,11 +883,16 @@ $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn saturating_add(self, rhs: Self) -> Self { + #[cfg(stage0)] match self.checked_add(rhs) { Some(x) => x, None if rhs >= 0 => Self::max_value(), None => Self::min_value(), } + #[cfg(not(stage0))] + { + intrinsics::saturating_add(self, rhs) + } } } @@ -908,11 +913,16 @@ $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn saturating_sub(self, rhs: Self) -> Self { + #[cfg(stage0)] match self.checked_sub(rhs) { Some(x) => x, None if rhs >= 0 => Self::min_value(), None => Self::max_value(), } + #[cfg(not(stage0))] + { + intrinsics::saturating_sub(self, rhs) + } } } @@ -2744,10 +2754,15 @@ assert_eq!(200u8.saturating_add(127), 255);", $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn saturating_add(self, rhs: Self) -> Self { + #[cfg(stage0)] match self.checked_add(rhs) { Some(x) => x, None => Self::max_value(), } + #[cfg(not(stage0))] + { + intrinsics::saturating_add(self, rhs) + } } } @@ -2766,10 +2781,15 @@ assert_eq!(13", stringify!($SelfT), ".saturating_sub(127), 0);", $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn saturating_sub(self, rhs: Self) -> Self { + #[cfg(stage0)] match self.checked_sub(rhs) { Some(x) => x, None => Self::min_value(), } + #[cfg(not(stage0))] + { + intrinsics::saturating_sub(self, rhs) + } } } |
