1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2c31ae4bbSArnd Bergmann #ifndef __ASM_GENERIC_BITS_PER_LONG
3c31ae4bbSArnd Bergmann #define __ASM_GENERIC_BITS_PER_LONG
4c31ae4bbSArnd Bergmann 
58a1ab315SDavid Howells #include <uapi/asm-generic/bitsperlong.h>
6c31ae4bbSArnd Bergmann 
7c31ae4bbSArnd Bergmann 
8c31ae4bbSArnd Bergmann #ifdef CONFIG_64BIT
9c31ae4bbSArnd Bergmann #define BITS_PER_LONG 64
10c31ae4bbSArnd Bergmann #else
11c31ae4bbSArnd Bergmann #define BITS_PER_LONG 32
12c31ae4bbSArnd Bergmann #endif /* CONFIG_64BIT */
13c31ae4bbSArnd Bergmann 
14c31ae4bbSArnd Bergmann /*
15c31ae4bbSArnd Bergmann  * FIXME: The check currently breaks x86-64 build, so it's
16c31ae4bbSArnd Bergmann  * temporarily disabled. Please fix x86-64 and reenable
17c31ae4bbSArnd Bergmann  */
18c31ae4bbSArnd Bergmann #if 0 && BITS_PER_LONG != __BITS_PER_LONG
19c31ae4bbSArnd Bergmann #error Inconsistent word size. Check asm/bitsperlong.h
20c31ae4bbSArnd Bergmann #endif
21c31ae4bbSArnd Bergmann 
22133fd9f5SDenys Vlasenko #ifndef BITS_PER_LONG_LONG
23133fd9f5SDenys Vlasenko #define BITS_PER_LONG_LONG 64
24133fd9f5SDenys Vlasenko #endif
25133fd9f5SDenys Vlasenko 
26*586eaebeSYury Norov /*
27*586eaebeSYury Norov  * small_const_nbits(n) is true precisely when it is known at compile-time
28*586eaebeSYury Norov  * that BITMAP_SIZE(n) is 1, i.e. 1 <= n <= BITS_PER_LONG. This allows
29*586eaebeSYury Norov  * various bit/bitmap APIs to provide a fast inline implementation. Bitmaps
30*586eaebeSYury Norov  * of size 0 are very rare, and a compile-time-known-size 0 is most likely
31*586eaebeSYury Norov  * a sign of error. They will be handled correctly by the bit/bitmap APIs,
32*586eaebeSYury Norov  * but using the out-of-line functions, so that the inline implementations
33*586eaebeSYury Norov  * can unconditionally dereference the pointer(s).
34*586eaebeSYury Norov  */
35*586eaebeSYury Norov #define small_const_nbits(nbits) \
36*586eaebeSYury Norov 	(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0)
37*586eaebeSYury Norov 
38c31ae4bbSArnd Bergmann #endif /* __ASM_GENERIC_BITS_PER_LONG */
39