Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_BITS_H
0003 #define __LINUX_BITS_H
0004 
0005 #include <linux/const.h>
0006 #include <vdso/bits.h>
0007 #include <asm/bitsperlong.h>
0008 
0009 #define BIT_ULL(nr)     (ULL(1) << (nr))
0010 #define BIT_MASK(nr)        (UL(1) << ((nr) % BITS_PER_LONG))
0011 #define BIT_WORD(nr)        ((nr) / BITS_PER_LONG)
0012 #define BIT_ULL_MASK(nr)    (ULL(1) << ((nr) % BITS_PER_LONG_LONG))
0013 #define BIT_ULL_WORD(nr)    ((nr) / BITS_PER_LONG_LONG)
0014 #define BITS_PER_BYTE       8
0015 
0016 /*
0017  * Create a contiguous bitmask starting at bit position @l and ending at
0018  * position @h. For example
0019  * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
0020  */
0021 #if !defined(__ASSEMBLY__)
0022 #include <linux/build_bug.h>
0023 #define GENMASK_INPUT_CHECK(h, l) \
0024     (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
0025         __is_constexpr((l) > (h)), (l) > (h), 0)))
0026 #else
0027 /*
0028  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
0029  * disable the input check if that is the case.
0030  */
0031 #define GENMASK_INPUT_CHECK(h, l) 0
0032 #endif
0033 
0034 #define __GENMASK(h, l) \
0035     (((~UL(0)) - (UL(1) << (l)) + 1) & \
0036      (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
0037 #define GENMASK(h, l) \
0038     (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
0039 
0040 #define __GENMASK_ULL(h, l) \
0041     (((~ULL(0)) - (ULL(1) << (l)) + 1) & \
0042      (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h))))
0043 #define GENMASK_ULL(h, l) \
0044     (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
0045 
0046 #endif  /* __LINUX_BITS_H */