Quantcast
Viewing latest article 33
Browse Latest Browse All 36

Answer by Noldorin for What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C?

Although I would probably only use this method if I absolutely required the best possible performance (e.g. for writing some sort of board game AI involving bitboards), the most efficient solution is to use inline ASM. See the Optimisations section of this blog post for code with an explanation.

[...], the bsrl assembly instruction computes the position of the most significant bit. Thus, we could use this asm statement:

asm ("bsrl %1, %0"     : "=r" (position)      : "r" (number));

Viewing latest article 33
Browse Latest Browse All 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>