Skip to content

Commit 2a0132c

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

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/mem/x86_64.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
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. Note that "rep cmps" has received no such
6+
// enhancement, so it is not used to implement memcmp.
7+
//
8+
// On certain recent Intel processors, "rep movsb" and "rep stosb" have been
9+
// further enhanced to automatically select the best microarchitectural
10+
// implementation based on length and alignment. See the following features from
11+
// the "Intel® 64 and IA-32 Architectures Optimization Reference Manual":
12+
// - ERMSB - Enhanced REP MOVSB and STOSB (Ivy Bridge and later)
13+
// - FSRM - Fast Short REP MOV (Ice Lake and later)
14+
// - Fast Zero-Length MOVSB (On no current hardware)
15+
// - Fast Short STOSB (On no current hardware)
16+
// However, to avoid run-time feature detection, we don't use these byte-based
17+
// instructions for most of the copying, preferring the qword variants.
18+
319
#[cfg_attr(all(feature = "mem", not(feature = "mangled-names")), no_mangle)]
420
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 {
521
asm!(

0 commit comments

Comments
 (0)