Re: [PATCH] lib: bitmap_[empty,full]: remove code duplication

From: Andrew Morton
Date: Tue Mar 24 2015 - 18:53:11 EST


On Mon, 16 Mar 2015 20:56:39 +0300 Yury Norov <yury.norov@xxxxxxxxx> wrote:

> Function 'bitmap_empty' has it's own implementation.
> But it's clearly as simple as:
> "find_first_bit(src, nbits) == nbits"
> The same is true for 'bitmap_full'.
>
> Underscored versions of 'bitmap_[empty,full]' are not
> needed anymore and so removed too.
>
> Boot-tested on Core i7-2630QM.
>
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -285,18 +285,12 @@ static inline int bitmap_subset(const unsigned long *src1,
>
> static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
> {
> - if (small_const_nbits(nbits))
> - return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
> - else
> - return __bitmap_empty(src, nbits);
> + return find_first_bit(src, nbits) == nbits;
> }

But we lost the small_const_nbits() optimization, and that will be a
common case.

Would it be better to do

if (small_const_nbits(...))
...
else
find_first_bit(...);

?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/