Mesa (master): mesa: Add a BITSET_FFS function.

Brian Paul brianp at kemper.freedesktop.org
Tue Feb 2 16:01:45 UTC 2010


Module: Mesa
Branch: master
Commit: 88593fff492e345b28720067ce0aadb988e86a28
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=88593fff492e345b28720067ce0aadb988e86a28

Author: Francisco Jerez <currojerez at riseup.net>
Date:   Tue Feb  2 03:07:08 2010 -0800

mesa: Add a BITSET_FFS function.

It will be useful for the nouveau DRI driver and IMHO there's no
reason to keep it private.

Signed-off-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/main/bitset.h |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/src/mesa/main/bitset.h b/src/mesa/main/bitset.h
index 8bd4526..f2709ab 100644
--- a/src/mesa/main/bitset.h
+++ b/src/mesa/main/bitset.h
@@ -27,7 +27,12 @@
  * \brief Bitset of arbitrary size definitions.
  * \author Michal Krol
  */
- 
+
+#ifndef BITSET_H
+#define BITSET_H
+
+#include "imports.h"
+
 /****************************************************************************
  * generic bitset implementation
  */
@@ -74,6 +79,23 @@
    ((x)[BITSET_BITWORD(b)] &= ~BITSET_RANGE(b, e)) : \
    (assert (!"BITSET_CLEAR_RANGE: bit range crosses word boundary"), 0))
 
+/* Get first bit set in a bitset.
+ */
+static INLINE int
+__bitset_ffs(const BITSET_WORD *x, int n)
+{
+   int i;
+
+   for (i = 0; i < n; i++) {
+      if (x[i])
+	 return _mesa_ffs(x[i]) + BITSET_WORDBITS * i;
+   }
+
+   return 0;
+}
+
+#define BITSET_FFS(x) __bitset_ffs(x, Elements(x))
+
 /****************************************************************************
  * 64-bit bitset implementation
  */
@@ -120,3 +142,4 @@
    ((x)[BITSET64_BITWORD(b)] &= ~BITSET64_RANGE(b, e)) : \
    (assert (!"BITSET64_CLEAR_RANGE: bit range crosses word boundary"), 0))
 
+#endif




More information about the mesa-commit mailing list