4 ms·
ia32 architectures do actually have an instruction which lets you do cheap memcpys and memsets --- REP (and friends). All it does it to repeat the next instruct
by david-given 10y ago
ia32 architectures do actually have an instruction which lets you do cheap memcpys and memsets --- REP (and friends). All it does it to repeat the next instruction rapidly, so if the next instruction is a set-and-increment-pointer than you get a memset. etc. (Don't know about ia64.)
Trouble is, it's still just a simple loop, and it's not that much faster than doing it the long way... and on some architectures it's actually slower. It all depends on how optimised the microcode it decodes into is. After all, it still has to set the address bus and issue a write for every location in the RAM. There are no shortcuts there.
Some architectures will let you do memcpys and memsets via the DMA engine, which can give a small performance boost, but these are usually embedded architectures. (I've used one on the MSP430.)
- MichaelGG 10y agoIs it though? The memcpy implementations I remember reading about do all sorts of exotic things depending on the size, which processor, etc. As you mention, sometimes it's still slower and depends on microcode. A dedicated memcpy instruction shouldn't have that issue right?