* [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*()
@ 2025-03-25 15:59 Vincent Mailhol via B4 Relay
2025-03-25 15:59 ` [PATCH v8 1/6] bits: add comments and newlines to #if, #else and #endif directives Vincent Mailhol via B4 Relay
` (6 more replies)
0 siblings, 7 replies; 13+ messages in thread
From: Vincent Mailhol via B4 Relay @ 2025-03-25 15:59 UTC (permalink / raw)
To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton
Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Vincent Mailhol, Jani Nikula
Introduce some fixed width variant of the GENMASK() and the BIT()
macros in bits.h. For example:
GENMASK_U16(16, 0)
will raise a build bug.
This series is a continuation of:
https://lore.kernel.org/intel-xe/20240208074521.577076-1-lucas.demarchi@intel.com
from Lucas De Marchi. Above series is one year old. I really think
that this was a good idea and I do not want this series to die. So I
am volunteering to revive it.
Meanwhile, many changes occurred in bits.h. The most significant
change is that __GENMASK() was moved to the uapi headers. For this
reason, a new GENMASK_TYPE() is introduced instead and the uapi
__GENMASK() is left untouched.
Finally, I do not think it makes sense to expose the fixed width
variants to the asm. The fixed width integers type are a C concept. So
the GENMASK_U*() are only visible to the non-asm code. For asm, the
long and long long variants seem sufficient.
This series does not modify the actual GENMASK(), GENMASK_ULL() and
GENMASK_U128(). A consolidation of the existing genmasks will be
proposed later on in a separate series.
As requested, here are the bloat-o-meter stats:
$ ./scripts/bloat-o-meter vmlinux_before.o vmlinux_after.o
add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)
Function old new delta
Total: Before=22781662, After=22781662, chg +0.00%
(done with GCC 12.4.1 on an x86_64_defconfig)
--
2.43.0
---
Changes from v7:
- Meanwhile, in commit db6fe4d61ece ("lib: Move KUnit tests into
tests/ subdirectory"), lib/test_bits.c was moved to
lib/tests/test_bits.c. Rebase onto Linus's master branch so that
this change is reflected.
- Remove the note in the cover letter on the return type, instead
add an explanation in patch "bits: introduce fixed-type
GENMASK_U*()".
- s/shift-count-overflow/-Wshift-count-overflow/g
- Link to v7: https://lore.kernel.org/r/20250322-fixed-type-genmasks-v7-0-da380ff1c5b9@wanadoo.fr
Changes from v6:
- Split the series in two: this series leave any existing GENMASK*()
unmodified. The consolidation will be done in a separate series.
- Collect some Reviewed-by tag.
- Address miscellaneous nitpick on the code comments and the line
wrapping (details in each patch).
- Link to v6: https://lore.kernel.org/r/20250308-fixed-type-genmasks-v6-0-f59315e73c29@wanadoo.fr
Changes from v5:
- Update the cover letter message. I was still refering to
GENMASK_t() instead of GENMASK_TYPE().
- Add a comment in the cover letter to explain that a common
GENMASK_TYPE() for C and asm wouldn't allow to generate the u128
variant.
- Restore the comment saying that BUILD_BUG_ON() is not available in
asm code.
- Add a FIXME message to highlight the absence of the asm GENMASK*()
unit tests.
- Use git's histogram diff algorithm
- Link to v5: https://lore.kernel.org/r/20250306-fixed-type-genmasks-v5-0-b443e9dcba63@wanadoo.fr
Changes from v4:
- Rebase on https://github.com/norov/linux/tree/bitmap-for-next
- Rename GENMASK_t() to GENMASK_TYPE()
- First patch of v4 (the typo fix 'init128' -> 'int128') is removed
because it was resent separately in:
https://lore.kernel.org/all/20250305-fix_init128_typo-v1-1-cbe5b8e54e7d@wanadoo.fr
- Replace the (t)~ULL(0) by type_max(t). This way, GENMASK_TYPE()
can now be used to generate GENMASK_U128().
- Get rid of the unsigned int cast for the U8 and U16 variants.
- Add the BIT_TYPE() helper macro.
- Link to v4: https://lore.kernel.org/r/20250305-fixed-type-genmasks-v4-0-1873dcdf6723@wanadoo.fr
Changes from v3:
- Rebase on v6.14-rc5
- Fix a typo in GENMASK_U128() comment.
- Split the asm and non-asm definition of
- Replace ~0ULL by ~ULL(0)
- Since v3, __GENMASK() was moved to the uapi and people started
using directly. Introduce GENMASK_t() instead.
- Link to v3: https://lore.kernel.org/intel-xe/20240208074521.577076-1-lucas.demarchi@intel.com
Changes from v2:
- Document both in commit message and code about the strict type
checking and give examples how it´d break with invalid params.
- Link to v2: https://lore.kernel.org/intel-xe/20240124050205.3646390-1-lucas.demarchi@intel.com
Link to v1: https://lore.kernel.org/intel-xe/20230509051403.2748545-1-lucas.demarchi@intel.com
---
Lucas De Marchi (3):
bits: introduce fixed-type BIT_U*()
drm/i915: Convert REG_GENMASK*() to fixed-width GENMASK_U*()
test_bits: add tests for GENMASK_U*()
Vincent Mailhol (3):
bits: add comments and newlines to #if, #else and #endif directives
bits: introduce fixed-type GENMASK_U*()
test_bits: add tests for BIT_U*()
drivers/gpu/drm/i915/i915_reg_defs.h | 108 ++++-------------------------------
include/linux/bitops.h | 1 -
include/linux/bits.h | 57 +++++++++++++++++-
lib/tests/test_bits.c | 30 ++++++++++
4 files changed, 96 insertions(+), 100 deletions(-)
---
base-commit: 2df0c02dab829dd89360d98a8a1abaa026ef5798
change-id: 20250228-fixed-type-genmasks-8d1a555f34e8
Best regards,
--
Vincent Mailhol <mailhol.vincent@wanadoo.fr>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v8 1/6] bits: add comments and newlines to #if, #else and #endif directives
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 15:59 ` Vincent Mailhol via B4 Relay
2025-03-25 16:20 ` Andy Shevchenko
2025-03-25 15:59 ` [PATCH v8 2/6] bits: introduce fixed-type GENMASK_U*() Vincent Mailhol via B4 Relay
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Vincent Mailhol via B4 Relay @ 2025-03-25 15:59 UTC (permalink / raw)
To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton
Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Vincent Mailhol
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
This is a preparation for the upcoming GENMASK_U*() and BIT_U*()
changes. After introducing those new macros, there will be a lot of
scrolling between the #if, #else and #endif.
Add a comment to the #else and #endif preprocessor macros to help keep
track of which context we are in. Also, add new lines to better
visually separate the non-asm and asm sections.
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
Changelog:
v7 -> v8:
- new patch
---
include/linux/bits.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/include/linux/bits.h b/include/linux/bits.h
index 14fd0ca9a6cd17339dd2f69e449558312a8a001b..e1e5177691406919ba4f5bbc875bd230414fd117 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -19,16 +19,21 @@
* GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
*/
#if !defined(__ASSEMBLY__)
+
#include <linux/build_bug.h>
#include <linux/compiler.h>
+
#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h)))
-#else
+
+#else /* defined(__ASSEMBLY__) */
+
/*
* BUILD_BUG_ON_ZERO is not available in h files included from asm files,
* disable the input check if that is the case.
*/
#define GENMASK_INPUT_CHECK(h, l) 0
-#endif
+
+#endif /* !defined(__ASSEMBLY__) */
#define GENMASK(h, l) \
(GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v8 2/6] bits: introduce fixed-type GENMASK_U*()
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
2025-03-25 15:59 ` [PATCH v8 1/6] bits: add comments and newlines to #if, #else and #endif directives Vincent Mailhol via B4 Relay
@ 2025-03-25 15:59 ` Vincent Mailhol via B4 Relay
2025-03-25 16:24 ` Andy Shevchenko
2025-03-25 15:59 ` [PATCH v8 3/6] bits: introduce fixed-type BIT_U*() Vincent Mailhol via B4 Relay
` (4 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Vincent Mailhol via B4 Relay @ 2025-03-25 15:59 UTC (permalink / raw)
To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton
Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Jani Nikula, Vincent Mailhol
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Add GENMASK_TYPE() which generalizes __GENMASK() to support different
types, and implement fixed-types versions of GENMASK() based on it.
The fixed-type version allows more strict checks to the min/max values
accepted, which is useful for defining registers like implemented by
i915 and xe drivers with their REG_GENMASK*() macros.
The strict checks rely on shift-count-overflow compiler check to fail
the build if a number outside of the range allowed is passed.
Example:
#define FOO_MASK GENMASK_U32(33, 4)
will generate a warning like:
include/linux/bits.h:51:27: error: right shift count >= width of type [-Werror=shift-count-overflow]
51 | type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h)))))
| ^~
The result is casted to the corresponding fixed width type. For
example, GENMASK_U8() returns an u8. Note that because of the C
promotion rules, GENMASK_U8() and GENMASK_U16() will immediately be
promoted to int if used in an expression. Regardless, the main goal is
not to get the correct type, but rather to enforce more checks at
compile time.
While GENMASK_TYPE() is crafted to cover all variants, including the
already existing GENMASK(), GENMASK_ULL() and GENMASK_U128(), for the
moment, only use it for the newly introduced GENMASK_U*(). The
consolidation will be done in a separate change.
Co-developed-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
Changelog:
v7 -> v8:
- s/shift-count-overflow/-Wshift-count-overflow/g
- add an explanation about the return value cast in the patch
description.
v6 -> v7:
- Fix grammar in comment: 'GENMASK_U*() depends' -> 'GENMASK_U*()
depend'.
- Fix typo in comment: 'Nethertheless' -> 'Nevertheless'
- Do an artificial early line wrap in comment so that the next
patch only has a one line diff change.
- Re-wrap the comments to the 80th column.
- The patch changed a lot since Yury first version: put myself as
main author and Yury as Co-developer.
- Add a new paragraph to the patch description to explain that
consolidation will be done later.
v5 -> v6:
- No changes.
v4 -> v5:
- Rename GENMASK_t() to GENMASK_TYPE().
- Fix typo in patch description.
- Use tab indentations instead of single space to separate the
macro name from its body.
- s/__GENMASK_U*()/GENMASK_U*()/g in the comment.
- Add a tag to credit myself as Co-developer. Keep Yury as the
main author.
- Modify GENMASK_TYPE() to match the changes made to __GENMASK()
in: https://github.com/norov/linux/commit/1e7933a575ed
- Replace (t)~_ULL(0) with type_max(t). This is OK because
GENMASK_TYPE() is not available in asm.
- linux/const.h and asm/bitsperlong.h are not used anymore. Remove
them.
- Apply GENMASK_TYPE() to GENMASK_U128().
- Remove the unsigned int cast for the U8 and U16 variants. Cast
to the target type instead. Do that cast directly in
GENMASK_TYPE().
v3 -> v4:
- The v3 is one year old. Meanwhile people started using
__GENMASK() directly. So instead of generalizing __GENMASK() to
support different types, add a new GENMASK_t().
- replace ~0ULL by ~_ULL(0). Otherwise, GENMASK_t() would fail in
asm code.
- Make GENMASK_U8() and GENMASK_U16() return an unsigned int. In
v3, due to the integer promotion rules, these were returning a
signed integer. By casting these to unsigned int, at least the
signedness is kept.
---
include/linux/bitops.h | 1 -
include/linux/bits.h | 30 ++++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index c1cb53cf2f0f8662ed3e324578f74330e63f935d..9be2d50da09a417966b3d11c84092bb2f4cd0bef 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -8,7 +8,6 @@
#include <uapi/linux/kernel.h>
-#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
#define BITS_TO_LONGS(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
#define BITS_TO_U64(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
#define BITS_TO_U32(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
diff --git a/include/linux/bits.h b/include/linux/bits.h
index e1e5177691406919ba4f5bbc875bd230414fd117..9718c5ae5fc356e66958cf48667bb1edda4f9673 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -12,6 +12,7 @@
#define BIT_ULL_MASK(nr) (ULL(1) << ((nr) % BITS_PER_LONG_LONG))
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#define BITS_PER_BYTE 8
+#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
/*
* Create a contiguous bitmask starting at bit position @l and ending at
@@ -20,11 +21,40 @@
*/
#if !defined(__ASSEMBLY__)
+/*
+ * Missing asm support
+ *
+ * GENMASK_U*() depend on BITS_PER_TYPE() which relies on sizeof(),
+ * something not available in asm. Nevertheless, fixed width integers is a C
+ * concept. Assembly code can rely on the long and long long versions instead.
+ */
+
#include <linux/build_bug.h>
#include <linux/compiler.h>
+#include <linux/overflow.h>
#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h)))
+/*
+ * Generate a mask for the specified type @t. Additional checks are made to
+ * guarantee the value returned fits in that type, relying on
+ * -Wshift-count-overflow compiler check to detect incompatible arguments.
+ * For example, all these create build errors or warnings:
+ *
+ * - GENMASK(15, 20): wrong argument order
+ * - GENMASK(72, 15): doesn't fit unsigned long
+ * - GENMASK_U32(33, 15): doesn't fit in a u32
+ */
+#define GENMASK_TYPE(t, h, l) \
+ ((t)(GENMASK_INPUT_CHECK(h, l) + \
+ (type_max(t) << (l) & \
+ type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h)))))
+
+#define GENMASK_U8(h, l) GENMASK_TYPE(u8, h, l)
+#define GENMASK_U16(h, l) GENMASK_TYPE(u16, h, l)
+#define GENMASK_U32(h, l) GENMASK_TYPE(u32, h, l)
+#define GENMASK_U64(h, l) GENMASK_TYPE(u64, h, l)
+
#else /* defined(__ASSEMBLY__) */
/*
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v8 3/6] bits: introduce fixed-type BIT_U*()
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
2025-03-25 15:59 ` [PATCH v8 1/6] bits: add comments and newlines to #if, #else and #endif directives Vincent Mailhol via B4 Relay
2025-03-25 15:59 ` [PATCH v8 2/6] bits: introduce fixed-type GENMASK_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 15:59 ` Vincent Mailhol via B4 Relay
2025-03-25 16:27 ` Andy Shevchenko
2025-03-25 15:59 ` [PATCH v8 4/6] drm/i915: Convert REG_GENMASK*() to fixed-width GENMASK_U*() Vincent Mailhol via B4 Relay
` (3 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Vincent Mailhol via B4 Relay @ 2025-03-25 15:59 UTC (permalink / raw)
To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton
Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Jani Nikula, Vincent Mailhol
From: Lucas De Marchi <lucas.demarchi@intel.com>
Implement fixed-type BIT_U*() to help drivers add stricter checks,
like it was done for GENMASK_U*().
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Co-developed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
Changelog:
v7 -> v8:
- s/shift-count-overflow/-Wshift-count-overflow/g
v6 -> v7:
v5 -> v6:
- No changes.
v4 -> v5:
- Rename GENMASK_t() to GENMASK_TYPE().
- Use tab indentations instead of single space to separate the
macro name from its body.
- Add a global comment at the beginning of the file to explain why
GENMASK_U*() and BIT_U*() are not available in asm.
- Add a new BIT_TYPE() helper function, similar to GENMASK_TYPE().
- Remove the unsigned int cast for the U8 and U16 variants. Move
the cast to BIT_TYPE().
- Rename the argument from BIT_U*(b) to BIT_U*(nr) for consistency
with vdso/bits.h.
v3 -> v4:
- Use const_true() to simplify BIT_INPUT_CHECK().
- Make BIT_U8() and BIT_U16() return an unsigned int instead of a
u8 and u16. Because of the integer promotion rules in C, an u8
or an u16 would become a signed integer as soon as these are
used in any expression. By casting these to unsigned ints, at
least the signedness is kept.
- Put the cast next to the BIT() macro.
- In BIT_U64(): use BIT_ULL() instead of BIT().
---
include/linux/bits.h | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/include/linux/bits.h b/include/linux/bits.h
index 9718c5ae5fc356e66958cf48667bb1edda4f9673..7ad0562191153471dac729b0020cdb1c9d3049fc 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -24,7 +24,7 @@
/*
* Missing asm support
*
- * GENMASK_U*() depend on BITS_PER_TYPE() which relies on sizeof(),
+ * GENMASK_U*() and BIT_U*() depend on BITS_PER_TYPE() which relies on sizeof(),
* something not available in asm. Nevertheless, fixed width integers is a C
* concept. Assembly code can rely on the long and long long versions instead.
*/
@@ -55,6 +55,24 @@
#define GENMASK_U32(h, l) GENMASK_TYPE(u32, h, l)
#define GENMASK_U64(h, l) GENMASK_TYPE(u64, h, l)
+/*
+ * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). The
+ * following examples generate compiler warnings due to -Wshift-count-overflow:
+ *
+ * - BIT_U8(8)
+ * - BIT_U32(-1)
+ * - BIT_U32(40)
+ */
+#define BIT_INPUT_CHECK(type, nr) \
+ BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type)))
+
+#define BIT_TYPE(type, nr) ((type)(BIT_INPUT_CHECK(type, nr) + BIT_ULL(nr)))
+
+#define BIT_U8(nr) BIT_TYPE(u8, nr)
+#define BIT_U16(nr) BIT_TYPE(u16, nr)
+#define BIT_U32(nr) BIT_TYPE(u32, nr)
+#define BIT_U64(nr) BIT_TYPE(u64, nr)
+
#else /* defined(__ASSEMBLY__) */
/*
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v8 4/6] drm/i915: Convert REG_GENMASK*() to fixed-width GENMASK_U*()
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
` (2 preceding siblings ...)
2025-03-25 15:59 ` [PATCH v8 3/6] bits: introduce fixed-type BIT_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 15:59 ` Vincent Mailhol via B4 Relay
2025-03-25 16:00 ` [PATCH v8 5/6] test_bits: add tests for GENMASK_U*() Vincent Mailhol via B4 Relay
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Vincent Mailhol via B4 Relay @ 2025-03-25 15:59 UTC (permalink / raw)
To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton
Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Jani Nikula, Vincent Mailhol
From: Lucas De Marchi <lucas.demarchi@intel.com>
Now that include/linux/bits.h implements fixed-width GENMASK_U*(), use
them to implement the i915/xe specific macros. Converting each driver
to use the generic macros are left for later, when/if other
driver-specific macros are also generalized.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
Changelog:
v7 -> v8:
- No changes.
v6 -> v7:
- Replace BIT_* and GENMASK_* by BIT_U*() and GENMASK_U*() in the
description.
- Add the information in the description that BIT_U*() and
GENMASK_U*() are fixed width.
v5 -> v6:
- No changes.
v4 -> v5:
- Add brackets to macro names in patch description,
e.g. 'REG_GENMASK*' -> 'REG_GENMASK*()'
v3 -> v4:
- Remove the prefixes in macro parameters,
e.g. 'REG_GENMASK(__high, __low)' -> 'REG_GENMASK(high, low)'
---
drivers/gpu/drm/i915/i915_reg_defs.h | 108 ++++-------------------------------
1 file changed, 11 insertions(+), 97 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_reg_defs.h b/drivers/gpu/drm/i915/i915_reg_defs.h
index e251bcc0c89f5710125bc70f07851b2cb978c89c..e0bc9cf5fa9ed98f7d36f6cb667999aa6522c384 100644
--- a/drivers/gpu/drm/i915/i915_reg_defs.h
+++ b/drivers/gpu/drm/i915/i915_reg_defs.h
@@ -9,76 +9,19 @@
#include <linux/bitfield.h>
#include <linux/bits.h>
-/**
- * REG_BIT() - Prepare a u32 bit value
- * @__n: 0-based bit number
- *
- * Local wrapper for BIT() to force u32, with compile time checks.
- *
- * @return: Value with bit @__n set.
+/*
+ * Wrappers over the generic fixed width BIT_U*() and GENMASK_U*()
+ * implementations, for compatibility reasons with previous implementation.
*/
-#define REG_BIT(__n) \
- ((u32)(BIT(__n) + \
- BUILD_BUG_ON_ZERO(__is_constexpr(__n) && \
- ((__n) < 0 || (__n) > 31))))
+#define REG_GENMASK(high, low) GENMASK_U32(high, low)
+#define REG_GENMASK64(high, low) GENMASK_U64(high, low)
+#define REG_GENMASK16(high, low) GENMASK_U16(high, low)
+#define REG_GENMASK8(high, low) GENMASK_U8(high, low)
-/**
- * REG_BIT8() - Prepare a u8 bit value
- * @__n: 0-based bit number
- *
- * Local wrapper for BIT() to force u8, with compile time checks.
- *
- * @return: Value with bit @__n set.
- */
-#define REG_BIT8(__n) \
- ((u8)(BIT(__n) + \
- BUILD_BUG_ON_ZERO(__is_constexpr(__n) && \
- ((__n) < 0 || (__n) > 7))))
-
-/**
- * REG_GENMASK() - Prepare a continuous u32 bitmask
- * @__high: 0-based high bit
- * @__low: 0-based low bit
- *
- * Local wrapper for GENMASK() to force u32, with compile time checks.
- *
- * @return: Continuous bitmask from @__high to @__low, inclusive.
- */
-#define REG_GENMASK(__high, __low) \
- ((u32)(GENMASK(__high, __low) + \
- BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \
- __is_constexpr(__low) && \
- ((__low) < 0 || (__high) > 31 || (__low) > (__high)))))
-
-/**
- * REG_GENMASK64() - Prepare a continuous u64 bitmask
- * @__high: 0-based high bit
- * @__low: 0-based low bit
- *
- * Local wrapper for GENMASK_ULL() to force u64, with compile time checks.
- *
- * @return: Continuous bitmask from @__high to @__low, inclusive.
- */
-#define REG_GENMASK64(__high, __low) \
- ((u64)(GENMASK_ULL(__high, __low) + \
- BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \
- __is_constexpr(__low) && \
- ((__low) < 0 || (__high) > 63 || (__low) > (__high)))))
-
-/**
- * REG_GENMASK8() - Prepare a continuous u8 bitmask
- * @__high: 0-based high bit
- * @__low: 0-based low bit
- *
- * Local wrapper for GENMASK() to force u8, with compile time checks.
- *
- * @return: Continuous bitmask from @__high to @__low, inclusive.
- */
-#define REG_GENMASK8(__high, __low) \
- ((u8)(GENMASK(__high, __low) + \
- BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \
- __is_constexpr(__low) && \
- ((__low) < 0 || (__high) > 7 || (__low) > (__high)))))
+#define REG_BIT(n) BIT_U32(n)
+#define REG_BIT64(n) BIT_U64(n)
+#define REG_BIT16(n) BIT_U16(n)
+#define REG_BIT8(n) BIT_U8(n)
/*
* Local integer constant expression version of is_power_of_2().
@@ -143,35 +86,6 @@
*/
#define REG_FIELD_GET64(__mask, __val) ((u64)FIELD_GET(__mask, __val))
-/**
- * REG_BIT16() - Prepare a u16 bit value
- * @__n: 0-based bit number
- *
- * Local wrapper for BIT() to force u16, with compile time
- * checks.
- *
- * @return: Value with bit @__n set.
- */
-#define REG_BIT16(__n) \
- ((u16)(BIT(__n) + \
- BUILD_BUG_ON_ZERO(__is_constexpr(__n) && \
- ((__n) < 0 || (__n) > 15))))
-
-/**
- * REG_GENMASK16() - Prepare a continuous u8 bitmask
- * @__high: 0-based high bit
- * @__low: 0-based low bit
- *
- * Local wrapper for GENMASK() to force u16, with compile time
- * checks.
- *
- * @return: Continuous bitmask from @__high to @__low, inclusive.
- */
-#define REG_GENMASK16(__high, __low) \
- ((u16)(GENMASK(__high, __low) + \
- BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \
- __is_constexpr(__low) && \
- ((__low) < 0 || (__high) > 15 || (__low) > (__high)))))
/**
* REG_FIELD_PREP16() - Prepare a u16 bitfield value
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v8 5/6] test_bits: add tests for GENMASK_U*()
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
` (3 preceding siblings ...)
2025-03-25 15:59 ` [PATCH v8 4/6] drm/i915: Convert REG_GENMASK*() to fixed-width GENMASK_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 16:00 ` Vincent Mailhol via B4 Relay
2025-03-25 16:26 ` Andy Shevchenko
2025-03-25 16:00 ` [PATCH v8 6/6] test_bits: add tests for BIT_U*() Vincent Mailhol via B4 Relay
2025-03-26 13:37 ` [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Yury Norov
6 siblings, 1 reply; 13+ messages in thread
From: Vincent Mailhol via B4 Relay @ 2025-03-25 16:00 UTC (permalink / raw)
To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton
Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Vincent Mailhol
From: Lucas De Marchi <lucas.demarchi@intel.com>
Add some additional tests in lib/tests/test_bits.c to cover the
expected/non-expected values of the fixed-type GENMASK_U*() macros.
Also check that the result value matches the expected type. Since
those are known at build time, use static_assert() instead of normal
kunit tests.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
Changelog:
v7 -> v8:
- In commit db6fe4d61ece ("lib: Move KUnit tests into tests/
subdirectory"), lib/test_bits.c was moved to
lib/tests/test_bits.c. Adjust the patch descrption accordingly.
v6 -> v7:
v5 -> v6:
- No changes.
v4 -> v5:
- Revert v4 change. GENMASK_U8()/GENMASK_U16() are now back to
u8/u16.
v3 -> v4:
- Adjust the type of GENMASK_U8()/GENMASK_U16() from u8/u16 to
unsigned int.
- Reorder the tests to match the order in which the macros are
declared in bits.h.
---
lib/tests/test_bits.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c
index c7b38d91e1f16d42b7ca92e62fbd6c19b37e76a0..f443476f3265c463c1219b13c1ef9663d238d58b 100644
--- a/lib/tests/test_bits.c
+++ b/lib/tests/test_bits.c
@@ -5,6 +5,16 @@
#include <kunit/test.h>
#include <linux/bits.h>
+#include <linux/types.h>
+
+#define assert_type(t, x) _Generic(x, t: x, default: 0)
+
+static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX);
+static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX);
+static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX);
+static_assert(assert_type(u16, GENMASK_U16(15, 0)) == U16_MAX);
+static_assert(assert_type(u32, GENMASK_U32(31, 0)) == U32_MAX);
+static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX);
static void genmask_test(struct kunit *test)
@@ -14,11 +24,21 @@ static void genmask_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, 6ul, GENMASK(2, 1));
KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, GENMASK(31, 0));
+ KUNIT_EXPECT_EQ(test, 1u, GENMASK_U8(0, 0));
+ KUNIT_EXPECT_EQ(test, 3u, GENMASK_U16(1, 0));
+ KUNIT_EXPECT_EQ(test, 0x10000, GENMASK_U32(16, 16));
+
#ifdef TEST_GENMASK_FAILURES
/* these should fail compilation */
GENMASK(0, 1);
GENMASK(0, 10);
GENMASK(9, 10);
+
+ GENMASK_U32(0, 31);
+ GENMASK_U64(64, 0);
+ GENMASK_U32(32, 0);
+ GENMASK_U16(16, 0);
+ GENMASK_U8(8, 0);
#endif
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v8 6/6] test_bits: add tests for BIT_U*()
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
` (4 preceding siblings ...)
2025-03-25 16:00 ` [PATCH v8 5/6] test_bits: add tests for GENMASK_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 16:00 ` Vincent Mailhol via B4 Relay
2025-03-25 16:26 ` Andy Shevchenko
2025-03-26 13:37 ` [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Yury Norov
6 siblings, 1 reply; 13+ messages in thread
From: Vincent Mailhol via B4 Relay @ 2025-03-25 16:00 UTC (permalink / raw)
To: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton
Cc: linux-kernel, intel-gfx, dri-devel, Andi Shyti, David Laight,
Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Vincent Mailhol
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Add some additional tests in lib/tests/test_bits.c to cover the
expected results of the fixed type BIT_U*() macros.
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
Changelog:
v7 -> v8:
- In commit db6fe4d61ece ("lib: Move KUnit tests into tests/
subdirectory"), lib/test_bits.c was moved to
lib/tests/test_bits.c. Adjust the patch descrption accordingly.
v6 -> v7:
- Add Lucas's Reviewed-by tag.
v5 -> v6:
- No changes.
v4 -> v5:
- BIT_U8()/BIT_U16() are now back to u8/u16.
v3 -> v4:
- New patch.
---
lib/tests/test_bits.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c
index f443476f3265c463c1219b13c1ef9663d238d58b..47325b41515fde2c3ed434ed6f4094925c98886b 100644
--- a/lib/tests/test_bits.c
+++ b/lib/tests/test_bits.c
@@ -9,6 +9,16 @@
#define assert_type(t, x) _Generic(x, t: x, default: 0)
+static_assert(assert_type(u8, BIT_U8(0)) == 1u);
+static_assert(assert_type(u16, BIT_U16(0)) == 1u);
+static_assert(assert_type(u32, BIT_U32(0)) == 1u);
+static_assert(assert_type(u64, BIT_U64(0)) == 1ull);
+
+static_assert(assert_type(u8, BIT_U8(7)) == 0x80u);
+static_assert(assert_type(u16, BIT_U16(15)) == 0x8000u);
+static_assert(assert_type(u32, BIT_U32(31)) == 0x80000000u);
+static_assert(assert_type(u64, BIT_U64(63)) == 0x8000000000000000ull);
+
static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX);
static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX);
static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX);
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v8 1/6] bits: add comments and newlines to #if, #else and #endif directives
2025-03-25 15:59 ` [PATCH v8 1/6] bits: add comments and newlines to #if, #else and #endif directives Vincent Mailhol via B4 Relay
@ 2025-03-25 16:20 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-03-25 16:20 UTC (permalink / raw)
To: mailhol.vincent
Cc: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton, linux-kernel, intel-gfx, dri-devel,
Andi Shyti, David Laight, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel
On Wed, Mar 26, 2025 at 12:59:56AM +0900, Vincent Mailhol via B4 Relay wrote:
> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
>
> This is a preparation for the upcoming GENMASK_U*() and BIT_U*()
> changes. After introducing those new macros, there will be a lot of
> scrolling between the #if, #else and #endif.
>
> Add a comment to the #else and #endif preprocessor macros to help keep
> track of which context we are in. Also, add new lines to better
> visually separate the non-asm and asm sections.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Thanks!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v8 2/6] bits: introduce fixed-type GENMASK_U*()
2025-03-25 15:59 ` [PATCH v8 2/6] bits: introduce fixed-type GENMASK_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 16:24 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-03-25 16:24 UTC (permalink / raw)
To: mailhol.vincent
Cc: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton, linux-kernel, intel-gfx, dri-devel,
Andi Shyti, David Laight, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Jani Nikula
On Wed, Mar 26, 2025 at 12:59:57AM +0900, Vincent Mailhol via B4 Relay wrote:
> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
>
> Add GENMASK_TYPE() which generalizes __GENMASK() to support different
> types, and implement fixed-types versions of GENMASK() based on it.
> The fixed-type version allows more strict checks to the min/max values
> accepted, which is useful for defining registers like implemented by
> i915 and xe drivers with their REG_GENMASK*() macros.
>
> The strict checks rely on shift-count-overflow compiler check to fail
-Wshift-count-overflow
but it's not so important here. It's good that it's fixed in the comment.
In any case if Yury wants/can do the change, it might be done when applying.
(I.o.w. no need to resend)
> the build if a number outside of the range allowed is passed.
> Example:
>
> #define FOO_MASK GENMASK_U32(33, 4)
>
> will generate a warning like:
>
> include/linux/bits.h:51:27: error: right shift count >= width of type [-Werror=shift-count-overflow]
> 51 | type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h)))))
> | ^~
>
> The result is casted to the corresponding fixed width type. For
> example, GENMASK_U8() returns an u8. Note that because of the C
> promotion rules, GENMASK_U8() and GENMASK_U16() will immediately be
> promoted to int if used in an expression. Regardless, the main goal is
> not to get the correct type, but rather to enforce more checks at
> compile time.
>
> While GENMASK_TYPE() is crafted to cover all variants, including the
> already existing GENMASK(), GENMASK_ULL() and GENMASK_U128(), for the
> moment, only use it for the newly introduced GENMASK_U*(). The
> consolidation will be done in a separate change.
The change LGTM, FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v8 5/6] test_bits: add tests for GENMASK_U*()
2025-03-25 16:00 ` [PATCH v8 5/6] test_bits: add tests for GENMASK_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 16:26 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-03-25 16:26 UTC (permalink / raw)
To: mailhol.vincent
Cc: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton, linux-kernel, intel-gfx, dri-devel,
Andi Shyti, David Laight, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel
On Wed, Mar 26, 2025 at 01:00:00AM +0900, Vincent Mailhol via B4 Relay wrote:
> From: Lucas De Marchi <lucas.demarchi@intel.com>
>
> Add some additional tests in lib/tests/test_bits.c to cover the
> expected/non-expected values of the fixed-type GENMASK_U*() macros.
>
> Also check that the result value matches the expected type. Since
> those are known at build time, use static_assert() instead of normal
> kunit tests.
New tests always have a green light to go from my point of view,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v8 6/6] test_bits: add tests for BIT_U*()
2025-03-25 16:00 ` [PATCH v8 6/6] test_bits: add tests for BIT_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 16:26 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-03-25 16:26 UTC (permalink / raw)
To: mailhol.vincent
Cc: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton, linux-kernel, intel-gfx, dri-devel,
Andi Shyti, David Laight, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel
On Wed, Mar 26, 2025 at 01:00:01AM +0900, Vincent Mailhol via B4 Relay wrote:
> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
>
> Add some additional tests in lib/tests/test_bits.c to cover the
> expected results of the fixed type BIT_U*() macros.
>
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
New tests always have a green light to go from my point of view,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v8 3/6] bits: introduce fixed-type BIT_U*()
2025-03-25 15:59 ` [PATCH v8 3/6] bits: introduce fixed-type BIT_U*() Vincent Mailhol via B4 Relay
@ 2025-03-25 16:27 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-03-25 16:27 UTC (permalink / raw)
To: mailhol.vincent
Cc: Yury Norov, Lucas De Marchi, Rasmus Villemoes, Jani Nikula,
Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Andrew Morton, linux-kernel, intel-gfx, dri-devel,
Andi Shyti, David Laight, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Jani Nikula
On Wed, Mar 26, 2025 at 12:59:58AM +0900, Vincent Mailhol via B4 Relay wrote:
> From: Lucas De Marchi <lucas.demarchi@intel.com>
>
> Implement fixed-type BIT_U*() to help drivers add stricter checks,
> like it was done for GENMASK_U*().
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*()
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
` (5 preceding siblings ...)
2025-03-25 16:00 ` [PATCH v8 6/6] test_bits: add tests for BIT_U*() Vincent Mailhol via B4 Relay
@ 2025-03-26 13:37 ` Yury Norov
6 siblings, 0 replies; 13+ messages in thread
From: Yury Norov @ 2025-03-26 13:37 UTC (permalink / raw)
To: mailhol.vincent
Cc: Lucas De Marchi, Rasmus Villemoes, Jani Nikula, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
Andrew Morton, linux-kernel, intel-gfx, dri-devel, Andi Shyti,
David Laight, Andy Shevchenko, Catalin Marinas, Anshuman Khandual,
linux-arm-kernel, Jani Nikula
On Wed, Mar 26, 2025 at 12:59:55AM +0900, Vincent Mailhol via B4 Relay wrote:
> Introduce some fixed width variant of the GENMASK() and the BIT()
> macros in bits.h. For example:
>
> GENMASK_U16(16, 0)
>
> will raise a build bug.
>
> This series is a continuation of:
>
> https://lore.kernel.org/intel-xe/20240208074521.577076-1-lucas.demarchi@intel.com
>
> from Lucas De Marchi. Above series is one year old. I really think
> that this was a good idea and I do not want this series to die. So I
> am volunteering to revive it.
>
> Meanwhile, many changes occurred in bits.h. The most significant
> change is that __GENMASK() was moved to the uapi headers. For this
> reason, a new GENMASK_TYPE() is introduced instead and the uapi
> __GENMASK() is left untouched.
>
> Finally, I do not think it makes sense to expose the fixed width
> variants to the asm. The fixed width integers type are a C concept. So
> the GENMASK_U*() are only visible to the non-asm code. For asm, the
> long and long long variants seem sufficient.
>
> This series does not modify the actual GENMASK(), GENMASK_ULL() and
> GENMASK_U128(). A consolidation of the existing genmasks will be
> proposed later on in a separate series.
>
> As requested, here are the bloat-o-meter stats:
>
> $ ./scripts/bloat-o-meter vmlinux_before.o vmlinux_after.o
> add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)
> Function old new delta
> Total: Before=22781662, After=22781662, chg +0.00%
>
> (done with GCC 12.4.1 on an x86_64_defconfig)
Applied, thanks!
>
> --
> 2.43.0
>
> ---
> Changes from v7:
>
> - Meanwhile, in commit db6fe4d61ece ("lib: Move KUnit tests into
> tests/ subdirectory"), lib/test_bits.c was moved to
> lib/tests/test_bits.c. Rebase onto Linus's master branch so that
> this change is reflected.
>
> - Remove the note in the cover letter on the return type, instead
> add an explanation in patch "bits: introduce fixed-type
> GENMASK_U*()".
>
> - s/shift-count-overflow/-Wshift-count-overflow/g
>
> - Link to v7: https://lore.kernel.org/r/20250322-fixed-type-genmasks-v7-0-da380ff1c5b9@wanadoo.fr
>
> Changes from v6:
>
> - Split the series in two: this series leave any existing GENMASK*()
> unmodified. The consolidation will be done in a separate series.
>
> - Collect some Reviewed-by tag.
>
> - Address miscellaneous nitpick on the code comments and the line
> wrapping (details in each patch).
>
> - Link to v6: https://lore.kernel.org/r/20250308-fixed-type-genmasks-v6-0-f59315e73c29@wanadoo.fr
>
> Changes from v5:
>
> - Update the cover letter message. I was still refering to
> GENMASK_t() instead of GENMASK_TYPE().
>
> - Add a comment in the cover letter to explain that a common
> GENMASK_TYPE() for C and asm wouldn't allow to generate the u128
> variant.
>
> - Restore the comment saying that BUILD_BUG_ON() is not available in
> asm code.
>
> - Add a FIXME message to highlight the absence of the asm GENMASK*()
> unit tests.
>
> - Use git's histogram diff algorithm
>
> - Link to v5: https://lore.kernel.org/r/20250306-fixed-type-genmasks-v5-0-b443e9dcba63@wanadoo.fr
>
> Changes from v4:
>
> - Rebase on https://github.com/norov/linux/tree/bitmap-for-next
>
> - Rename GENMASK_t() to GENMASK_TYPE()
>
> - First patch of v4 (the typo fix 'init128' -> 'int128') is removed
> because it was resent separately in:
> https://lore.kernel.org/all/20250305-fix_init128_typo-v1-1-cbe5b8e54e7d@wanadoo.fr
>
> - Replace the (t)~ULL(0) by type_max(t). This way, GENMASK_TYPE()
> can now be used to generate GENMASK_U128().
>
> - Get rid of the unsigned int cast for the U8 and U16 variants.
>
> - Add the BIT_TYPE() helper macro.
>
> - Link to v4: https://lore.kernel.org/r/20250305-fixed-type-genmasks-v4-0-1873dcdf6723@wanadoo.fr
>
> Changes from v3:
>
> - Rebase on v6.14-rc5
>
> - Fix a typo in GENMASK_U128() comment.
>
> - Split the asm and non-asm definition of
>
> - Replace ~0ULL by ~ULL(0)
>
> - Since v3, __GENMASK() was moved to the uapi and people started
> using directly. Introduce GENMASK_t() instead.
>
> - Link to v3: https://lore.kernel.org/intel-xe/20240208074521.577076-1-lucas.demarchi@intel.com
>
> Changes from v2:
>
> - Document both in commit message and code about the strict type
> checking and give examples how it´d break with invalid params.
>
> - Link to v2: https://lore.kernel.org/intel-xe/20240124050205.3646390-1-lucas.demarchi@intel.com
>
> Link to v1: https://lore.kernel.org/intel-xe/20230509051403.2748545-1-lucas.demarchi@intel.com
>
> ---
> Lucas De Marchi (3):
> bits: introduce fixed-type BIT_U*()
> drm/i915: Convert REG_GENMASK*() to fixed-width GENMASK_U*()
> test_bits: add tests for GENMASK_U*()
>
> Vincent Mailhol (3):
> bits: add comments and newlines to #if, #else and #endif directives
> bits: introduce fixed-type GENMASK_U*()
> test_bits: add tests for BIT_U*()
>
> drivers/gpu/drm/i915/i915_reg_defs.h | 108 ++++-------------------------------
> include/linux/bitops.h | 1 -
> include/linux/bits.h | 57 +++++++++++++++++-
> lib/tests/test_bits.c | 30 ++++++++++
> 4 files changed, 96 insertions(+), 100 deletions(-)
> ---
> base-commit: 2df0c02dab829dd89360d98a8a1abaa026ef5798
> change-id: 20250228-fixed-type-genmasks-8d1a555f34e8
>
> Best regards,
> --
> Vincent Mailhol <mailhol.vincent@wanadoo.fr>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-03-26 14:00 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25 15:59 [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Vincent Mailhol via B4 Relay
2025-03-25 15:59 ` [PATCH v8 1/6] bits: add comments and newlines to #if, #else and #endif directives Vincent Mailhol via B4 Relay
2025-03-25 16:20 ` Andy Shevchenko
2025-03-25 15:59 ` [PATCH v8 2/6] bits: introduce fixed-type GENMASK_U*() Vincent Mailhol via B4 Relay
2025-03-25 16:24 ` Andy Shevchenko
2025-03-25 15:59 ` [PATCH v8 3/6] bits: introduce fixed-type BIT_U*() Vincent Mailhol via B4 Relay
2025-03-25 16:27 ` Andy Shevchenko
2025-03-25 15:59 ` [PATCH v8 4/6] drm/i915: Convert REG_GENMASK*() to fixed-width GENMASK_U*() Vincent Mailhol via B4 Relay
2025-03-25 16:00 ` [PATCH v8 5/6] test_bits: add tests for GENMASK_U*() Vincent Mailhol via B4 Relay
2025-03-25 16:26 ` Andy Shevchenko
2025-03-25 16:00 ` [PATCH v8 6/6] test_bits: add tests for BIT_U*() Vincent Mailhol via B4 Relay
2025-03-25 16:26 ` Andy Shevchenko
2025-03-26 13:37 ` [PATCH v8 0/6] bits: Fixed-type GENMASK_U*() and BIT_U*() Yury Norov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).