
15 Jul
2010
15 Jul
'10
7:36 a.m.
ajb@spamcop.net wrote:
Many modern ISAs (at least EM64T, PPC and recent ARMs; these are just the ones I know about) have a single-instruction priority encoder usually called "count leading zeroes". In GCC, it's available as a builtin:
uint64_t log2v = v == 1 ? 0 : 64 - __builtin_clzll(v - 1);
Guess my old signal processing habits showed up ;) Of course, mapping to intrinsic is better I think. But I guess when they are not there, we need a fallback ;)