Skip to content

Commit dd7b7dc

Browse files
committed
mem: Add documentations for REP string insturctions
Signed-off-by: Joe Richey <[email protected]>
1 parent fb03d26 commit dd7b7dc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/mem/x86_64.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
use super::c_int;
22

3+
// On most modern Intel and AMD processors, "rep movsq" and "rep stosq" have
4+
// been enhanced to perform better than an simple qword loop, making them ideal
5+
// for implementing memcpy/memset.
6+
//
7+
// On certain recent Intel processors, "rep movsb" and "rep stosb" have been
8+
// further enhanced to automatically select the best microarchitectural
9+
// implementation based on length and alignment.
10+
// See "Intel® 64 and IA-32 Architectures Optimization Reference Manual"
11+
// - Enhanced REP MOVSB and STOSB operation (ERMSB) (section 3.7.7)
12+
// - Fast Short REP MOV (FSRM)
13+
// However, to avoid run-time feature detection, we don't use these byte-based
14+
// instructions for most of the copying, instead using the qword variants.
15+
316
#[cfg_attr(all(feature = "mem", not(feature = "mangled-names")), no_mangle)]
417
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 {
518
asm!(

0 commit comments

Comments
 (0)