[Mesa-dev] [PATCH 4/7] i965: Add an assert for when SET_FIELD's value exceeds the field size.

Kenneth Graunke kenneth at whitecape.org
Mon Jan 6 12:27:03 PST 2014


On 12/23/2013 04:08 PM, Eric Anholt wrote:
> This was one of the things we always wanted to do to this, to make it more
> useful than just (value << FIELD_MASK).
> ---
>  src/mesa/drivers/dri/i965/brw_defines.h | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h
> index dc38ace..21a97a9 100644
> --- a/src/mesa/drivers/dri/i965/brw_defines.h
> +++ b/src/mesa/drivers/dri/i965/brw_defines.h
> @@ -30,7 +30,13 @@
>    */
>  
>  #define INTEL_MASK(high, low) (((1<<((high)-(low)+1))-1)<<(low))
> -#define SET_FIELD(value, field) (((value) << field ## _SHIFT) & field ## _MASK)
> +#define SET_FIELD(value, field)                                         \
> +   ({                                                                   \
> +      uint32_t fieldval = (value) << field ## _SHIFT;                   \
> +      assert((fieldval & ~ field ## _MASK) == 0);                       \
> +      fieldval & field ## _MASK;                                        \
> +   })
> +
>  #define GET_FIELD(word, field) (((word)  & field ## _MASK) >> field ## _SHIFT)
>  
>  #ifndef BRW_DEFINES_H

Whoa.  This is some crazy language extension.

However, it appears to be supported by GCC, Clang, and (according to
Google) Sun Studio 12.

I might add a comment:
/* Using the GNU statement expression extension */

Otherwise, this series is:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>


More information about the mesa-dev mailing list