mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17217 from maribu/core/bitarithm
core/bitarthm: suppress false positives
This commit is contained in:
commit
69af236d50
@ -172,6 +172,10 @@ static inline unsigned bitarithm_lsb(unsigned v)
|
|||||||
{
|
{
|
||||||
/* Source: http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
|
/* Source: http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
|
||||||
extern const uint8_t MultiplyDeBruijnBitPosition[32];
|
extern const uint8_t MultiplyDeBruijnBitPosition[32];
|
||||||
|
/* cppcheck-suppress oppositeExpression
|
||||||
|
* (reason: `x & -x` is a bit twiddling idiom to extract the LSB; the
|
||||||
|
* check treats opposite arguments as indicator for poor copy-pasting
|
||||||
|
* as e.g. `x + -x` or `x & ~x` don't make sense. ) */
|
||||||
return MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >>
|
return MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >>
|
||||||
27];
|
27];
|
||||||
}
|
}
|
||||||
@ -216,6 +220,10 @@ static inline unsigned bitarithm_test_and_clear(unsigned state, uint8_t *index)
|
|||||||
#elif defined(BITARITHM_LSB_LOOKUP)
|
#elif defined(BITARITHM_LSB_LOOKUP)
|
||||||
/* Source: http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
|
/* Source: http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
|
||||||
extern const uint8_t MultiplyDeBruijnBitPosition[32];
|
extern const uint8_t MultiplyDeBruijnBitPosition[32];
|
||||||
|
/* cppcheck-suppress oppositeExpression
|
||||||
|
* (reason: `x & -x` is a bit twiddling idiom to extract the LSB; the
|
||||||
|
* check treats opposite arguments as indicator for poor copy-pasting
|
||||||
|
* as e.g. `x + -x` or `x & ~x` don't make sense. ) */
|
||||||
uint32_t least_bit = state & -state;
|
uint32_t least_bit = state & -state;
|
||||||
*index = MultiplyDeBruijnBitPosition[(least_bit * 0x077CB531U) >> 27];
|
*index = MultiplyDeBruijnBitPosition[(least_bit * 0x077CB531U) >> 27];
|
||||||
return state & ~least_bit;
|
return state & ~least_bit;
|
||||||
|
Loading…
Reference in New Issue
Block a user