|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2013 Freie Universität Berlin |
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin |
|
|
|
|
* |
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General |
|
|
|
|
* Public License. See the file LICENSE in the top level directory for more |
|
|
|
@ -21,9 +21,47 @@
|
|
|
|
|
#ifndef BITARITHM_H_ |
|
|
|
|
#define BITARITHM_H_ |
|
|
|
|
|
|
|
|
|
/** @def BS
|
|
|
|
|
* @brief Sets a bitmask |
|
|
|
|
* @param[in] val The value to which the bitmask will be applied |
|
|
|
|
* @param[in] bit The bitmask to be set |
|
|
|
|
* |
|
|
|
|
* @return The applied bitmask |
|
|
|
|
*/ |
|
|
|
|
#define BS(val, bit) ((val) & (bit)) |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def BS_COND |
|
|
|
|
* @brief Conditional setting of a bitmask |
|
|
|
|
* |
|
|
|
|
* @param[in] condition The condition to be checked |
|
|
|
|
* @param[in] target The value to which the bitmask will be applied |
|
|
|
|
* @param[in] mask The bitmask to be set |
|
|
|
|
* |
|
|
|
|
* @return The applied bitmask if *condition* is true |
|
|
|
|
*/ |
|
|
|
|
#define BS_COND(condition, target, mask) (target) ^= ( (-(condition) ^ (target)) & (mask) ) |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def SETBIT |
|
|
|
|
* @brief Sets a single bit in a bitfield |
|
|
|
|
* |
|
|
|
|
* @param[in] val The bitfield |
|
|
|
|
* @param[in] bit Specifies the bit to be set |
|
|
|
|
* |
|
|
|
|
* @return The modified bitfield |
|
|
|
|
*/ |
|
|
|
|
#define SETBIT(val, bit) val |= (bit) |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @def CLRBIT |
|
|
|
|
* @brief Clears a single bit in a bitfield |
|
|
|
|
* |
|
|
|
|
* @param[in] val The bitfield |
|
|
|
|
* @param[in] bit Specifies the bit to be cleared |
|
|
|
|
* |
|
|
|
|
* @return The modified bitfield |
|
|
|
|
*/ |
|
|
|
|
#define CLRBIT(val, bit) val &= (~(bit)) |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -68,7 +106,7 @@
|
|
|
|
|
#endif |
|
|
|
|
/** @} */ |
|
|
|
|
|
|
|
|
|
#define ARCH_32_BIT (__INT_MAX__ == 2147483647) |
|
|
|
|
#define ARCH_32_BIT (__INT_MAX__ == 2147483647) /**< 1 for 32 bit architectures, 0 otherwise */ |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Returns the number of the highest '1' bit in a value |
|
|
|
@ -98,5 +136,5 @@ unsigned number_of_lowest_bit(register unsigned v);
|
|
|
|
|
*/ |
|
|
|
|
unsigned number_of_bits_set(unsigned v); |
|
|
|
|
|
|
|
|
|
/** @} */ |
|
|
|
|
#endif /* BITARITHM_H_ */ |
|
|
|
|
/** @} */ |
|
|
|
|