Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Apparently not true, at least in a simple function.

https://godbolt.org/g/hfpHz7

  int isEven(int number)
  {
      return number & 1;
  }
gcc 7.3, -O1, -O2 and -O3 (identical codegen for all optimization levels):

  isEven(int):
    mov eax, edi
    and eax, 1
    ret


that function checks if a number is odd, not even.

https://godbolt.org/g/7Khcg9


My bad. Didn't even check it at any point.

Anyways, you still prove my point. All those three are pretty close.

-O1 sete instruction is very slightly unoptimal, but even it is just a fractional clock cycle.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: