|
|
|
|
|
by phamilton
5718 days ago
|
|
I'm guessing & and - are much quicker than log. & is a single instruction, - is a single instruction.
The == are single compare instructions. I'm not sure about the && , but otherwise this is simple enough to write in ~20 lines of assembly. |
|
You can figure out that a logarithm in base 2 is easy to compute in base 2 arithmetic (sounds kinda obvious, too); it's the position of the most significant bit set.
Now someone needs to come and point out that BSR has a latency 16 times that of AND, and 4 times the throughput. Touche, gentlemen.
[1] http://graphics.stanford.edu/~seander/bithacks.html#IntegerL...