while (x)
{
- x = x >> 1;
+ x >>= 1;
i--;
}
return i;
/* 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)