Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/bitset.h
Show First 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | #define BIT_COUNT(_s, p) __extension__ ({ \ | ||||
long __count; \ | long __count; \ | ||||
\ | \ | ||||
__count = 0; \ | __count = 0; \ | ||||
for (__i = 0; __i < __bitset_words((_s)); __i++) \ | for (__i = 0; __i < __bitset_words((_s)); __i++) \ | ||||
__count += __bitcountl((p)->__bits[__i]); \ | __count += __bitcountl((p)->__bits[__i]); \ | ||||
__count; \ | __count; \ | ||||
}) | }) | ||||
/* Non-destructively loop over all set or clear bits in the set. */ | #define _BIT_FOREACH_ADVANCE(_s, i, p, op) __extension__ ({ \ | ||||
int __found; \ | |||||
for (;;) { \ | |||||
if (__bits != 0) { \ | |||||
int __bit = ffsl(__bits) - 1; \ | |||||
__bits &= ~(1ul << __bit); \ | |||||
(i) = __i * _BITSET_BITS + __bit; \ | |||||
rlibby: `i` is passed through from the caller, don't we want it parenthesized? Or do we make an… | |||||
Done Inline ActionsI couldn't imagine a scenario where parens were needed to give correct behaviour here. But it is probably better to be consistent. markj: I couldn't imagine a scenario where parens were needed to give correct behaviour here. But it… | |||||
__found = 1; \ | |||||
break; \ | |||||
} \ | |||||
if (++__i == __bitset_words(_s)) { \ | |||||
__found = 0; \ | |||||
break; \ | |||||
} \ | |||||
__bits = op((p)->__bits[__i]); \ | |||||
} \ | |||||
__found != 0; \ | |||||
}) | |||||
/* | |||||
* Non-destructively loop over all set or clear bits in the set. | |||||
*/ | |||||
#define _BIT_FOREACH(_s, i, p, op) \ | #define _BIT_FOREACH(_s, i, p, op) \ | ||||
for (__size_t __i = 0; __i < __bitset_words(_s); __i++) \ | for (long __i = -1, __bits = 0; \ | ||||
for (long __j = op((p)->__bits[__i]), __b = ffsl(__j); \ | _BIT_FOREACH_ADVANCE(_s, i, p, op); ) | ||||
(i = (__b - 1) + __i * _BITSET_BITS), __j != 0; \ | |||||
__j &= ~(1l << i), __b = ffsl(__j)) | |||||
#define BIT_FOREACH_ISSET(_s, i, p) _BIT_FOREACH(_s, i, p, ) | #define BIT_FOREACH_ISSET(_s, i, p) _BIT_FOREACH(_s, i, p, ) | ||||
#define BIT_FOREACH_ISCLR(_s, i, p) _BIT_FOREACH(_s, i, p, ~) | #define BIT_FOREACH_ISCLR(_s, i, p) _BIT_FOREACH(_s, i, p, ~) | ||||
#define BITSET_T_INITIALIZER(x) \ | #define BITSET_T_INITIALIZER(x) \ | ||||
{ .__bits = { x } } | { .__bits = { x } } | ||||
#define BITSET_FSET(n) \ | #define BITSET_FSET(n) \ | ||||
Show All 10 Lines |
i is passed through from the caller, don't we want it parenthesized? Or do we make an exception next to an assignment operator, since there isn't really a sensible lower precedence operator that might be used in i?