diff options
Diffstat (limited to 'src/support/bits.h')
-rw-r--r-- | src/support/bits.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/support/bits.h b/src/support/bits.h index 1fba58bf1..73d71e804 100644 --- a/src/support/bits.h +++ b/src/support/bits.h @@ -29,6 +29,9 @@ * * We instead use portable and reasonably-fast implementations, while * avoiding implementations with large lookup tables. + * + * TODO: The convention here should be changed PopCount => popCount, + * initial lowercase, to match the rest of the codebase. */ namespace wasm { @@ -65,6 +68,10 @@ template <typename T> int CountLeadingZeroes(T v) { return CountLeadingZeroes(typename std::make_unsigned<T>::type(v)); } +template <typename T> +bool IsPowerOf2(T v) { + return v != 0 && PopCount(v) == 1; +} template <typename T, typename U> inline static T RotateLeft(T val, U count) { |