Skip to content

Commit b856148

Browse files
YuryNorovnotcarbide
authored andcommitted
lib: extend the scope of small_const_nbits() macro
find_bit would also benefit from small_const_nbits() optimizations. The detailed comment is provided by Rasmus Villemoes. Link: https://lkml.kernel.org/r/[email protected] Suggested-by: Rasmus Villemoes <[email protected]> Signed-off-by: Yury Norov <[email protected]> Acked-by: Rasmus Villemoes <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Cc: Alexey Klimov <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: David Sterba <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Jianpeng Ma <[email protected]> Cc: Joe Perches <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Rich Felker <[email protected]> Cc: Stefano Brivio <[email protected]> Cc: Wei Yang <[email protected]> Cc: Wolfram Sang <[email protected]> Cc: Yoshinori Sato <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Stephen Rothwell <[email protected]>
1 parent 0f6dfb0 commit b856148

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

include/asm-generic/bitsperlong.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@
2323
#define BITS_PER_LONG_LONG 64
2424
#endif
2525

26+
/*
27+
* small_const_nbits(n) is true precisely when it is known at compile-time
28+
* that BITMAP_SIZE(n) is 1, i.e. 1 <= n <= BITS_PER_LONG. This allows
29+
* various bit/bitmap APIs to provide a fast inline implementation. Bitmaps
30+
* of size 0 are very rare, and a compile-time-known-size 0 is most likely
31+
* a sign of error. They will be handled correctly by the bit/bitmap APIs,
32+
* but using the out-of-line functions, so that the inline implementations
33+
* can unconditionally dereference the pointer(s).
34+
*/
35+
#define small_const_nbits(nbits) \
36+
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0)
37+
2638
#endif /* __ASM_GENERIC_BITS_PER_LONG */

include/linux/bitmap.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,6 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf,
224224
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
225225
#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
226226

227-
/*
228-
* The static inlines below do not handle constant nbits==0 correctly,
229-
* so make such users (should any ever turn up) call the out-of-line
230-
* versions.
231-
*/
232-
#define small_const_nbits(nbits) \
233-
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0)
234-
235227
static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
236228
{
237229
unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);

0 commit comments

Comments
 (0)