Message ID | 20210121000630.371883-3-yury.norov@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | lib/find_bit: fast path for small bitmaps | expand |
On Wed, Jan 20, 2021 at 04:06:26PM -0800, Yury Norov wrote: > In the following patches of the series they are used by > find_bit subsystem. s/subsystem/API/ ... > --- a/include/linux/bitops.h > +++ b/include/linux/bitops.h > @@ -7,6 +7,17 @@ > > #include <uapi/linux/kernel.h> > > +#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) > +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) Hmm... Naming here is not in the bitops namespace. I would expect BITS rather than BITMAP for these two. So, we have at least the following options: - split to a separate header, like bitmap_macros.h - s/BITMAP/BITS/ and either define BITMAP_* as respective BITS_* or rename it everywhere in bitmap.* - your variant - ...???...
On Thu, Jan 21, 2021 at 2:18 AM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Wed, Jan 20, 2021 at 04:06:26PM -0800, Yury Norov wrote: > > In the following patches of the series they are used by > > find_bit subsystem. > > s/subsystem/API/ > > ... > > > --- a/include/linux/bitops.h > > +++ b/include/linux/bitops.h > > @@ -7,6 +7,17 @@ > > > > #include <uapi/linux/kernel.h> > > > > +#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) > > +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) > > Hmm... Naming here is not in the bitops namespace. > I would expect BITS rather than BITMAP for these two. > > So, we have at least the following options: > - split to a separate header, like bitmap_macros.h > - s/BITMAP/BITS/ and either define BITMAP_* as respective BITS_* or rename it > everywhere in bitmap.* > - your variant > - ...???... We have GENMASK in linux/bits.h. I think we should use it here and drop local ones. It will also cover the case of OFFSET macro that you suggested in your comment to patch #5.
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 70a932470b2d..5bacbc8785eb 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -219,17 +219,6 @@ extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int extern int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits); -#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) -#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) - -/* - * The static inlines below do not handle constant nbits==0 correctly, - * so make such users (should any ever turn up) call the out-of-line - * versions. - */ -#define small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0) - static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); diff --git a/include/linux/bitops.h b/include/linux/bitops.h index a5a48303b0f1..a0e138bbb8ce 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -7,6 +7,17 @@ #include <uapi/linux/kernel.h> +#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) + +/* + * The static inlines below do not handle constant nbits==0 correctly, + * so make such users (should any ever turn up) call the out-of-line + * versions. + */ +#define small_const_nbits(nbits) \ + (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0) + /* Set bits in the first 'n' bytes when loaded from memory */ #ifdef __LITTLE_ENDIAN # define aligned_byte_mask(n) ((1UL << 8*(n))-1)
In the following patches of the series they are used by find_bit subsystem. Signed-off-by: Yury Norov <yury.norov@gmail.com> --- include/linux/bitmap.h | 11 ----------- include/linux/bitops.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-)