We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4f5563d commit 77e7f8aCopy full SHA for 77e7f8a
library/core/src/num/uint_macros.rs
@@ -1504,10 +1504,16 @@ macro_rules! uint_impl {
1504
#[unstable(feature = "int_abs_diff", issue = "none")]
1505
#[inline]
1506
pub const fn abs_diff(self, other: Self) -> Self {
1507
- if self < other {
1508
- other - self
+ if mem::size_of::<Self>() == 1 {
+ // Trick LLVM into generating the psadbw instruction when SSE2
1509
+ // is available and this function is autovectorized for u8's.
1510
+ (self as i32).wrapping_sub(other as i32).abs() as Self
1511
} else {
- self - other
1512
+ if self < other {
1513
+ other - self
1514
+ } else {
1515
+ self - other
1516
+ }
1517
}
1518
1519
0 commit comments