News for hackers. Stuff that matters.
Re:An optimization guide for assembly programmers and compil... by heyjudy on Monday February 11, 2019 @09:16PM (#19140445)
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.

Re:An optimization guide for assembly programmers and compil... by caf on Monday February 11, 2019 @09:51PM (#19140588)
The 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.
Re:An optimization guide for assembly programmers and compil... by kijiki on Monday February 11, 2019 @10:42PM (#19140838)
Probably not directly faster, but "xor %rax, %rax" is still smaller (and thus faster if you're icache constrained) than "mov $0x0, %rax"
Re:An optimization guide for assembly programmers and compil... by userbinator on Monday February 11, 2019 @11:10PM (#19140981)
It is still faster because the register renamer handles it --- ditto for "sub reg, reg":

https://randomascii.wordpress.com/2012/12/29/the-surprising-...

Re:An optimization guide for assembly programmers and compil... by jabl on Tuesday February 12, 2019 @02:35AM (#19141734)
"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).

Re:An optimization guide for assembly programmers and compil... by bogomipz on Monday February 11, 2019 @10:58PM (#19140924)
>"and Abrash'es book was the magnum opus of the pre-P6 era."

What book is that?

Re:An optimization guide for assembly programmers and compil... by vnorilo on Tuesday February 12, 2019 @12:08AM (#19141199)
Probably Zen of Code Optimization. Good times.
Re:An optimization guide for assembly programmers and compil... by bogomipz on Tuesday February 12, 2019 @01:02AM (#19141416)
The Zen of Assembler? Does that sound correct? That's the closest I could find.
Re:An optimization guide for assembly programmers and compil... by markedathome on Tuesday February 12, 2019 @04:10AM (#19142108)
Zen of Code Optimization 1994 ( 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-Progr...)
Re:An optimization guide for assembly programmers and compil... by xsgsdfgsdg on Tuesday February 12, 2019 @06:04AM (#19142553)
XOR was never faster, it is 2 bytes-vs 3 bytes instruction size.