Re: [PATCH 3/6] bitops: define gen_test_bit() the same way as the rest of functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Alexander Lobakin <alexandr.lobakin@xxxxxxxxx>
- Subject: Re: [PATCH 3/6] bitops: define gen_test_bit() the same way as the rest of functions
- From: Mark Rutland <mark.rutland@xxxxxxx>
- Date: Mon, 6 Jun 2022 17:19:42 +0100
- Cc: Arnd Bergmann <arnd@xxxxxxxx>, Yury Norov <yury.norov@xxxxxxxxx>, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>, Richard Henderson <rth@xxxxxxxxxxxxxxx>, Matt Turner <mattst88@xxxxxxxxx>, Brian Cain <bcain@xxxxxxxxxxx>, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxxxxx>, Kees Cook <keescook@xxxxxxxxxxxx>, "Peter Zijlstra (Intel)" <peterz@xxxxxxxxxxxxx>, Marco Elver <elver@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxx>, Tony Luck <tony.luck@xxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, linux-alpha@xxxxxxxxxxxxxxx, linux-hexagon@xxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-m68k@xxxxxxxxxxxxxxx, linux-sh@xxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, linux-arch@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
- In-reply-to: <20220606114908.962562-4-alexandr.lobakin@intel.com>
- References: <20220606114908.962562-1-alexandr.lobakin@intel.com> <20220606114908.962562-4-alexandr.lobakin@intel.com>
On Mon, Jun 06, 2022 at 01:49:04PM +0200, Alexander Lobakin wrote:
> Currently, the generic test_bit() function is defined as a one-liner
> and in case with constant bitmaps the compiler is unable to optimize
> it to a constant. At the same time, gen_test_and_*_bit() are being
> optimized pretty good.
> Define gen_test_bit() the same way as they are defined.
>
> Signed-off-by: Alexander Lobakin <alexandr.lobakin@xxxxxxxxx>
Regardless of whether compilers prefer this, I think it's nicer to have the
structure consistent with the rest of the functions, so FWIW:
Acked-by: Mark Rutland <mark.rutland@xxxxxxx>
Mark.
> ---
> include/asm-generic/bitops/generic-non-atomic.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/include/asm-generic/bitops/generic-non-atomic.h b/include/asm-generic/bitops/generic-non-atomic.h
> index 7a60adfa6e7d..202d8a3b40e1 100644
> --- a/include/asm-generic/bitops/generic-non-atomic.h
> +++ b/include/asm-generic/bitops/generic-non-atomic.h
> @@ -118,7 +118,11 @@ gen___test_and_change_bit(unsigned int nr, volatile unsigned long *addr)
> static __always_inline int
> gen_test_bit(unsigned int nr, const volatile unsigned long *addr)
> {
> - return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
> + const unsigned long *p = (const unsigned long *)addr + BIT_WORD(nr);
> + unsigned long mask = BIT_MASK(nr);
> + unsigned long val = *p;
> +
> + return !!(val & mask);
> }
>
> #endif /* __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMIC_H */
> --
> 2.36.1
>
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]