mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-03 10:50:26 +01:00
util: add new ASSERT_BITFIELD_SIZE() macro (v3)
For checking that bitfields are large enough to hold the largest expected value. v2: move into existing util/macros.h header where STATIC_ASSERT() lives. v3: add MAYBE_UNUSED to variable declaration Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
parent
c8ce3c2689
commit
fe81e1f975
1 changed files with 17 additions and 0 deletions
|
|
@ -241,6 +241,23 @@ do { \
|
|||
#define ATTRIBUTE_NOINLINE
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Check that STRUCT::FIELD can hold MAXVAL. We use a lot of bitfields
|
||||
* in Mesa/gallium. We have to be sure they're of sufficient size to
|
||||
* hold the largest expected value.
|
||||
* Note that with MSVC, enums are signed and enum bitfields need one extra
|
||||
* high bit (always zero) to ensure the max value is handled correctly.
|
||||
* This macro will detect that with MSVC, but not GCC.
|
||||
*/
|
||||
#define ASSERT_BITFIELD_SIZE(STRUCT, FIELD, MAXVAL) \
|
||||
do { \
|
||||
MAYBE_UNUSED STRUCT s; \
|
||||
s.FIELD = (MAXVAL); \
|
||||
assert((int) s.FIELD == (MAXVAL) && "Insufficient bitfield size!"); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/** Compute ceiling of integer quotient of A divided by B. */
|
||||
#define DIV_ROUND_UP( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue