Skip to content

Commit

Permalink
mem: Add documentations for REP string insturctions
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Richey <[email protected]>
  • Loading branch information
josephlr committed Oct 15, 2020
1 parent 8d25b6a commit 5886c98
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mem/x86_64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
use super::c_int;

// On most modern Intel and AMD processors, "rep movsq" and "rep stosq" have
// been enhanced to perform better than an simple qword loop, making them ideal
// for implementing memcpy/memset.
//
// On certain recent Intel processors, "rep movsb" and "rep stosb" have been
// further enhanced to automatically select the best microarchitectural
// implementation based on length and alignment.
// See "Intel® 64 and IA-32 Architectures Optimization Reference Manual"
// - Enhanced REP MOVSB and STOSB operation (ERMSB) (section 3.7.7)
// - Fast Short REP MOV (FSRM)
// However, to avoid run-time feature detection, we don't use these byte-based
// instructions for most of the copying, instead using the qword variants.

#[cfg_attr(all(feature = "mem", not(feature = "mangled-names")), no_mangle)]
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 {
asm!(
Expand Down

0 comments on commit 5886c98

Please sign in to comment.