4 ms·
> I know of no compiler that generates the Intel string instructions. Not even Forth! Yes, because they are measurably slower than their equivalent primitive i
by a1k0n 15y ago
> I know of no compiler that generates the Intel string instructions. Not even Forth!
Yes, because they are measurably slower than their equivalent primitive instruction sequences, and the space saved isn't really all that significant when you consider all the other loads and stores necessary to run them. I think they've been actually slower since either the 486 or Pentium days. I'm pretty sure, for instance, Watcom C++ would generate "rep movsd" sequences for memcpy back in the 386/486 days, back when it was actually an optimization to do so.
- a1k0n 15y agoActually I have to update my own comment here, due to a completely unexpected circumstance. I just happened to diassemble some 64-bit test code I wrote tonight (unrelated to testing out the string instruction theory) and lo and behold, Apple gcc-4.2.1 with -O3 turned memset(x, 0, 7*sizeof(uint64_t)) into a 3-byte "rep stos" instruction: 0x0000000100000cee <main+30>: cld 0x0000000100000cef <main+31>: mov $0x7,%ecx 0x0000000100000cf4 <main+36>: xor %eax,%eax 0x0000000100000cf6 <main+38>: mov %r15,%rdi 0x0000000100000cf9 <main+41>: rep stos %rax,%es:(%rdi) 0x0000000100000cfc <main+44>: ... It even does pretty much the same thing with -m32 and with optimization turned down to -O1. So perhaps things have changed.