Commit 82fdabda authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

vlc_common: add ctz() to count trailing zeroes

parent c5d9ac73
......@@ -524,7 +524,7 @@ static inline unsigned clz (unsigned x)
while (x)
{
x = x >> 1;
x >>= 1;
i--;
}
return i;
......@@ -536,6 +536,24 @@ static inline unsigned clz (unsigned x)
/* XXX: this assumes that int is 32-bits or more */
#define clz32( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint32_t)) * 8))
/** Count trailing zeroes */
VLC_USED
static inline unsigned ctz (unsigned x)
{
#if VLC_GCC_VERSION(3,4)
return __builtin_ctz (x);
#else
unsigned i = sizeof (x) * 8;
while (x)
{
x <<= 1;
i--;
}
return i;
#endif
}
/** Bit weight */
VLC_USED
static inline unsigned popcount (unsigned x)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment