Skip to content

Commit

Permalink
Skip rep movsb in copy_backward if possible
Browse files Browse the repository at this point in the history
There is currently no measureable performance difference in benchmarks
but it likely will make a difference in real workloads.
  • Loading branch information
Demindiro committed Jul 7, 2022
1 parent fbc0922 commit f03ed0e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mem/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f03ed0e

Please sign in to comment.