Skip to content

Commit

Permalink
Merge pull request #688 from LebedevRI/numActiveBits-widen
Browse files Browse the repository at this point in the history
numActiveBits(): explicitly widen to at least 32 bits (OlympusDecompressor -1%)
  • Loading branch information
LebedevRI authored Feb 29, 2024
2 parents 16885d2 + 6c0d365 commit 65c4cc3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librawspeed/adt/Bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ unsigned numSignBits(const T v) {
}

template <class T>
requires std::unsigned_integral<T>
requires(std::unsigned_integral<T> && bitwidth<T>() >= bitwidth<uint32_t>())
unsigned numActiveBits(const T v) {
return bitwidth(v) - std::countl_zero(v);
}

template <class T>
requires(std::unsigned_integral<T> && bitwidth<T>() < bitwidth<uint32_t>())
unsigned numActiveBits(const T v) {
return numActiveBits(static_cast<uint32_t>(v));
}

template <class T>
requires std::unsigned_integral<T>
unsigned numSignificantBits(const T v) {
Expand Down

0 comments on commit 65c4cc3

Please sign in to comment.