Skip to content

Commit 8ab6f08

Browse files
authored
Remove incorrectly placed preserves_flags, and other inline asm fixes
* `repe` is "repeat while equal", which only makes sense for string comparisons. Change it to `rep`. (The encoding is the same so there is no performance change.) * Remove an unneeded `test`. This was added in ae557bd ("Skip rep movsb in copy_backward if possible"). The `jz` was removed in ef37a23 ("Remove branches around rep movsb/stosb") but the `test` was missed. * Remove an incorrect `preserves_flags`; `add` and `sub` affect flags. Discussion: #911 Fixes: ef37a23 ("Remove branches around rep movsb/stosb") Fixes: c30322a ("Align destination in mem* instructions.") [ Added details to the commit message - Trevor ]
1 parent 23f6f33 commit 8ab6f08

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

compiler-builtins/src/mem/x86_64.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use core::{intrinsics, mem};
2323
#[cfg(target_feature = "ermsb")]
2424
pub unsafe fn copy_forward(dest: *mut u8, src: *const u8, count: usize) {
2525
asm!(
26-
"repe movsb [rdi], [rsi]",
26+
"rep movsb [rdi], [rsi]",
2727
inout("rcx") count => _,
2828
inout("rdi") dest => _,
2929
inout("rsi") src => _,
@@ -70,7 +70,6 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
7070
"sub rdi, 7",
7171
"mov rcx, {qword_count:r}",
7272
"rep movsq",
73-
"test {pre_byte_count:e}, {pre_byte_count:e}",
7473
"add rsi, 7",
7574
"add rdi, 7",
7675
"mov ecx, {pre_byte_count:e}",
@@ -81,16 +80,15 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
8180
inout("ecx") byte_count => _,
8281
inout("rdi") dest.add(count - 1) => _,
8382
inout("rsi") src.add(count - 1) => _,
84-
// We modify flags, but we restore it afterwards
85-
options(nostack, preserves_flags)
83+
options(nostack)
8684
);
8785
}
8886

8987
#[inline(always)]
9088
#[cfg(target_feature = "ermsb")]
9189
pub unsafe fn set_bytes(dest: *mut u8, c: u8, count: usize) {
9290
asm!(
93-
"repe stosb [rdi], al",
91+
"rep stosb [rdi], al",
9492
inout("rcx") count => _,
9593
inout("rdi") dest => _,
9694
inout("al") c => _,

0 commit comments

Comments
 (0)