mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #310 from OlegHahm/revert_bitarithm
reverted 18e97f6dd5
This commit is contained in:
commit
4bdec3af78
@ -11,7 +11,6 @@
|
|||||||
* \{
|
* \{
|
||||||
* \file
|
* \file
|
||||||
* \author Kaspar Schleiser <kaspar@schleiser.de>
|
* \author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
* \author Martin Lenders <mlenders@inf.fu-berlin.de>
|
|
||||||
* \}
|
* \}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -40,3 +39,29 @@ number_of_highest_bit(unsigned v)
|
|||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
unsigned
|
||||||
|
number_of_lowest_bit(register unsigned v)
|
||||||
|
{
|
||||||
|
register unsigned r = 0;
|
||||||
|
|
||||||
|
while ((v & 0x01) == 0) {
|
||||||
|
v >>= 1;
|
||||||
|
r++;
|
||||||
|
};
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
unsigned
|
||||||
|
number_of_bits_set(unsigned v)
|
||||||
|
{
|
||||||
|
unsigned c; // c accumulates the total bits set in v
|
||||||
|
|
||||||
|
for (c = 0; v; c++) {
|
||||||
|
v &= v - 1; // clear the least significant bit set
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
* @file
|
* @file
|
||||||
* @author Freie Universität Berlin, Computer Systems & Telematics
|
* @author Freie Universität Berlin, Computer Systems & Telematics
|
||||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BITARITHM_H_
|
#ifndef BITARITHM_H_
|
||||||
@ -79,17 +78,22 @@ unsigned number_of_highest_bit(unsigned v);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the number of the lowest '1' bit in a value
|
* @brief Returns the number of the lowest '1' bit in a value
|
||||||
* @param[in] v Input value
|
* @param[in] v Input value - must be unequal to '0', otherwise the
|
||||||
* @return Bit Number, 0 for least significant bit, -1 if input is 0
|
* function will produce an infinite loop
|
||||||
|
* @return Bit Number
|
||||||
|
*
|
||||||
|
* Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
|
||||||
*/
|
*/
|
||||||
#define number_of_lowest_bit(v) (__builtin_ffs(v)-1)
|
unsigned number_of_lowest_bit(register unsigned v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the number of bits set in a value
|
* @brief Returns the number of bits set in a value
|
||||||
* @param[in] v Input value
|
* @param[in] v Input value
|
||||||
* @return Number of set bits
|
* @return Number of set bits
|
||||||
|
*
|
||||||
|
* Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
|
||||||
*/
|
*/
|
||||||
#define number_of_bits_set(v) (__builtin_popcount(v))
|
unsigned number_of_bits_set(unsigned v);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
Loading…
Reference in New Issue
Block a user