* 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
*/
/* 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;
/* 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