summaryrefslogtreecommitdiff
path: root/src/support
diff options
context:
space:
mode:
Diffstat (limited to 'src/support')
-rw-r--r--src/support/bits.h7
-rw-r--r--src/support/utilities.h8
2 files changed, 10 insertions, 5 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) {
diff --git a/src/support/utilities.h b/src/support/utilities.h
index 66e7ed797..a2fff7f0a 100644
--- a/src/support/utilities.h
+++ b/src/support/utilities.h
@@ -26,6 +26,8 @@
#include <iostream>
#include <type_traits>
+#include "support/bits.h"
+
namespace wasm {
// Type punning needs to be done through this function to avoid undefined
@@ -41,12 +43,8 @@ inline Destination bit_cast(const Source& source) {
return destination;
}
-inline bool isPowerOf2(uint32_t v) {
- return v && !(v & (v - 1));
-}
-
inline size_t alignAddr(size_t address, size_t alignment) {
- assert(alignment && isPowerOf2((uint32_t)alignment) &&
+ assert(alignment && IsPowerOf2((uint32_t)alignment) &&
"Alignment is not a power of two!");
assert(address + alignment - 1 >= address);