by mierle · 13y ago · 0 comments
int div_by_2(int x) {return x/2;}
compiles to: div_by_2:
movl %edi, %eax
shrl $31, %eax
addl %edi, %eax
sarl %eax
ret
Meanwhile, the signed variant: unsigned int div_by_2(unsigned int x) {return x/2;}
compiles to: div_by_2:
movl %edi, %eax
shrl %eax
ret
My conclusion remains that for hot loops, you should check the compilers assembly to make sure the compiler is applying the strength reduction you expect.No comments yet.