Add the implementation for the ARM assembler.
Change-Id: Iabeb834c3cc2b00a043bd79f9e1c4573d0f0a934
diff --git a/src/utils.h b/src/utils.h
index 96ce02f..a8bf3e7 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -7,6 +7,24 @@
namespace art {
+template<typename T>
+static inline bool IsPowerOfTwo(T x) {
+ return (x & (x - 1)) == 0;
+}
+
+
+template<typename T>
+static inline bool IsAligned(T x, int n) {
+ CHECK(IsPowerOfTwo(n));
+ return (x & (n - 1)) == 0;
+}
+
+
+template<typename T>
+static inline bool IsAligned(T* x, int n) {
+ return IsAligned(reinterpret_cast<uintptr_t>(x), n);
+}
+
// Check whether an N-bit two's-complement representation can hold value.
static inline bool IsInt(int N, word value) {
CHECK_LT(0, N);
@@ -16,12 +34,6 @@
}
-template<typename T>
-static inline bool IsPowerOfTwo(T x) {
- return (x & (x - 1)) == 0;
-}
-
-
static inline bool IsUint(int N, word value) {
CHECK_LT(0, N);
CHECK_LT(N, kBitsPerWord);
@@ -30,6 +42,14 @@
}
+static inline bool IsAbsoluteUint(int N, word value) {
+ CHECK_LT(0, N);
+ CHECK_LT(N, kBitsPerWord);
+ if (value < 0) value = -value;
+ return IsUint(N, value);
+}
+
+
static inline int32_t Low32Bits(int64_t value) {
return static_cast<int32_t>(value);
}
@@ -39,6 +59,17 @@
return static_cast<int32_t>(value >> 32);
}
+// Implementation is from "Hacker's Delight" by Henry S. Warren, Jr.,
+// figure 5-2, page 66, where the function is called pop.
+static inline int CountOneBits(uint32_t x) {
+ x = x - ((x >> 1) & 0x55555555);
+ x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
+ x = (x + (x >> 4)) & 0x0F0F0F0F;
+ x = x + (x >> 8);
+ x = x + (x >> 16);
+ return static_cast<int>(x & 0x0000003F);
+}
+
} // namespace art
#endif // ART_SRC_UTILS_H_