]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
lib/bitrev: Introduce GENERIC_BITREVERSE
authorYury Norov <ynorov@nvidia.com>
Wed, 6 May 2026 17:52:03 +0000 (13:52 -0400)
committerYury Norov <ynorov@nvidia.com>
Thu, 28 May 2026 15:39:16 +0000 (11:39 -0400)
commit00751d655ece97fe85ce9193542ee8396fe98651
tree4d95cb8b90000b72d4a92bbaf1c6cac29de04c2c
parent42d9c75e8b9cae9583c228617be38ab1637fd574
lib/bitrev: Introduce GENERIC_BITREVERSE

The generic bit reversal implementation is controlled by
!HAVE_ARCH_BITREVERSE. This makes it difficult for architectures to
provide a hardware-accelerated implementation while being able to
fall back to the generic version if needed.

This patch adds GENERIC_BITREVERSE, so bitreverse API is controlled by
BITREVERSE, GENERIC_BITREVERSE and HAVE_ARCH_BITREVERSE options. The
relationship between them is described as follows:

 - BITREVERSE is selected by user code; it's required to generate the API;
 - Architectures may select HAVE_ARCH_BITREVERSE and provide an arch
   implementation in arch/$(ARCH)/include/asm/bitrev.h.
 - if HAVE_ARCH_BITREVERSE isn't set, BITREVERSE selects GENERIC_BITREVERSE;
 - if GENERIC_BITREVERSE is set and HAVE_ARCH_BITREVERSE is not, the kernel
   provides generic implementation only, and wires bitrevXX() to it.
 - if HAVE_ARCH_BITREVERSE is set and GENERIC_BITREVERSE is not, the arch
   code provides __arch_bitrevXX(), and it is wired to bitrevXX();
 - if both GENERIC_BITREVERSE and HAVE_ARCH_BITREVERSE are selected, the kernel
   generates generic___bitrev(), but wires bitrev() to the __arch_bitrev().

The last option allows architectures to use generic___bitrev() as a
fallback option.

Drivers and core code should never select GENERIC_BITREVERSE or
HAVE_ARCH_BITREVERSE explicitly.

Architectures that require generic bitreverse API as a fallback should
explicitly enable GENERIC_BITREVERSE together with HAVE_ARCH_BITREVERSE.

Signed-off-by: Yury Norov <ynorov@nvidia.com>
lib/Kconfig
lib/Makefile
lib/bitrev.c