2 * MSB0 numbered special bitops handling.
4 * On s390x the bits are numbered:
5 * |0..............63|64............127|128...........191|192...........255|
7 * |0.....31|32....63|64....95|96...127|128..159|160..191|192..223|224..255|
9 * The reason for this bit numbering is the fact that the hardware sets bits
10 * in a bitmap starting at bit 0 (MSB) and we don't want to scan the bitmap
11 * from the 'wrong end'.
14 #include <linux/compiler.h>
15 #include <linux/bitops.h>
16 #include <linux/export.h>
18 unsigned long find_first_bit_inv(const unsigned long *addr
, unsigned long size
)
20 const unsigned long *p
= addr
;
21 unsigned long result
= 0;
24 while (size
& ~(BITS_PER_LONG
- 1)) {
27 result
+= BITS_PER_LONG
;
28 size
-= BITS_PER_LONG
;
32 tmp
= (*p
) & (~0UL << (BITS_PER_LONG
- size
));
33 if (!tmp
) /* Are any bits set? */
34 return result
+ size
; /* Nope. */
36 return result
+ (__fls(tmp
) ^ (BITS_PER_LONG
- 1));
38 EXPORT_SYMBOL(find_first_bit_inv
);
40 unsigned long find_next_bit_inv(const unsigned long *addr
, unsigned long size
,
43 const unsigned long *p
= addr
+ (offset
/ BITS_PER_LONG
);
44 unsigned long result
= offset
& ~(BITS_PER_LONG
- 1);
50 offset
%= BITS_PER_LONG
;
53 tmp
&= (~0UL >> offset
);
54 if (size
< BITS_PER_LONG
)
58 size
-= BITS_PER_LONG
;
59 result
+= BITS_PER_LONG
;
61 while (size
& ~(BITS_PER_LONG
-1)) {
64 result
+= BITS_PER_LONG
;
65 size
-= BITS_PER_LONG
;
71 tmp
&= (~0UL << (BITS_PER_LONG
- size
));
72 if (!tmp
) /* Are any bits set? */
73 return result
+ size
; /* Nope. */
75 return result
+ (__fls(tmp
) ^ (BITS_PER_LONG
- 1));
77 EXPORT_SYMBOL(find_next_bit_inv
);