i965: Add an assert for when SET_FIELD's value exceeds the field size.
authorEric Anholt <eric@anholt.net>
Mon, 23 Dec 2013 09:39:42 +0000 (01:39 -0800)
committerEric Anholt <eric@anholt.net>
Thu, 9 Jan 2014 07:23:27 +0000 (15:23 +0800)
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 <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/mesa/drivers/dri/i965/brw_defines.h

index 0fc24a7ede99341e615d42585cfa69740f750a05..78df0b896727978c98015e1192cab4012257e3d4 100644 (file)
   */
 
 #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