summaryrefslogtreecommitdiff
path: root/cesar/lib/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/lib/utils.h')
-rw-r--r--cesar/lib/utils.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/cesar/lib/utils.h b/cesar/lib/utils.h
index 306030ffff..c88c7fd03b 100644
--- a/cesar/lib/utils.h
+++ b/cesar/lib/utils.h
@@ -134,6 +134,17 @@ lesseq_mod2p16 (u16 a, u16 b)
*/
#define BITS_ONES(b) ((1u << ((b) - 1) << 1) - 1)
+/** Return a bit mask composed of a number of LSB ones.
+ * \param b number of one bits, 0 to 32
+ *
+ * - BITS_ONES_OR_ZERO (0) => 0x00000000
+ * - BITS_ONES_OR_ZERO (1) => 0x00000001
+ * - BITS_ONES_OR_ZERO (15) => 0x00007fff
+ * - BITS_ONES_OR_ZERO (32) => 0xffffffff
+ */
+#define BITS_ONES_OR_ZERO(b) ({ typeof (b) _b = (b);\
+ _b ? ((1u << (_b - 1) << 1) - 1) : 0; })
+
/** Return a bit mask composed of a number of LSB ones, corresponding to the
* given bit field.
* \param f bit field define