Commit 8eff4b60 authored by TOKITA Hiroshi's avatar TOKITA Hiroshi Committed by Carles Cufi
Browse files

include: sys: util_macro: add IS_BIT_MASK()/IS_SHIFTED_BIT_MASK()



Add IS_BIT_MASK() macro for determining whether a value is set bits
continuously from the LSB.
This macro is not dependent on bit-width and works in contrast to
BIT_MASK() and BIT64_MASK().
IS_SHIFTED_BIT_MASK() is a version of IS_BIT_MASK() that allows setting
the start bit of continuous bits.

Signed-off-by: default avatarTOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
parent de313d74
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -73,6 +73,23 @@ extern "C" {
 */
#define BIT64_MASK(n) (BIT64(n) - 1ULL)

/**
 * @brief Check if bits are set continuously from the specified bit
 *
 * The macro is not dependent on the bit-width.
 *
 * @param m Check whether the bits are set continuously or not.
 * @param s Specify the lowest bit for that is continuously set bits.
 */
#define IS_SHIFTED_BIT_MASK(m, s) (!(((m) >> (s)) & (((m) >> (s)) + 1U)))

/**
 * @brief Check if bits are set continuously from the LSB.
 *
 * @param m Check whether the bits are set continuously from LSB.
 */
#define IS_BIT_MASK(m) IS_SHIFTED_BIT_MASK(m, 0)

/**
 * @brief Check for macro definition in compiler-visible expressions
 *