projects
/
mesa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
5173d14
)
gallium/util: added util_bitcount()
author
Brian Paul
<brianp@vmware.com>
Tue, 24 Nov 2009 01:04:22 +0000
(18:04 -0700)
committer
Brian Paul
<brianp@vmware.com>
Tue, 24 Nov 2009 01:04:22 +0000
(18:04 -0700)
src/gallium/auxiliary/util/u_math.h
patch
|
blob
|
history
diff --git
a/src/gallium/auxiliary/util/u_math.h
b/src/gallium/auxiliary/util/u_math.h
index 731a11475ecbd4848f0c49d734416bfae5d23a87..9ed1ab6d8eef8464069f9d28675b7ba116dfb06d 100644
(file)
--- a/
src/gallium/auxiliary/util/u_math.h
+++ b/
src/gallium/auxiliary/util/u_math.h
@@
-490,6
+490,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.