@@ -18,9 +18,14 @@ use super::c_int;
18
18
19
19
#[ cfg_attr( all( feature = "mem" , not( feature = "mangled-names" ) ) , no_mangle) ]
20
20
pub unsafe extern "C" fn memcpy ( dest : * mut u8 , src : * const u8 , count : usize ) -> * mut u8 {
21
+ let qword_count = count >> 3 ;
22
+ let byte_count = count & 0b111 ;
21
23
asm ! (
24
+ "rep movsq [rdi], [rsi]" ,
25
+ "mov ecx, {byte_count:e}" ,
22
26
"rep movsb [rdi], [rsi]" ,
23
- inout( "rcx" ) count => _,
27
+ byte_count = in( reg) byte_count,
28
+ inout( "rcx" ) qword_count => _,
24
29
inout( "rdi" ) dest => _,
25
30
inout( "rsi" ) src => _,
26
31
options( nostack, preserves_flags)
@@ -37,25 +42,37 @@ pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, count: usize) ->
37
42
return self :: memcpy ( dest, src, count) ;
38
43
}
39
44
// copy backwards
45
+ let qword_count = count >> 3 ;
46
+ let byte_count = count & 0b111 ;
40
47
asm ! (
41
48
"std" ,
49
+ "rep movsq [rdi], [rsi]" ,
50
+ "mov ecx, {byte_count:e}" ,
51
+ "add rdi, 7" ,
52
+ "add rsi, 7" ,
42
53
"rep movsb [rdi], [rsi]" ,
43
54
"cld" ,
44
- inout( "rcx" ) count => _,
45
- inout( "rdi" ) dest. add( count) . sub( 1 ) => _,
46
- inout( "rsi" ) src. add( count) . sub( 1 ) => _,
47
- options( nostack, preserves_flags)
55
+ byte_count = in( reg) byte_count,
56
+ inout( "rcx" ) qword_count => _,
57
+ inout( "rdi" ) dest. offset( count as isize ) . wrapping_sub( 8 ) => _,
58
+ inout( "rsi" ) src. offset( count as isize ) . wrapping_sub( 8 ) => _,
59
+ options( nostack)
48
60
) ;
49
61
dest
50
62
}
51
63
52
64
#[ cfg_attr( all( feature = "mem" , not( feature = "mangled-names" ) ) , no_mangle) ]
53
65
pub unsafe extern "C" fn memset ( dest : * mut u8 , c : c_int , count : usize ) -> * mut u8 {
66
+ let qword_count = count >> 3 ;
67
+ let byte_count = count & 0b111 ;
54
68
asm ! (
69
+ "rep stosq [rdi], rax" ,
70
+ "mov ecx, {byte_count:e}" ,
55
71
"rep stosb [rdi], al" ,
56
- inout( "rcx" ) count => _,
72
+ byte_count = in( reg) byte_count,
73
+ inout( "rcx" ) qword_count => _,
57
74
inout( "rdi" ) dest => _,
58
- in( "al " ) c as u8 ,
75
+ in( "rax " ) ( c as u8 as u64 ) * 0x0101010101010101 ,
59
76
options( nostack, preserves_flags)
60
77
) ;
61
78
dest
0 commit comments