1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

core/bitarthm: suppress false positives

Co-authored-by: chrysn <chrysn@fsfe.org>
This commit is contained in:
Marian Buschsieweke 2021-11-16 15:58:23 +01:00
parent 69dadf61e9
commit d7a0ea1eec
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94

View File

@ -172,6 +172,10 @@ static inline unsigned bitarithm_lsb(unsigned v)
{
/* Source: http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
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)) >>
27];
}
@ -216,6 +220,10 @@ static inline unsigned bitarithm_test_and_clear(unsigned state, uint8_t *index)
#elif defined(BITARITHM_LSB_LOOKUP)
/* Source: http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
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;
*index = MultiplyDeBruijnBitPosition[(least_bit * 0x077CB531U) >> 27];
return state & ~least_bit;