mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / main / bitset.h
index f2709abc9fd06cc5e1328cb5c6b7e089ea6efe4b..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.
  */
 
 /* 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
  */
-#define BITSET_COPY(x, y) _mesa_memcpy( (x), (y), sizeof (x) )
-#define BITSET_EQUAL(x, y) (_mesa_memcmp( (x), (y), sizeof (x) ) == 0)
-#define BITSET_ZERO(x) _mesa_memset( (x), 0, sizeof (x) )
-#define BITSET_ONES(x) _mesa_memset( (x), 0xff, sizeof (x) )
+#define BITSET_COPY(x, y) memcpy( (x), (y), sizeof (x) )
+#define BITSET_EQUAL(x, y) (memcmp( (x), (y), sizeof (x) ) == 0)
+#define BITSET_ZERO(x) memset( (x), 0, sizeof (x) )
+#define BITSET_ONES(x) memset( (x), 0xff, sizeof (x) )
 
 #define BITSET_BITWORD(b) ((b) / BITSET_WORDBITS)
 #define BITSET_BIT(b) (1 << ((b) % BITSET_WORDBITS))
 
 /* 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