Re: [PATCH] Bitmap: Optimized division operation to shift operation

From: Peter Zijlstra
Date: Wed Apr 15 2020 - 04:57:27 EST


On Wed, Apr 15, 2020 at 03:27:40PM +0800, Wang Qing wrote:
> On some processors, the / operate will call the compiler`s div lib,
> which is low efficient. Bitmap is performance sensitive, We can
> replace the / operation with shift.
>
> Signed-off-by: Wang Qing <wangqing@xxxxxxxx>
> ---
> include/linux/bitmap.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> index 99058eb..85ff982 100644
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -337,7 +337,7 @@ static inline int bitmap_equal(const unsigned long *src1,
> return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
> if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) &&
> IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT))
> - return !memcmp(src1, src2, nbits / 8);
> + return !memcmp(src1, src2, nbits >> 3);
> return __bitmap_equal(src1, src2, nbits);
> }

If your compiler gets this wrong, set it on fire and scatter its remains.