diff options
| -rw-r--r-- | include/linux/bitmap.h | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 5f11fbdc27f8..1ee46f492267 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h | |||
| @@ -302,12 +302,20 @@ static inline void bitmap_complement(unsigned long *dst, const unsigned long *sr | |||
| 302 | __bitmap_complement(dst, src, nbits); | 302 | __bitmap_complement(dst, src, nbits); |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | #ifdef __LITTLE_ENDIAN | ||
| 306 | #define BITMAP_MEM_ALIGNMENT 8 | ||
| 307 | #else | ||
| 308 | #define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long)) | ||
| 309 | #endif | ||
| 310 | #define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) | ||
| 311 | |||
| 305 | static inline int bitmap_equal(const unsigned long *src1, | 312 | static inline int bitmap_equal(const unsigned long *src1, |
| 306 | const unsigned long *src2, unsigned int nbits) | 313 | const unsigned long *src2, unsigned int nbits) |
| 307 | { | 314 | { |
| 308 | if (small_const_nbits(nbits)) | 315 | if (small_const_nbits(nbits)) |
| 309 | return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); | 316 | return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); |
| 310 | if (__builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8)) | 317 | if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && |
| 318 | IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) | ||
| 311 | return !memcmp(src1, src2, nbits / 8); | 319 | return !memcmp(src1, src2, nbits / 8); |
| 312 | return __bitmap_equal(src1, src2, nbits); | 320 | return __bitmap_equal(src1, src2, nbits); |
| 313 | } | 321 | } |
| @@ -358,8 +366,10 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start, | |||
| 358 | { | 366 | { |
| 359 | if (__builtin_constant_p(nbits) && nbits == 1) | 367 | if (__builtin_constant_p(nbits) && nbits == 1) |
| 360 | __set_bit(start, map); | 368 | __set_bit(start, map); |
| 361 | else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) && | 369 | else if (__builtin_constant_p(start & BITMAP_MEM_MASK) && |
| 362 | __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8)) | 370 | IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) && |
| 371 | __builtin_constant_p(nbits & BITMAP_MEM_MASK) && | ||
| 372 | IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) | ||
| 363 | memset((char *)map + start / 8, 0xff, nbits / 8); | 373 | memset((char *)map + start / 8, 0xff, nbits / 8); |
| 364 | else | 374 | else |
| 365 | __bitmap_set(map, start, nbits); | 375 | __bitmap_set(map, start, nbits); |
| @@ -370,8 +380,10 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start, | |||
| 370 | { | 380 | { |
| 371 | if (__builtin_constant_p(nbits) && nbits == 1) | 381 | if (__builtin_constant_p(nbits) && nbits == 1) |
| 372 | __clear_bit(start, map); | 382 | __clear_bit(start, map); |
| 373 | else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) && | 383 | else if (__builtin_constant_p(start & BITMAP_MEM_MASK) && |
| 374 | __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8)) | 384 | IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) && |
| 385 | __builtin_constant_p(nbits & BITMAP_MEM_MASK) && | ||
| 386 | IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) | ||
| 375 | memset((char *)map + start / 8, 0, nbits / 8); | 387 | memset((char *)map + start / 8, 0, nbits / 8); |
| 376 | else | 388 | else |
| 377 | __bitmap_clear(map, start, nbits); | 389 | __bitmap_clear(map, start, nbits); |
