[vlc-commits] vlc_common: add ctz() to count trailing zeroes
Rémi Denis-Courmont
git at videolan.org
Sun Jan 13 19:23:35 CET 2013
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jan 13 19:54:59 2013 +0200| [82fdabda9df936231519720e055c7033d5a209b0] | committer: Rémi Denis-Courmont
vlc_common: add ctz() to count trailing zeroes
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=82fdabda9df936231519720e055c7033d5a209b0
---
include/vlc_common.h | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/include/vlc_common.h b/include/vlc_common.h
index d09bf78..6a3dd9b 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -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)
More information about the vlc-commits
mailing list