3 ms·
> memcpy and memset use SSE on some generations, but these days are best inlined by the compiler as "rep movsb/stosb". Why? I’ve usually seen this get compiled
by saagarjha 7y ago
> memcpy and memset use SSE on some generations, but these days are best inlined by the compiler as "rep movsb/stosb".
Why? I’ve usually seen this get compiled to some version of “mov byte ptr, inc”.
- bonzini 7y agoYou want to copy more one byte at a time (unrolling by 4, 8 or more; and for memset, multiplying the stored value by 0x01010101...). In recent processors rep movsb and rep stosb do all that in microcode, and are also able to copy or fill the destination one cache line at a time.