5 ms·
I still remember the olden days when XOR AX,AX was faster than MOV AX,0 and Abrash'es book was the magnum opus of the pre-P6 era. I guess I better th
by heyjudy 8y ago
I still remember the olden days when
XOR AX,AX
was faster than
MOV AX,0
and Abrash'es book was the magnum opus of the pre-P6 era.
I guess I better throw most of those assumptions out for modern microarchitectures.
- caf 8y agoThe XOR is still idiomatic because it is smaller than the MOV, because the immediate zero has to be encoded as the same size as the destination register.
- kijiki 8y agoProbably not directly faster, but "xor %rax, %rax" is still smaller (and thus faster if you're icache constrained) than "mov $0x0, %rax"
- userbinator 8y agoIt is still faster because the register renamer handles it --- ditto for "sub reg, reg": https://randomascii.wordpress.com/2012/12/29/the-surprising-subtleties-of-zeroing-a-register/ https://randomascii.wordpress.com/2012/12/29/the-surprising-...
- jabl 8y ago"xor %eax, %eax" is even smaller (2 bytes vs. 3) and does the same thing since operations on the 32-bit subregisters are defined to zero the upper half [1]. This is what compilers tend to do when they want to zero a register. [1] This is not true for 8- or 16-bit subregisters, causing all kinds of fun issues (see "partial register stalls", also discussed in Agner Fog's materials).
- bogomipz 8y ago>"and Abrash'es book was the magnum opus of the pre-P6 era." What book is that?
- vnorilo 8y agoProbably Zen of Code Optimization. Good times.
- bogomipz 8y agoThe Zen of Assembler? Does that sound correct? That's the closest I could find.
- markedathome 8y agoZen of Code Optimization 1994 ( https://www.amazon.com/Zen-Code-Optimization-Ultimate-Software/dp/1883577039 https://www.amazon.com/Zen-Code-Optimization-Ultimate-Softwa...) is the follow up to Zen of Assembly Language 1990 (https://www.amazon.com/Zen-Assembly-Language-Knowledge-Programming/dp/0673386023 https://www.amazon.com/Zen-Assembly-Language-Knowledge-Progr...)
- deleted 8y ago[deleted]
- xsgsdfgsdg 8y agoXOR was never faster, it is 2 bytes-vs 3 bytes instruction size.