2 * MSB0 numbered special bitops handling.
4 * The bits are numbered:
5 * |0..............63|64............127|128...........191|192...........255|
7 * The reason for this bit numbering is the fact that the hardware sets bits
8 * in a bitmap starting at bit 0 (MSB) and we don't want to scan the bitmap
9 * from the 'wrong end'.
12 #include <linux/compiler.h>
13 #include <linux/bitops.h>
14 #include <linux/export.h>
16 unsigned long find_first_bit_inv(const unsigned long *addr, unsigned long size)
18 const unsigned long *p = addr;
19 unsigned long result = 0;
22 while (size & ~(BITS_PER_LONG - 1)) {
25 result += BITS_PER_LONG;
26 size -= BITS_PER_LONG;
30 tmp = (*p) & (~0UL << (BITS_PER_LONG - size));
31 if (!tmp) /* Are any bits set? */
32 return result + size; /* Nope. */
34 return result + (__fls(tmp) ^ (BITS_PER_LONG - 1));
36 EXPORT_SYMBOL(find_first_bit_inv);
38 unsigned long find_next_bit_inv(const unsigned long *addr, unsigned long size,
41 const unsigned long *p = addr + (offset / BITS_PER_LONG);
42 unsigned long result = offset & ~(BITS_PER_LONG - 1);
48 offset %= BITS_PER_LONG;
51 tmp &= (~0UL >> offset);
52 if (size < BITS_PER_LONG)
56 size -= BITS_PER_LONG;
57 result += BITS_PER_LONG;
59 while (size & ~(BITS_PER_LONG-1)) {
62 result += BITS_PER_LONG;
63 size -= BITS_PER_LONG;
69 tmp &= (~0UL << (BITS_PER_LONG - size));
70 if (!tmp) /* Are any bits set? */
71 return result + size; /* Nope. */
73 return result + (__fls(tmp) ^ (BITS_PER_LONG - 1));
75 EXPORT_SYMBOL(find_next_bit_inv);