mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / main / bitset.h
index 9f48b3cceaba8b13507146d78cfac702353db392..df5b632325a17cf09800801109f5730efed2543b 100644 (file)
@@ -17,7 +17,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
@@ -42,8 +42,8 @@
 
 /* bitset declarations
  */
-#define BITSET_DECLARE(name, size) \
-   BITSET_WORD name[((size) + BITSET_WORDBITS - 1) / BITSET_WORDBITS]
+#define BITSET_WORDS(bits) (ALIGN(bits, BITSET_WORDBITS) / BITSET_WORDBITS)
+#define BITSET_DECLARE(name, bits) BITSET_WORD name[BITSET_WORDS(bits)]
 
 /* bitset operations
  */
 
 /* 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