diff options
Diffstat (limited to 'lib/find_next_bit.c')
| -rw-r--r-- | lib/find_next_bit.c | 77 |
1 files changed, 65 insertions, 12 deletions
diff --git a/lib/find_next_bit.c b/lib/find_next_bit.c index 78ccd73a8841..d3f5784807b4 100644 --- a/lib/find_next_bit.c +++ b/lib/find_next_bit.c | |||
| @@ -16,14 +16,12 @@ | |||
| 16 | 16 | ||
| 17 | #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) | 17 | #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) |
| 18 | 18 | ||
| 19 | /** | 19 | #ifdef CONFIG_GENERIC_FIND_NEXT_BIT |
| 20 | * find_next_bit - find the next set bit in a memory region | 20 | /* |
| 21 | * @addr: The address to base the search on | 21 | * Find the next set bit in a memory region. |
| 22 | * @offset: The bitnumber to start searching at | ||
| 23 | * @size: The maximum size to search | ||
| 24 | */ | 22 | */ |
| 25 | unsigned long find_next_bit(const unsigned long *addr, unsigned long size, | 23 | unsigned long __find_next_bit(const unsigned long *addr, |
| 26 | unsigned long offset) | 24 | unsigned long size, unsigned long offset) |
| 27 | { | 25 | { |
| 28 | const unsigned long *p = addr + BITOP_WORD(offset); | 26 | const unsigned long *p = addr + BITOP_WORD(offset); |
| 29 | unsigned long result = offset & ~(BITS_PER_LONG-1); | 27 | unsigned long result = offset & ~(BITS_PER_LONG-1); |
| @@ -60,15 +58,14 @@ found_first: | |||
| 60 | found_middle: | 58 | found_middle: |
| 61 | return result + __ffs(tmp); | 59 | return result + __ffs(tmp); |
| 62 | } | 60 | } |
| 63 | 61 | EXPORT_SYMBOL(__find_next_bit); | |
| 64 | EXPORT_SYMBOL(find_next_bit); | ||
| 65 | 62 | ||
| 66 | /* | 63 | /* |
| 67 | * This implementation of find_{first,next}_zero_bit was stolen from | 64 | * This implementation of find_{first,next}_zero_bit was stolen from |
| 68 | * Linus' asm-alpha/bitops.h. | 65 | * Linus' asm-alpha/bitops.h. |
| 69 | */ | 66 | */ |
| 70 | unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, | 67 | unsigned long __find_next_zero_bit(const unsigned long *addr, |
| 71 | unsigned long offset) | 68 | unsigned long size, unsigned long offset) |
| 72 | { | 69 | { |
| 73 | const unsigned long *p = addr + BITOP_WORD(offset); | 70 | const unsigned long *p = addr + BITOP_WORD(offset); |
| 74 | unsigned long result = offset & ~(BITS_PER_LONG-1); | 71 | unsigned long result = offset & ~(BITS_PER_LONG-1); |
| @@ -105,8 +102,64 @@ found_first: | |||
| 105 | found_middle: | 102 | found_middle: |
| 106 | return result + ffz(tmp); | 103 | return result + ffz(tmp); |
| 107 | } | 104 | } |
| 105 | EXPORT_SYMBOL(__find_next_zero_bit); | ||
| 106 | #endif /* CONFIG_GENERIC_FIND_NEXT_BIT */ | ||
| 107 | |||
| 108 | #ifdef CONFIG_GENERIC_FIND_FIRST_BIT | ||
| 109 | /* | ||
| 110 | * Find the first set bit in a memory region. | ||
| 111 | */ | ||
| 112 | unsigned long __find_first_bit(const unsigned long *addr, | ||
| 113 | unsigned long size) | ||
| 114 | { | ||
| 115 | const unsigned long *p = addr; | ||
| 116 | unsigned long result = 0; | ||
| 117 | unsigned long tmp; | ||
| 108 | 118 | ||
| 109 | EXPORT_SYMBOL(find_next_zero_bit); | 119 | while (size & ~(BITS_PER_LONG-1)) { |
| 120 | if ((tmp = *(p++))) | ||
| 121 | goto found; | ||
| 122 | result += BITS_PER_LONG; | ||
| 123 | size -= BITS_PER_LONG; | ||
| 124 | } | ||
| 125 | if (!size) | ||
| 126 | return result; | ||
| 127 | |||
| 128 | tmp = (*p) & (~0UL >> (BITS_PER_LONG - size)); | ||
| 129 | if (tmp == 0UL) /* Are any bits set? */ | ||
| 130 | return result + size; /* Nope. */ | ||
| 131 | found: | ||
| 132 | return result + __ffs(tmp); | ||
| 133 | } | ||
| 134 | EXPORT_SYMBOL(__find_first_bit); | ||
| 135 | |||
| 136 | /* | ||
| 137 | * Find the first cleared bit in a memory region. | ||
| 138 | */ | ||
| 139 | unsigned long __find_first_zero_bit(const unsigned long *addr, | ||
| 140 | unsigned long size) | ||
| 141 | { | ||
| 142 | const unsigned long *p = addr; | ||
| 143 | unsigned long result = 0; | ||
| 144 | unsigned long tmp; | ||
| 145 | |||
| 146 | while (size & ~(BITS_PER_LONG-1)) { | ||
| 147 | if (~(tmp = *(p++))) | ||
| 148 | goto found; | ||
| 149 | result += BITS_PER_LONG; | ||
| 150 | size -= BITS_PER_LONG; | ||
| 151 | } | ||
| 152 | if (!size) | ||
| 153 | return result; | ||
| 154 | |||
| 155 | tmp = (*p) | (~0UL << size); | ||
| 156 | if (tmp == ~0UL) /* Are any bits zero? */ | ||
| 157 | return result + size; /* Nope. */ | ||
| 158 | found: | ||
| 159 | return result + ffz(tmp); | ||
| 160 | } | ||
| 161 | EXPORT_SYMBOL(__find_first_zero_bit); | ||
| 162 | #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ | ||
| 110 | 163 | ||
| 111 | #ifdef __BIG_ENDIAN | 164 | #ifdef __BIG_ENDIAN |
| 112 | 165 | ||
