Skip to content

Commit 77e7f8a

Browse files
committed
Added psadbw support for u8::abs_diff.
1 parent 4f5563d commit 77e7f8a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

library/core/src/num/uint_macros.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1504,10 +1504,16 @@ macro_rules! uint_impl {
15041504
#[unstable(feature = "int_abs_diff", issue = "none")]
15051505
#[inline]
15061506
pub const fn abs_diff(self, other: Self) -> Self {
1507-
if self < other {
1508-
other - self
1507+
if mem::size_of::<Self>() == 1 {
1508+
// 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
15091511
} else {
1510-
self - other
1512+
if self < other {
1513+
other - self
1514+
} else {
1515+
self - other
1516+
}
15111517
}
15121518
}
15131519

0 commit comments

Comments
 (0)