Does gcc (or any other compiler) change (n%2==1) for (n&1==1)? -
to test if number odd or even, understanding test using
(n%2==1)
is same thing as
(n&1==1)
i assume first test faster (please correct me if i'm wrong), compiler recognize , "correct" it? makes difference in performance?
void main() { int n = 5; int = n & 1; } call __main movl $5, -4(%rbp) movl -4(%rbp), %eax andl $1, %eax movl %eax, -8(%rbp) addq $48, %rsp popq %rbp ret void main() { int n = 5; int = n % 2; } call __main movl $5, -4(%rbp) movl -4(%rbp), %eax cltd shrl $31, %edx addl %edx, %eax andl $1, %eax subl %edx, %eax movl %eax, -8(%rbp) addq $48, %rsp popq %rbp ret
tried gcc.exe (gcc) 4.9.2 using -s -o0
seams & 1
check parity better.
Comments
Post a Comment