summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2019-02-06 12:18:52 +1100
committerTimothy Arceri <[email protected]>2019-02-08 02:54:56 +0000
commitd0abbaa528a0b23999079951c88effb3f2c0d27a (patch)
treeacdb34afda6c33e789a68649a534f0107349b2ed /src/util
parentcbd1ad6165f0aea7fb7c6fd1b36ad5317dd65cb7 (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.h18
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 */