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