mesa: remove array size so the static assert can work
[mesa.git] / src / mesa / main / bitset.h
index 9f48b3cceaba8b13507146d78cfac702353db392..28b3c127e753e3ed6ef3aaa908b4157038c0718a 100644 (file)
 
 /* Get first bit set in a bitset.
  */
-static INLINE int
+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 ffs(x[i]) + BITSET_WORDBITS * i;
    }
 
    return 0;
@@ -129,17 +129,32 @@ __bitset_ffs(const BITSET_WORD *x, int n)
 
 /* bit range operations
  */
-#define BITSET64_TEST_RANGE(x, b, e) \
+#define BITSET64_TEST_SUBRANGE(x, b, e) \
    (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \
    ((x)[BITSET64_BITWORD(b)] & BITSET64_RANGE(b, e)) : \
    (assert (!"BITSET64_TEST_RANGE: bit range crosses word boundary"), 0))
-#define BITSET64_SET_RANGE(x, b, e) \
+#define BITSET64_TEST_RANGE(x, b, e) \
+   (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \
+   (BITSET64_TEST_SUBRANGE(x, b, e)) : \
+   (BITSET64_TEST_SUBRANGE(x, b, BITSET64_WORDBITS - 1) | \
+    BITSET64_TEST_SUBRANGE(x, BITSET64_WORDBITS, e)))
+#define BITSET64_SET_SUBRANGE(x, b, e) \
    (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \
    ((x)[BITSET64_BITWORD(b)] |= BITSET64_RANGE(b, e)) : \
    (assert (!"BITSET64_SET_RANGE: bit range crosses word boundary"), 0))
-#define BITSET64_CLEAR_RANGE(x, b, e) \
+#define BITSET64_SET_RANGE(x, b, e) \
+   (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \
+   (BITSET64_SET_SUBRANGE(x, b, e)) : \
+   (BITSET64_SET_SUBRANGE(x, b, BITSET64_WORDBITS - 1) | \
+    BITSET64_SET_SUBRANGE(x, BITSET64_WORDBITS, e)))
+#define BITSET64_CLEAR_SUBRANGE(x, b, e) \
    (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \
    ((x)[BITSET64_BITWORD(b)] &= ~BITSET64_RANGE(b, e)) : \
    (assert (!"BITSET64_CLEAR_RANGE: bit range crosses word boundary"), 0))
+#define BITSET64_CLEAR_RANGE(x, b, e) \
+   (BITSET64_BITWORD(b) == BITSET64_BITWORD(e) ? \
+   (BITSET64_CLEAR_SUBRANGE(x, b, e)) : \
+   (BITSET64_CLEAR_SUBRANGE(x, b, BITSET64_WORDBITS - 1) | \
+    BITSET64_CLEAR_SUBRANGE(x, BITSET64_WORDBITS, e)))
 
 #endif