3 ms·
Alright maybe I'm stupid but I could have sworn that more than square(int): # @square(int) xor eax, eax ret
by 0x6c6f6c 10y ago
Alright maybe I'm stupid but I could have sworn that more than
square(int): # @square(int)
xor eax, eax
ret
is required to perform this, what's going on?
- akeruu 10y agoX can always by devided by 2, meaning the condition will always be false thus returning "a" unchanged. "xor eax, eax" is a shortcut to "mov eax, 0".
- syncsynchalt 10y ago"xor r,r" is intel-ese for "set r to zero". For various reasons it's faster and smaller than the more obvious "mov r,0". From this we can see that gcc and clang have figured out that the "if" can never be true, then they elided the loop, then optimized out the variable, ending in the equivalent of "return 0;".