static void __init test_for_each_set_bit(void)
{
- unsigned int ui, ui_res = 0;
+ unsigned int ui, ui_res = 0, tmp;
unsigned long ul, ul_res = 0;
uint64_t ull, ull_res = 0;
if ( ull != ull_res )
panic("for_each_set_bit(uint64) expected %#"PRIx64", got %#"PRIx64"\n", ull, ull_res);
+
+ /* Check that we can break from the middle of the loop. */
+ ui = HIDE(0x80001008U);
+ tmp = 0;
+ ui_res = 0;
+ for_each_set_bit ( i, ui )
+ {
+ if ( tmp++ > 1 )
+ break;
+
+ ui_res |= 1U << i;
+ }
+
+ if ( ui_res != 0x1008 )
+ panic("for_each_set_bit(break) expected 0x1008, got %#x\n", ui_res);
}
static void __init test_multiple_bits_set(void)
* A copy of @val is taken internally.
*/
#define for_each_set_bit(iter, val) \
- for ( typeof(val) __v = (val); __v; ) \
+ for ( typeof(val) __v = (val); __v; __v = 0 ) \
for ( unsigned int (iter); \
__v && ((iter) = ffs_g(__v) - 1, true); \
__v &= __v - 1 )