xref: /DragonStub/inc/dragonstub/linux/bitsperlong.h (revision f412fd2a1a248b546b7085648dece8d908077fab)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_GENERIC_BITS_PER_LONG
3 #define __ASM_GENERIC_BITS_PER_LONG
4 
5 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
6 #ifndef _UAPI__ASM_GENERIC_BITS_PER_LONG
7 #define _UAPI__ASM_GENERIC_BITS_PER_LONG
8 
9 #ifndef __BITS_PER_LONG
10 /*
11  * In order to keep safe and avoid regression, only unify uapi
12  * bitsperlong.h for some archs which are using newer toolchains
13  * that have the definitions of __CHAR_BIT__ and __SIZEOF_LONG__.
14  * See the following link for more info:
15  * https://lore.kernel.org/linux-arch/b9624545-2c80-49a1-ac3c-39264a591f7b@app.fastmail.com/
16  */
17 #if defined(__CHAR_BIT__) && defined(__SIZEOF_LONG__)
18 #define __BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__)
19 #else
20 /*
21  * There seems to be no way of detecting this automatically from user
22  * space, so 64 bit architectures should override this in their
23  * bitsperlong.h. In particular, an architecture that supports
24  * both 32 and 64 bit user space must not rely on CONFIG_64BIT
25  * to decide it, but rather check a compiler provided macro.
26  */
27 #define __BITS_PER_LONG 32
28 #endif
29 #endif
30 
31 #endif /* _UAPI__ASM_GENERIC_BITS_PER_LONG */
32 
33 
34 
35 #ifdef CONFIG_64BIT
36 #ifndef BITS_PER_LONG
37 #define BITS_PER_LONG 64
38 #endif
39 #else
40 #define BITS_PER_LONG 32
41 #endif /* CONFIG_64BIT */
42 
43 /*
44  * FIXME: The check currently breaks x86-64 build, so it's
45  * temporarily disabled. Please fix x86-64 and reenable
46  */
47 #if 0 && BITS_PER_LONG != __BITS_PER_LONG
48 #error Inconsistent word size. Check asm/bitsperlong.h
49 #endif
50 
51 #ifndef BITS_PER_LONG_LONG
52 #define BITS_PER_LONG_LONG 64
53 #endif
54 
55 /*
56  * small_const_nbits(n) is true precisely when it is known at compile-time
57  * that BITMAP_SIZE(n) is 1, i.e. 1 <= n <= BITS_PER_LONG. This allows
58  * various bit/bitmap APIs to provide a fast inline implementation. Bitmaps
59  * of size 0 are very rare, and a compile-time-known-size 0 is most likely
60  * a sign of error. They will be handled correctly by the bit/bitmap APIs,
61  * but using the out-of-line functions, so that the inline implementations
62  * can unconditionally dereference the pointer(s).
63  */
64 #define small_const_nbits(nbits) \
65 	(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0)
66 
67 #endif /* __ASM_GENERIC_BITS_PER_LONG */
68