[Intel-gfx] [PATCH] drm/i915: make REG_BIT() and REG_GENMASK() work with variables
Chris Wilson
chris at chris-wilson.co.uk
Fri May 24 19:43:42 UTC 2019
Quoting Jani Nikula (2019-05-24 19:52:53)
> REG_BIT() and REG_GENMASK() were intended to work with both constant
> expressions and otherwise, with the former having extra compile time
> checks for the bit ranges. Incredibly, the result of
> __builtin_constant_p() is not an integer constant expression when given
> a non-constant expression, leading to errors in BUILD_BUG_ON_ZERO().
>
> Replace __builtin_constant_p() with the __is_constexpr() magic spell.
>
> Reported-by: Ville Syrjala <ville.syrjala at linux.intel.com>
> Signed-off-by: Jani Nikula <jani.nikula at intel.com>
> ---
> drivers/gpu/drm/i915/i915_reg.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
> index 49dce04dd688..019c48748dc9 100644
> --- a/drivers/gpu/drm/i915/i915_reg.h
> +++ b/drivers/gpu/drm/i915/i915_reg.h
> @@ -126,7 +126,7 @@
> */
> #define REG_BIT(__n) \
> ((u32)(BIT(__n) + \
> - BUILD_BUG_ON_ZERO(__builtin_constant_p(__n) && \
> + BUILD_BUG_ON_ZERO(__is_constexpr(__n) && \
> ((__n) < 0 || (__n) > 31))))
>
> /**
> @@ -140,8 +140,8 @@
> */
> #define REG_GENMASK(__high, __low) \
> ((u32)(GENMASK(__high, __low) + \
> - BUILD_BUG_ON_ZERO(__builtin_constant_p(__high) && \
> - __builtin_constant_p(__low) && \
> + BUILD_BUG_ON_ZERO(__is_constexpr(__high) && \
> + __is_constexpr(__low) && \
> ((__low) < 0 || (__high) > 31 || (__low) > (__high)))))
Ok, one old one remaining in _MASKED_FIELD().
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
-Chris
More information about the Intel-gfx
mailing list