[PATCH v6 2/7] bits: introduce fixed-type genmasks

Andy Shevchenko andriy.shevchenko at linux.intel.com
Fri Mar 7 17:46:28 UTC 2025


On Sat, Mar 08, 2025 at 01:48:49AM +0900, Vincent Mailhol via B4 Relay wrote:
> From: Yury Norov <yury.norov at gmail.com>
> 
> 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)))))
>         |                           ^~

...

>  /*
>   * Missing asm support
>   *

> + * GENMASK_U*() depends on BITS_PER_TYPE() which relies on sizeof(),

s/depends/depend/ (we are already referring to a plural)

> + * something not available in asm. Nethertheless, fixed width integers
> + * is a C concept. Assembly code can rely on the long and long long
> + * versions instead.
>   */

-- 
With Best Regards,
Andy Shevchenko




More information about the dri-devel mailing list