Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/bitset.h
Show First 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | if ((p)->__bits[__i] != 0) { \ | ||||
__bit = ffsl((p)->__bits[__i]); \ | __bit = ffsl((p)->__bits[__i]); \ | ||||
__bit += __i * _BITSET_BITS; \ | __bit += __i * _BITSET_BITS; \ | ||||
break; \ | break; \ | ||||
} \ | } \ | ||||
} \ | } \ | ||||
__bit; \ | __bit; \ | ||||
}) | }) | ||||
#define BIT_FFS_AT(_s, p, start) __extension__ ({ \ | |||||
kib: Don' you need to write this as `BIT_FFS_AT((_s), (p), 0)` ? | |||||
Done Inline ActionsI don't believe anything could go wrong without it, but I've added it for consistency with the surrounding code. scottph: I don't believe anything could go wrong without it, but I've added it for consistency with the… | |||||
__size_t __i; \ | |||||
int __bit; \ | |||||
long __test; \ | |||||
\ | |||||
__bit = 0; \ | |||||
__i = __bitset_word(_s, start); \ | |||||
if (__i < __bitset_words((_s))) { \ | |||||
__test = (p)->__bits[__i] & \ | |||||
(~0UL << ((start) % _BITSET_BITS)); \ | |||||
while (__test == 0 && ++__i < __bitset_words((_s))) \ | |||||
__test = (p)->__bits[__i]; \ | |||||
if (__i < __bitset_words((_s))) \ | |||||
__bit = ffsl(__test) + __i * _BITSET_BITS; \ | |||||
} \ | |||||
__bit; \ | |||||
}) | |||||
kibUnsubmitted Not Done Inline ActionsWhy not implement this same as BIT_FFS, but start the loop not from __i = 0, but from __i = __bitset_word(s, start) ? Then BIT_FFS() can be redefined as BIT_FFS_AT(s, p, 0). Of course, all this assuming my note about 'greater or equal' being true. kib: Why not implement this same as BIT_FFS, but start the loop not from `__i = 0`, but from `__i =… | |||||
scottphAuthorUnsubmitted Done Inline ActionsThe old version was a sort-of transliteration of bitstring's bit_ffs_at, and then I had not redefined BIT_FFS() in terms of BIT_FFS_AT() because it seemed to be generating assembly for the mask even in the 0 start case. This version doesn't seem to have that problem so I've redefined BIT_FFS here. scottph: The old version was a sort-of transliteration of bitstring's bit_ffs_at, and then I had not… | |||||
#define BIT_FLS(_s, p) __extension__ ({ \ | #define BIT_FLS(_s, p) __extension__ ({ \ | ||||
__size_t __i; \ | __size_t __i; \ | ||||
int __bit; \ | int __bit; \ | ||||
\ | \ | ||||
__bit = 0; \ | __bit = 0; \ | ||||
for (__i = __bitset_words((_s)); __i > 0; __i--) { \ | for (__i = __bitset_words((_s)); __i > 0; __i--) { \ | ||||
if ((p)->__bits[__i - 1] != 0) { \ | if ((p)->__bits[__i - 1] != 0) { \ | ||||
__bit = flsl((p)->__bits[__i - 1]); \ | __bit = flsl((p)->__bits[__i - 1]); \ | ||||
Show All 31 Lines |
Don' you need to write this as BIT_FFS_AT((_s), (p), 0) ?