1
0
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:
chrysn 2021-11-18 10:31:21 +01:00 committed by GitHub
commit 69af236d50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;