[vlc-commits] popcount(): compute bit weight

Rémi Denis-Courmont git at videolan.org
Tue Feb 15 18:20:43 CET 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Feb 15 18:53:00 2011 +0200| [9477ef1f3b824dbae9a57a7f918f5809d3f0027f] | committer: Rémi Denis-Courmont

popcount(): compute bit weight

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9477ef1f3b824dbae9a57a7f918f5809d3f0027f
---

 include/vlc_common.h |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index b312a72..2fbcdc3 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -625,6 +625,23 @@ 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))
 
+/* Bit weight */
+LIBVLC_USED
+static inline unsigned popcount (unsigned x)
+{
+#ifdef __GNUC_
+    return __builtin_popcount (x);
+#else
+    unsigned count = 0;
+    while (x)
+    {
+        count += x & 1;
+        x = x >> 1;
+    }
+    return count;
+#endif
+}
+
 /* Free and set set the variable to NULL */
 #define FREENULL(a) do { free( a ); a = NULL; } while(0)
 



More information about the vlc-commits mailing list