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.
This commit is contained in:
David Hoppenbrouwers 2022-07-07 13:20:41 +02:00
parent 30e0c1f4c2
commit 04c223f0df
No known key found for this signature in database
GPG key ID: A9156EA5E4B644FF

View file

@ -73,15 +73,21 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
// We can't separate this block due to std/cld
asm!(
"std",
"test %ecx, %ecx",
"jz 1f",
"rep movsb",
"1:",
"sub $7, %rsi",
"sub $7, %rdi",
"mov {qword_count}, %rcx",
"rep movsq",
"test {pre_byte_count:e}, {pre_byte_count:e}",
"jz 1f",
"add $7, %rsi",
"add $7, %rdi",
"mov {pre_byte_count:e}, %ecx",
"rep movsb",
"1:",
"cld",
pre_byte_count = in(reg) pre_byte_count,
qword_count = in(reg) qword_count,