Re: [PATCH v4 3/8] bits: introduce fixed-type genmasks

Andy Shevchenko
2025-03-05T14:30:15Z

On Wed, Mar 05, 2025 at 10:00:15PM +0900, Vincent Mailhol via B4 Relay wrote:
> From: Yury Norov <yury.norov@gmail.com>
>
> Add __GENMASK_t() which generalizes __GENMASK() to support different

Is it with double underscore? I do not see it.

_t is used for typedef simple types. It's unfortunate to have it
in such a macro. Perhaps T or TYPE will suffice. Or perhaps we want
__GENMASK_Uxx() here?

> 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:41:31: error: left shift count >= width of type [-Werror=shift-count-overflow]
> 41 | (((t)~0ULL - ((t)(1) << (l)) + 1) & \
> | ^~

...

> + * __GENMASK_U*() depends on BITS_PER_TYPE() which would not work in the asm

Where are the double underscore variants? I see it only for U128.

> + * code as BITS_PER_TYPE() relies on sizeof(), something not available in
> + * asm. Nethertheless, the concept of fixed width integers is a C thing which
> + * does not apply to assembly code.

--
With Best Regards,
Andy Shevchenko