diff options
| author | Orson Peters <orsonpeters@gmail.com> | 2021-09-09 23:01:28 +0200 |
|---|---|---|
| committer | Orson Peters <orsonpeters@gmail.com> | 2021-09-09 23:01:28 +0200 |
| commit | 77e7f8ae88910d64ebeba5689e90d7c1a01f2bf3 (patch) | |
| tree | e59ac1c262c2098bfc9111f77d2b2d3bda351b43 | |
| parent | 4f5563d0275118cbebbc2a3d3d60be1a7600adaa (diff) | |
| download | rust-77e7f8ae88910d64ebeba5689e90d7c1a01f2bf3.tar.gz rust-77e7f8ae88910d64ebeba5689e90d7c1a01f2bf3.zip | |
Added psadbw support for u8::abs_diff.
| -rw-r--r-- | library/core/src/num/uint_macros.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 1bba4179f99..a5f12447fdc 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1504,10 +1504,16 @@ macro_rules! uint_impl { #[unstable(feature = "int_abs_diff", issue = "none")] #[inline] pub const fn abs_diff(self, other: Self) -> Self { - if self < other { - other - self + if mem::size_of::<Self>() == 1 { + // Trick LLVM into generating the psadbw instruction when SSE2 + // is available and this function is autovectorized for u8's. + (self as i32).wrapping_sub(other as i32).abs() as Self } else { - self - other + if self < other { + other - self + } else { + self - other + } } } |
