3 ms·
Apparently not true, at least in a simple function. https://godbolt.org/g/hfpHz7 https://godbolt.org/g/hfpHz7 int isEven(int number) { return number
by vardump 9y ago
Apparently not true, at least in a simple function.
https://godbolt.org/g/hfpHz7 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
- Hello71 9y agothat function checks if a number is odd, not even. https://godbolt.org/g/7Khcg9 https://godbolt.org/g/7Khcg9
- vardump 9y agoMy 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.