Skip to content

Commit 947697c

Browse files
Anshuman KhandualYuryNorov
authored andcommitted
uapi: Define GENMASK_U128
This adds GENMASK_U128() and __GENMASK_U128() macros using __BITS_PER_U128 and __int128 data types. These macros will be used in providing support for generating 128 bit masks. The macros wouldn't work in all assembler flavors for reasons described in the comments on top of declarations. Enforce it for more by adding !__ASSEMBLY__ guard. Cc: Yury Norov <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Arnd Bergmann <[email protected]>> Cc: [email protected] Cc: [email protected] Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Anshuman Khandual <[email protected]> Signed-off-by: Yury Norov <[email protected]>
1 parent 54c9e00 commit 947697c

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

include/linux/bits.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,19 @@
3636
#define GENMASK_ULL(h, l) \
3737
(GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
3838

39+
#if !defined(__ASSEMBLY__)
40+
/*
41+
* Missing asm support
42+
*
43+
* __GENMASK_U128() depends on _BIT128() which would not work
44+
* in the asm code, as it shifts an 'unsigned __init128' data
45+
* type instead of direct representation of 128 bit constants
46+
* such as long and unsigned long. The fundamental problem is
47+
* that a 128 bit constant will get silently truncated by the
48+
* gcc compiler.
49+
*/
50+
#define GENMASK_U128(h, l) \
51+
(GENMASK_INPUT_CHECK(h, l) + __GENMASK_U128(h, l))
52+
#endif
53+
3954
#endif /* __LINUX_BITS_H */

include/uapi/linux/bits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
(((~_ULL(0)) - (_ULL(1) << (l)) + 1) & \
1313
(~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
1414

15+
#define __GENMASK_U128(h, l) \
16+
((_BIT128((h)) << 1) - (_BIT128(l)))
17+
1518
#endif /* _UAPI_LINUX_BITS_H */

include/uapi/linux/const.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@
2828
#define _BITUL(x) (_UL(1) << (x))
2929
#define _BITULL(x) (_ULL(1) << (x))
3030

31+
#if !defined(__ASSEMBLY__)
32+
/*
33+
* Missing asm support
34+
*
35+
* __BIT128() would not work in the asm code, as it shifts an
36+
* 'unsigned __init128' data type as direct representation of
37+
* 128 bit constants is not supported in the gcc compiler, as
38+
* they get silently truncated.
39+
*
40+
* TODO: Please revisit this implementation when gcc compiler
41+
* starts representing 128 bit constants directly like long
42+
* and unsigned long etc. Subsequently drop the comment for
43+
* GENMASK_U128() which would then start supporting asm code.
44+
*/
45+
#define _BIT128(x) ((unsigned __int128)(1) << (x))
46+
#endif
47+
3148
#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
3249
#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
3350

0 commit comments

Comments
 (0)