File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 24
24
/*
25
25
* Missing asm support
26
26
*
27
- * GENMASK_U*() depend on BITS_PER_TYPE() which relies on sizeof(),
27
+ * GENMASK_U*() and BIT_U*() depend on BITS_PER_TYPE() which relies on sizeof(),
28
28
* something not available in asm. Nevertheless, fixed width integers is a C
29
29
* concept. Assembly code can rely on the long and long long versions instead.
30
30
*/
55
55
#define GENMASK_U32 (h , l ) GENMASK_TYPE(u32, h, l)
56
56
#define GENMASK_U64 (h , l ) GENMASK_TYPE(u64, h, l)
57
57
58
+ /*
59
+ * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). The
60
+ * following examples generate compiler warnings due to -Wshift-count-overflow:
61
+ *
62
+ * - BIT_U8(8)
63
+ * - BIT_U32(-1)
64
+ * - BIT_U32(40)
65
+ */
66
+ #define BIT_INPUT_CHECK (type , nr ) \
67
+ BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type)))
68
+
69
+ #define BIT_TYPE (type , nr ) ((type)(BIT_INPUT_CHECK(type, nr) + BIT_ULL(nr)))
70
+
71
+ #define BIT_U8 (nr ) BIT_TYPE(u8, nr)
72
+ #define BIT_U16 (nr ) BIT_TYPE(u16, nr)
73
+ #define BIT_U32 (nr ) BIT_TYPE(u32, nr)
74
+ #define BIT_U64 (nr ) BIT_TYPE(u64, nr)
75
+
58
76
#else /* defined(__ASSEMBLY__) */
59
77
60
78
/*
You can’t perform that action at this time.
0 commit comments