Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bits: unify the non-asm GENMASK*()

The newly introduced GENMASK_TYPE() macro can also be used to generate
the pre-existing non-asm GENMASK*() variants.

Apply GENMASK_TYPE() to GENMASK(), GENMASK_ULL() and GENMASK_U128().

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>

authored by

Vincent Mailhol and committed by
Yury Norov
104ea1c8 6d447125

+4 -22
+4 -22
include/linux/bits.h
··· 2 2 #ifndef __LINUX_BITS_H 3 3 #define __LINUX_BITS_H 4 4 5 - #include <linux/const.h> 6 5 #include <vdso/bits.h> 7 6 #include <uapi/linux/bits.h> 8 - #include <asm/bitsperlong.h> 9 7 10 8 #define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG)) 11 9 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) ··· 33 35 34 36 #define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h))) 35 37 36 - #define GENMASK(h, l) \ 37 - (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) 38 - #define GENMASK_ULL(h, l) \ 39 - (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l)) 40 - 41 38 /* 42 39 * Generate a mask for the specified type @t. Additional checks are made to 43 40 * guarantee the value returned fits in that type, relying on ··· 48 55 (type_max(t) << (l) & \ 49 56 type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h))))) 50 57 58 + #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) 59 + #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l) 60 + 51 61 #define GENMASK_U8(h, l) GENMASK_TYPE(u8, h, l) 52 62 #define GENMASK_U16(h, l) GENMASK_TYPE(u16, h, l) 53 63 #define GENMASK_U32(h, l) GENMASK_TYPE(u32, h, l) 54 64 #define GENMASK_U64(h, l) GENMASK_TYPE(u64, h, l) 65 + #define GENMASK_U128(h, l) GENMASK_TYPE(u128, h, l) 55 66 56 67 /* 57 68 * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). The ··· 85 88 #define GENMASK_ULL(h, l) __GENMASK_ULL(h, l) 86 89 87 90 #endif /* !defined(__ASSEMBLY__) */ 88 - 89 - #if !defined(__ASSEMBLY__) 90 - /* 91 - * Missing asm support 92 - * 93 - * __GENMASK_U128() depends on _BIT128() which would not work 94 - * in the asm code, as it shifts an 'unsigned __int128' data 95 - * type instead of direct representation of 128 bit constants 96 - * such as long and unsigned long. The fundamental problem is 97 - * that a 128 bit constant will get silently truncated by the 98 - * gcc compiler. 99 - */ 100 - #define GENMASK_U128(h, l) \ 101 - (GENMASK_INPUT_CHECK(h, l) + __GENMASK_U128(h, l)) 102 - #endif 103 91 104 92 #endif /* __LINUX_BITS_H */