[Mesa-dev] [PATCH 4/7] i965: Add an assert for when SET_FIELD's value exceeds the field size.
Eric Anholt
eric at anholt.net
Mon Dec 23 16:08:56 PST 2013
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
--
1.8.5.1
More information about the mesa-dev
mailing list