Skip to content

Commit 104ea1c

Browse files
vincent-mailholYuryNorov
authored andcommitted
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 <[email protected]> Signed-off-by: Yury Norov (NVIDIA) <[email protected]>
1 parent 6d44712 commit 104ea1c

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

include/linux/bits.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#ifndef __LINUX_BITS_H
33
#define __LINUX_BITS_H
44

5-
#include <linux/const.h>
65
#include <vdso/bits.h>
76
#include <uapi/linux/bits.h>
8-
#include <asm/bitsperlong.h>
97

108
#define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG))
119
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
@@ -35,11 +33,6 @@
3533

3634
#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h)))
3735

38-
#define GENMASK(h, l) \
39-
(GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
40-
#define GENMASK_ULL(h, l) \
41-
(GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
42-
4336
/*
4437
* Generate a mask for the specified type @t. Additional checks are made to
4538
* guarantee the value returned fits in that type, relying on
@@ -55,10 +48,14 @@
5548
(type_max(t) << (l) & \
5649
type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h)))))
5750

51+
#define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l)
52+
#define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l)
53+
5854
#define GENMASK_U8(h, l) GENMASK_TYPE(u8, h, l)
5955
#define GENMASK_U16(h, l) GENMASK_TYPE(u16, h, l)
6056
#define GENMASK_U32(h, l) GENMASK_TYPE(u32, h, l)
6157
#define GENMASK_U64(h, l) GENMASK_TYPE(u64, h, l)
58+
#define GENMASK_U128(h, l) GENMASK_TYPE(u128, h, l)
6259

6360
/*
6461
* Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). The
@@ -89,19 +86,4 @@
8986

9087
#endif /* !defined(__ASSEMBLY__) */
9188

92-
#if !defined(__ASSEMBLY__)
93-
/*
94-
* Missing asm support
95-
*
96-
* __GENMASK_U128() depends on _BIT128() which would not work
97-
* in the asm code, as it shifts an 'unsigned __int128' data
98-
* type instead of direct representation of 128 bit constants
99-
* such as long and unsigned long. The fundamental problem is
100-
* that a 128 bit constant will get silently truncated by the
101-
* gcc compiler.
102-
*/
103-
#define GENMASK_U128(h, l) \
104-
(GENMASK_INPUT_CHECK(h, l) + __GENMASK_U128(h, l))
105-
#endif
106-
10789
#endif /* __LINUX_BITS_H */

0 commit comments

Comments
 (0)