diff options
Diffstat (limited to 'include/linux/bitmap.h')
-rw-r--r-- | include/linux/bitmap.h | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index a08c33a26ca9..2878811c6134 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h | |||
@@ -137,9 +137,12 @@ extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); | |||
137 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ | 137 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ |
138 | ) | 138 | ) |
139 | 139 | ||
140 | #define small_const_nbits(nbits) \ | ||
141 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) | ||
142 | |||
140 | static inline void bitmap_zero(unsigned long *dst, int nbits) | 143 | static inline void bitmap_zero(unsigned long *dst, int nbits) |
141 | { | 144 | { |
142 | if (nbits <= BITS_PER_LONG) | 145 | if (small_const_nbits(nbits)) |
143 | *dst = 0UL; | 146 | *dst = 0UL; |
144 | else { | 147 | else { |
145 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); | 148 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
@@ -150,7 +153,7 @@ static inline void bitmap_zero(unsigned long *dst, int nbits) | |||
150 | static inline void bitmap_fill(unsigned long *dst, int nbits) | 153 | static inline void bitmap_fill(unsigned long *dst, int nbits) |
151 | { | 154 | { |
152 | size_t nlongs = BITS_TO_LONGS(nbits); | 155 | size_t nlongs = BITS_TO_LONGS(nbits); |
153 | if (nlongs > 1) { | 156 | if (!small_const_nbits(nbits)) { |
154 | int len = (nlongs - 1) * sizeof(unsigned long); | 157 | int len = (nlongs - 1) * sizeof(unsigned long); |
155 | memset(dst, 0xff, len); | 158 | memset(dst, 0xff, len); |
156 | } | 159 | } |
@@ -160,7 +163,7 @@ static inline void bitmap_fill(unsigned long *dst, int nbits) | |||
160 | static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, | 163 | static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, |
161 | int nbits) | 164 | int nbits) |
162 | { | 165 | { |
163 | if (nbits <= BITS_PER_LONG) | 166 | if (small_const_nbits(nbits)) |
164 | *dst = *src; | 167 | *dst = *src; |
165 | else { | 168 | else { |
166 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); | 169 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
@@ -171,7 +174,7 @@ static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, | |||
171 | static inline void bitmap_and(unsigned long *dst, const unsigned long *src1, | 174 | static inline void bitmap_and(unsigned long *dst, const unsigned long *src1, |
172 | const unsigned long *src2, int nbits) | 175 | const unsigned long *src2, int nbits) |
173 | { | 176 | { |
174 | if (nbits <= BITS_PER_LONG) | 177 | if (small_const_nbits(nbits)) |
175 | *dst = *src1 & *src2; | 178 | *dst = *src1 & *src2; |
176 | else | 179 | else |
177 | __bitmap_and(dst, src1, src2, nbits); | 180 | __bitmap_and(dst, src1, src2, nbits); |
@@ -180,7 +183,7 @@ static inline void bitmap_and(unsigned long *dst, const unsigned long *src1, | |||
180 | static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, | 183 | static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, |
181 | const unsigned long *src2, int nbits) | 184 | const unsigned long *src2, int nbits) |
182 | { | 185 | { |
183 | if (nbits <= BITS_PER_LONG) | 186 | if (small_const_nbits(nbits)) |
184 | *dst = *src1 | *src2; | 187 | *dst = *src1 | *src2; |
185 | else | 188 | else |
186 | __bitmap_or(dst, src1, src2, nbits); | 189 | __bitmap_or(dst, src1, src2, nbits); |
@@ -189,7 +192,7 @@ static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, | |||
189 | static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, | 192 | static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, |
190 | const unsigned long *src2, int nbits) | 193 | const unsigned long *src2, int nbits) |
191 | { | 194 | { |
192 | if (nbits <= BITS_PER_LONG) | 195 | if (small_const_nbits(nbits)) |
193 | *dst = *src1 ^ *src2; | 196 | *dst = *src1 ^ *src2; |
194 | else | 197 | else |
195 | __bitmap_xor(dst, src1, src2, nbits); | 198 | __bitmap_xor(dst, src1, src2, nbits); |
@@ -198,7 +201,7 @@ static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, | |||
198 | static inline void bitmap_andnot(unsigned long *dst, const unsigned long *src1, | 201 | static inline void bitmap_andnot(unsigned long *dst, const unsigned long *src1, |
199 | const unsigned long *src2, int nbits) | 202 | const unsigned long *src2, int nbits) |
200 | { | 203 | { |
201 | if (nbits <= BITS_PER_LONG) | 204 | if (small_const_nbits(nbits)) |
202 | *dst = *src1 & ~(*src2); | 205 | *dst = *src1 & ~(*src2); |
203 | else | 206 | else |
204 | __bitmap_andnot(dst, src1, src2, nbits); | 207 | __bitmap_andnot(dst, src1, src2, nbits); |
@@ -207,7 +210,7 @@ static inline void bitmap_andnot(unsigned long *dst, const unsigned long *src1, | |||
207 | static inline void bitmap_complement(unsigned long *dst, const unsigned long *src, | 210 | static inline void bitmap_complement(unsigned long *dst, const unsigned long *src, |
208 | int nbits) | 211 | int nbits) |
209 | { | 212 | { |
210 | if (nbits <= BITS_PER_LONG) | 213 | if (small_const_nbits(nbits)) |
211 | *dst = ~(*src) & BITMAP_LAST_WORD_MASK(nbits); | 214 | *dst = ~(*src) & BITMAP_LAST_WORD_MASK(nbits); |
212 | else | 215 | else |
213 | __bitmap_complement(dst, src, nbits); | 216 | __bitmap_complement(dst, src, nbits); |
@@ -216,7 +219,7 @@ static inline void bitmap_complement(unsigned long *dst, const unsigned long *sr | |||
216 | static inline int bitmap_equal(const unsigned long *src1, | 219 | static inline int bitmap_equal(const unsigned long *src1, |
217 | const unsigned long *src2, int nbits) | 220 | const unsigned long *src2, int nbits) |
218 | { | 221 | { |
219 | if (nbits <= BITS_PER_LONG) | 222 | if (small_const_nbits(nbits)) |
220 | return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); | 223 | return ! ((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); |
221 | else | 224 | else |
222 | return __bitmap_equal(src1, src2, nbits); | 225 | return __bitmap_equal(src1, src2, nbits); |
@@ -225,7 +228,7 @@ static inline int bitmap_equal(const unsigned long *src1, | |||
225 | static inline int bitmap_intersects(const unsigned long *src1, | 228 | static inline int bitmap_intersects(const unsigned long *src1, |
226 | const unsigned long *src2, int nbits) | 229 | const unsigned long *src2, int nbits) |
227 | { | 230 | { |
228 | if (nbits <= BITS_PER_LONG) | 231 | if (small_const_nbits(nbits)) |
229 | return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; | 232 | return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; |
230 | else | 233 | else |
231 | return __bitmap_intersects(src1, src2, nbits); | 234 | return __bitmap_intersects(src1, src2, nbits); |
@@ -234,7 +237,7 @@ static inline int bitmap_intersects(const unsigned long *src1, | |||
234 | static inline int bitmap_subset(const unsigned long *src1, | 237 | static inline int bitmap_subset(const unsigned long *src1, |
235 | const unsigned long *src2, int nbits) | 238 | const unsigned long *src2, int nbits) |
236 | { | 239 | { |
237 | if (nbits <= BITS_PER_LONG) | 240 | if (small_const_nbits(nbits)) |
238 | return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits)); | 241 | return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits)); |
239 | else | 242 | else |
240 | return __bitmap_subset(src1, src2, nbits); | 243 | return __bitmap_subset(src1, src2, nbits); |
@@ -242,7 +245,7 @@ static inline int bitmap_subset(const unsigned long *src1, | |||
242 | 245 | ||
243 | static inline int bitmap_empty(const unsigned long *src, int nbits) | 246 | static inline int bitmap_empty(const unsigned long *src, int nbits) |
244 | { | 247 | { |
245 | if (nbits <= BITS_PER_LONG) | 248 | if (small_const_nbits(nbits)) |
246 | return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); | 249 | return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); |
247 | else | 250 | else |
248 | return __bitmap_empty(src, nbits); | 251 | return __bitmap_empty(src, nbits); |
@@ -250,7 +253,7 @@ static inline int bitmap_empty(const unsigned long *src, int nbits) | |||
250 | 253 | ||
251 | static inline int bitmap_full(const unsigned long *src, int nbits) | 254 | static inline int bitmap_full(const unsigned long *src, int nbits) |
252 | { | 255 | { |
253 | if (nbits <= BITS_PER_LONG) | 256 | if (small_const_nbits(nbits)) |
254 | return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); | 257 | return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); |
255 | else | 258 | else |
256 | return __bitmap_full(src, nbits); | 259 | return __bitmap_full(src, nbits); |
@@ -258,7 +261,7 @@ static inline int bitmap_full(const unsigned long *src, int nbits) | |||
258 | 261 | ||
259 | static inline int bitmap_weight(const unsigned long *src, int nbits) | 262 | static inline int bitmap_weight(const unsigned long *src, int nbits) |
260 | { | 263 | { |
261 | if (nbits <= BITS_PER_LONG) | 264 | if (small_const_nbits(nbits)) |
262 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); | 265 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); |
263 | return __bitmap_weight(src, nbits); | 266 | return __bitmap_weight(src, nbits); |
264 | } | 267 | } |
@@ -266,7 +269,7 @@ static inline int bitmap_weight(const unsigned long *src, int nbits) | |||
266 | static inline void bitmap_shift_right(unsigned long *dst, | 269 | static inline void bitmap_shift_right(unsigned long *dst, |
267 | const unsigned long *src, int n, int nbits) | 270 | const unsigned long *src, int n, int nbits) |
268 | { | 271 | { |
269 | if (nbits <= BITS_PER_LONG) | 272 | if (small_const_nbits(nbits)) |
270 | *dst = *src >> n; | 273 | *dst = *src >> n; |
271 | else | 274 | else |
272 | __bitmap_shift_right(dst, src, n, nbits); | 275 | __bitmap_shift_right(dst, src, n, nbits); |
@@ -275,7 +278,7 @@ static inline void bitmap_shift_right(unsigned long *dst, | |||
275 | static inline void bitmap_shift_left(unsigned long *dst, | 278 | static inline void bitmap_shift_left(unsigned long *dst, |
276 | const unsigned long *src, int n, int nbits) | 279 | const unsigned long *src, int n, int nbits) |
277 | { | 280 | { |
278 | if (nbits <= BITS_PER_LONG) | 281 | if (small_const_nbits(nbits)) |
279 | *dst = (*src << n) & BITMAP_LAST_WORD_MASK(nbits); | 282 | *dst = (*src << n) & BITMAP_LAST_WORD_MASK(nbits); |
280 | else | 283 | else |
281 | __bitmap_shift_left(dst, src, n, nbits); | 284 | __bitmap_shift_left(dst, src, n, nbits); |