On 25.06.2024 21:07, Andrew Cooper wrote: > --- a/xen/include/xen/bitops.h > +++ b/xen/include/xen/bitops.h > @@ -56,6 +56,16 @@ static always_inline __pure unsigned int ffs64(uint64_t x) > return !x || (uint32_t)x ? ffs(x) : ffs(x >> 32) + 32; > } > > +/* > + * A type-generic ffs() which picks the appropriate ffs{,l,64}() based on > it's > + * argument. > + */ > +#define ffs_g(x) \ > + sizeof(x) <= sizeof(int) ? ffs(x) : \ > + sizeof(x) <= sizeof(long) ? ffsl(x) : \ > + sizeof(x) <= sizeof(uint64_t) ? ffs64(x) : \ > + ({ BUILD_ERROR("ffs_g() Bad input type"); 0; })
I guess the lack of parentheses around the entire construct might be the reason for the problems you're seeing, as that ... > @@ -92,6 +102,20 @@ static always_inline __pure unsigned int fls64(uint64_t x) > } > } > > +/* > + * for_each_set_bit() - Iterate over all set bits in a scalar value. > + * > + * @iter An iterator name. Scoped is within the loop only. > + * @val A scalar value to iterate over. > + * > + * A copy of @val is taken internally. > + */ > +#define for_each_set_bit(iter, val) \ > + for ( typeof(val) __v = (val); __v; ) \ > + for ( unsigned int (iter); \ > + __v && ((iter) = ffs_g(__v) - 1, true); \ ... affects what effect the "- 1" here has. Jan