4 ms·
If you use more registers as storage it can go faster. 'rep movs' uses no registers for storage; only source, destination and count. There are many, many tric
by bboreham 10y ago
If you use more registers as storage it can go faster. 'rep movs' uses no registers for storage; only source, destination and count.
There are many, many tricks like doing 'look ahead' to start the L1 cache bringing in the next line before we actually need it, to hide that latency.
And the article describes how there are various code paths for big blocks, short blocks, aligned, unaligned, etc.
- mikeash 10y agoThe hardware can do whatever it wants as long as it preserves the semantics. I'm sure modern CPUs use registers and perform prefetching as appropriate when they encounter a rep movs.
- masklinn 10y agoSurely the CPU hardware isn't limited to the ABI either and microcode can directly work on the physical registers?
- mikeash 10y agoIndeed. It could even conceivably use some special memcpy hardware. I doubt it goes that far, but another comment here mentions that it will use SSE or AVX registers when appropriate. `rep movsb` shouldn't be thought of as repeatedly copying single bytes from source to destination, but rather as a `memcpy` instruction with a weird name due to history. If it's used frequently enough to be worth optimizing (and it seems like it is) then Intel and AMD can easily recognize it as such and make their hardware perform the operation as efficiently as possible.
- deleted 10y ago[deleted]