Commit 33bc26c1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont Committed by Jean-Paul Saman

vlc_common: add ctz() to count trailing zeroes

(cherry picked from commit 82fdabda9df936231519720e055c7033d5a209b0)
Signed-off-by: default avatarJean-Paul Saman <jpsaman@videolan.org>
parent b8fac6a7
......@@ -615,7 +615,7 @@ static inline unsigned clz (unsigned x)
while (x)
{
x = x >> 1;
x >>= 1;
i--;
}
return i;
......@@ -627,6 +627,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