summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util/u_math.h
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-11-23 18:04:22 -0700
committerBrian Paul <brianp@vmware.com>2009-11-23 18:04:22 -0700
commit15740eb03ca8fb7eda585c612c1b36ec9df4474a (patch)
tree5965283060497b396b2ebeffa216693062f9f30f /src/gallium/auxiliary/util/u_math.h
parent5173d14cb5821637f22247d16be1b970f3762d6a (diff)
gallium/util: added util_bitcount()
Diffstat (limited to 'src/gallium/auxiliary/util/u_math.h')
-rw-r--r--src/gallium/auxiliary/util/u_math.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 731a11475e..9ed1ab6d8e 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -491,6 +491,26 @@ util_next_power_of_two(unsigned x)
/**
+ * Return number of bits set in n.
+ */
+static INLINE unsigned
+util_bitcount(unsigned n)
+{
+#if defined(PIPE_CC_GCC)
+ return __builtin_popcount(n);
+#else
+ /* XXX there are more clever ways of doing this */
+ unsigned bits = 0;
+ while (n) {
+ bits += (n & 1);
+ n = n >> 1;
+ }
+ return bits;
+#endif
+}
+
+
+/**
* Clamp X to [MIN, MAX].
* This is a macro to allow float, int, uint, etc. types.
*/