News for hackers. Stuff that matters.
Re:Beating the Compiler by swolchok on Tuesday November 29, 2016 @03:39AM (#13061718)
> An equivalent but faster variant that the compiler generates is "xor r9d, r9d".

Can you explain why this is faster? I assumed the ALU would be 64 bits wide, and 32-bit operations would just leave half of it unused.

Re:Beating the Compiler by bjourne on Tuesday November 29, 2016 @04:40AM (#13061953)
They are equivalent due to zero extension. See http://stackoverflow.com/questions/11177137/why-do-most-x64-... But the encoding for most instructions using 32bit operands are shorter than 64bit operands. And shorter code is better because it fits better in caches and jumps are closer and so on.

Though I was wrong about that particular case because "xor r9d, r9d" and "xor r9, r9" are both three bytes long. But "xor eax, eax" is two bytes and "xor rax, rax" is three bytes. So that's why you should use the old GPR:s when you are able to choose.

Re:Beating the Compiler by gpderetta on Tuesday November 29, 2016 @09:58AM (#13063371)
CPUs special case xor r,r as clearing the register and breaking dependency chains. Do they do the same thing when relying on implicit zero extension? (Can't be bothered to check Agner)