diff options
author | Timothy Arceri <[email protected]> | 2019-02-06 12:18:52 +1100 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2019-02-08 02:54:56 +0000 |
commit | d0abbaa528a0b23999079951c88effb3f2c0d27a (patch) | |
tree | acdb34afda6c33e789a68649a534f0107349b2ed /src/util | |
parent | cbd1ad6165f0aea7fb7c6fd1b36ad5317dd65cb7 (diff) |
util: move BITFIELD macros to util/macros.h
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/macros.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util/macros.h b/src/util/macros.h index c47bbb6dfcd..73d4e68b99a 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -296,4 +296,22 @@ do { \ #define EXPLICIT_CONVERSION #endif +/** Set a single bit */ +#define BITFIELD_BIT(b) (1u << (b)) +/** Set all bits up to excluding bit b */ +#define BITFIELD_MASK(b) \ + ((b) == 32 ? (~0u) : BITFIELD_BIT((b) % 32) - 1) +/** Set count bits starting from bit b */ +#define BITFIELD_RANGE(b, count) \ + (BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b)) + +/** Set a single bit */ +#define BITFIELD64_BIT(b) (1ull << (b)) +/** Set all bits up to excluding bit b */ +#define BITFIELD64_MASK(b) \ + ((b) == 64 ? (~0ull) : BITFIELD64_BIT(b) - 1) +/** Set count bits starting from bit b */ +#define BITFIELD64_RANGE(b, count) \ + (BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b)) + #endif /* UTIL_MACROS_H */ |