Skip to content

Commit f15f99f

Browse files
committed
Slightly optimize main (32b) memcmp loop
It only seems to save a single instruction at first sight yet the effects are significant.
1 parent ae069f1 commit f15f99f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/mem/x86_64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ pub unsafe fn compare_bytes(a: *const u8, b: *const u8, n: usize) -> i32 {
116116

117117
// This should be equivalent to division with power-of-two sizes, except the former
118118
// somehow still leaves a call to panic because ??
119-
for _ in 0..n >> mem::size_of::<T>().trailing_zeros() {
119+
let end = a.add(n >> mem::size_of::<T>().trailing_zeros());
120+
while a != end {
120121
if a.read_unaligned() != b.read_unaligned() {
121122
return f(a.cast(), b.cast(), mem::size_of::<T>());
122123
}

0 commit comments

Comments
 (0)