Skip to content

Commit f03ed0e

Browse files
committed
Skip rep movsb in copy_backward if possible
There is currently no measureable performance difference in benchmarks but it likely will make a difference in real workloads.
1 parent fbc0922 commit f03ed0e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/mem/x86_64.rs

+6
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,21 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
7373
// We can't separate this block due to std/cld
7474
asm!(
7575
"std",
76+
"test %ecx, %ecx",
77+
"jz 1f",
7678
"rep movsb",
79+
"1:",
7780
"sub $7, %rsi",
7881
"sub $7, %rdi",
7982
"mov {qword_count}, %rcx",
8083
"rep movsq",
84+
"test {pre_byte_count:e}, {pre_byte_count:e}",
85+
"jz 1f",
8186
"add $7, %rsi",
8287
"add $7, %rdi",
8388
"mov {pre_byte_count:e}, %ecx",
8489
"rep movsb",
90+
"1:",
8591
"cld",
8692
pre_byte_count = in(reg) pre_byte_count,
8793
qword_count = in(reg) qword_count,

0 commit comments

Comments
 (0)