According to Chris Lalancette on 3/5/2010 10:03 AM:
+static int popcnt(char x)
+{
+ char count;
+ for (count = 0; x; count++)
+ x &= x-1;
+ return count;
+}
Gnulib provides the count-one-bits module, which does this much more
efficiently (via a gcc builtin, when available; otherwise without any
branching in the assembly).
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org