4 ms·
Speaking of the while head, after posting this I realized that there is an optimization you can do by moving the bitshift into the while head, like this: while
by robalni 4y ago
Speaking of the while head, after posting this I realized that there is an optimization you can do by moving the bitshift into the while head, like this:
while (x >>= 1)
This makes gcc compile the code to one instruction less per iteration because it can use the status flags generated by the bitshift to determine whether to jump. Now the loop will only be 3 instructions long and the entire function 8 instructions. https://godbolt.org/z/fna8de367 https://godbolt.org/z/fna8de367
- svnpenn 4y agowhoosh