162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __ASM_GENERIC_BITS_PER_LONG
362306a36Sopenharmony_ci#define __ASM_GENERIC_BITS_PER_LONG
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <uapi/asm-generic/bitsperlong.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifdef CONFIG_64BIT
962306a36Sopenharmony_ci#define BITS_PER_LONG 64
1062306a36Sopenharmony_ci#else
1162306a36Sopenharmony_ci#define BITS_PER_LONG 32
1262306a36Sopenharmony_ci#endif /* CONFIG_64BIT */
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/*
1562306a36Sopenharmony_ci * FIXME: The check currently breaks x86-64 build, so it's
1662306a36Sopenharmony_ci * temporarily disabled. Please fix x86-64 and reenable
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci#if 0 && BITS_PER_LONG != __BITS_PER_LONG
1962306a36Sopenharmony_ci#error Inconsistent word size. Check asm/bitsperlong.h
2062306a36Sopenharmony_ci#endif
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#ifndef BITS_PER_LONG_LONG
2362306a36Sopenharmony_ci#define BITS_PER_LONG_LONG 64
2462306a36Sopenharmony_ci#endif
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/*
2762306a36Sopenharmony_ci * small_const_nbits(n) is true precisely when it is known at compile-time
2862306a36Sopenharmony_ci * that BITMAP_SIZE(n) is 1, i.e. 1 <= n <= BITS_PER_LONG. This allows
2962306a36Sopenharmony_ci * various bit/bitmap APIs to provide a fast inline implementation. Bitmaps
3062306a36Sopenharmony_ci * of size 0 are very rare, and a compile-time-known-size 0 is most likely
3162306a36Sopenharmony_ci * a sign of error. They will be handled correctly by the bit/bitmap APIs,
3262306a36Sopenharmony_ci * but using the out-of-line functions, so that the inline implementations
3362306a36Sopenharmony_ci * can unconditionally dereference the pointer(s).
3462306a36Sopenharmony_ci */
3562306a36Sopenharmony_ci#define small_const_nbits(nbits) \
3662306a36Sopenharmony_ci	(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#endif /* __ASM_GENERIC_BITS_PER_LONG */
39