From: Eric Anholt Date: Mon, 23 Dec 2013 09:39:42 +0000 (-0800) Subject: i965: Add an assert for when SET_FIELD's value exceeds the field size. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5d2e86924ebe7b520a5964e9c90c5bb7213c67cf;p=mesa.git i965: Add an assert for when SET_FIELD's value exceeds the field size. This was one of the things we always wanted to do to this, to make it more useful than just (value << FIELD_MASK). Reviewed-by: Kenneth Graunke Reviewed-by: Ian Romanick Reviewed-by: Anuj Phogat --- diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h index 0fc24a7ede9..78df0b89672 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