Skip to content

Commit 51971a2

Browse files
committed
Remove rep_param_rev
1 parent c6a54e6 commit 51971a2

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/mem/x86_64.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, count: usize)
6969

7070
#[inline(always)]
7171
pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
72-
let (pre_byte_count, qword_count, byte_count) = rep_param_rev(dest, count);
72+
let (pre_byte_count, qword_count, byte_count) = rep_param(dest, count);
7373
// We can't separate this block due to std/cld
7474
asm!(
7575
"std",
@@ -80,12 +80,12 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
8080
"rep movsq",
8181
"add rsi, 7",
8282
"add rdi, 7",
83-
"mov ecx, {byte_count:e}",
83+
"mov ecx, {pre_byte_count:e}",
8484
"rep movsb",
8585
"cld",
86-
byte_count = in(reg) byte_count,
86+
pre_byte_count = in(reg) pre_byte_count,
8787
qword_count = in(reg) qword_count,
88-
inout("ecx") pre_byte_count => _,
88+
inout("ecx") byte_count => _,
8989
inout("rdi") dest.add(count - 1) => _,
9090
inout("rsi") src.add(count - 1) => _,
9191
// We modify flags, but we restore it afterwards
@@ -205,13 +205,3 @@ fn rep_param(dest: *mut u8, mut count: usize) -> (usize, usize, usize) {
205205
let byte_count = count & 0b111;
206206
(pre_byte_count, qword_count, byte_count)
207207
}
208-
209-
/// Determine optimal parameters for a reverse `rep` instruction (i.e. direction bit is set).
210-
fn rep_param_rev(dest: *mut u8, mut count: usize) -> (usize, usize, usize) {
211-
// Unaligned writes are still slow on modern processors, so align the destination address.
212-
let pre_byte_count = ((dest as usize + count) & 0b111).min(count);
213-
count -= pre_byte_count;
214-
let qword_count = count >> 3;
215-
let byte_count = count & 0b111;
216-
(pre_byte_count, qword_count, byte_count)
217-
}

0 commit comments

Comments
 (0)