intel/eu: Define SET_BITS helper more easily reusable than SET_FIELD.
authorFrancisco Jerez <currojerez@riseup.net>
Mon, 25 Jun 2018 19:06:50 +0000 (12:06 -0700)
committerFrancisco Jerez <currojerez@riseup.net>
Tue, 10 Jul 2018 06:46:57 +0000 (23:46 -0700)
Allows to specify a bitfield based on its upper and lower bounds
instead of a symbolic field definition, kind of what the current
GET_BITS macro is to GET_FIELD.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/intel/compiler/brw_eu_defines.h

index f6d771d153414e26a180e6bb7a904c502b0d240b..fb8caa60715106c6df409c6cdebd02878c15fd62 100644 (file)
       fieldval & field ## _MASK;                                        \
    })
 
+#define SET_BITS(value, high, low)                                      \
+   ({                                                                   \
+      const uint32_t fieldval = (value) << (low);                       \
+      assert((fieldval & ~INTEL_MASK(high, low)) == 0);                 \
+      fieldval & INTEL_MASK(high, low);                                 \
+   })
+
 #define GET_BITS(data, high, low) ((data & INTEL_MASK((high), (low))) >> (low))
 #define GET_FIELD(word, field) (((word)  & field ## _MASK) >> field ## _SHIFT)