about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOrson Peters <orsonpeters@gmail.com>2021-09-09 23:01:28 +0200
committerOrson Peters <orsonpeters@gmail.com>2021-09-09 23:01:28 +0200
commit77e7f8ae88910d64ebeba5689e90d7c1a01f2bf3 (patch)
treee59ac1c262c2098bfc9111f77d2b2d3bda351b43
parent4f5563d0275118cbebbc2a3d3d60be1a7600adaa (diff)
downloadrust-77e7f8ae88910d64ebeba5689e90d7c1a01f2bf3.tar.gz
rust-77e7f8ae88910d64ebeba5689e90d7c1a01f2bf3.zip
Added psadbw support for u8::abs_diff.
-rw-r--r--library/core/src/num/uint_macros.rs12
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
+                }
             }
         }