I am learning x86-64 by reading the output of GCC at -O2. To return zero it never writes mov eax, 0; it writes xor eax, eax. Before a je or jne it uses test eax, eax where I would have written cmp eax, 0. It also zeroes eax when the function clearly returns a 64-bit zero in rax.
Are these just shorter encodings, or is there a real speed difference? And is it safe to copy these idioms into hand-written code?




