What’s the best way to copy a block of data from one memory location to another on a modern x86 processor?
Perhaps surprisingly, this isn’t a simple question to answer.
Even in 2023, Linus Torvalds himself has felt it necessary to roll up his sleeves and make some changes to improve the implementation of data copying on x86 processors in the Linux kernel.
The choices are between what might be called a RISCy approach and a CISCy approach. Or in other words, between using lots of simple instructions or a small number of complex instructions.
This all sheds some interesting insights into the evolution of the x86 architecture and how complex decisions to optimize code can be.
We’ll start by looking at one x86 instruction that can be used to copy data.