ART: Clean up arm64 kNumberOfXRegisters usage.

Avoid undefined behavior for arm64 stemming from 1u << 32 in
loops with upper bound kNumberOfXRegisters.

Create iterators for enumerating bits in an integer either
from high to low or from low to high and use them for
<arch>Context::FillCalleeSaves() on all architectures.

Refactor runtime/utils.{h,cc} by moving all bit-fiddling
functions to runtime/base/bit_utils.{h,cc} (together with
the new bit iterators) and all time-related functions to
runtime/base/time_utils.{h,cc}. Improve test coverage and
fix some corner cases for the bit-fiddling functions.

Bug: 13925192
Change-Id: I704884dab15b41ecf7a1c47d397ab1c3fc7ee0f7
diff --git a/runtime/base/bounded_fifo.h b/runtime/base/bounded_fifo.h
index d04840a..7bcd382 100644
--- a/runtime/base/bounded_fifo.h
+++ b/runtime/base/bounded_fifo.h
@@ -17,16 +17,19 @@
 #ifndef ART_RUNTIME_BASE_BOUNDED_FIFO_H_
 #define ART_RUNTIME_BASE_BOUNDED_FIFO_H_
 
+#include "base/bit_utils.h"
+#include "base/logging.h"
+
 namespace art {
 
 // A bounded fifo is a fifo which has a bounded size. The power of two version uses a bit mask to
 // avoid needing to deal with wrapping integers around or using a modulo operation.
-template <typename T, const size_t MaxSize>
+template <typename T, const size_t kMaxSize>
 class BoundedFifoPowerOfTwo {
+  static_assert(IsPowerOfTwo(kMaxSize), "kMaxSize must be a power of 2.");
+
  public:
   BoundedFifoPowerOfTwo() {
-    // TODO: Do this with a compile time check.
-    CHECK(IsPowerOfTwo(MaxSize));
     clear();
   }
 
@@ -45,7 +48,7 @@
 
   void push_back(const T& value) {
     ++size_;
-    DCHECK_LE(size_, MaxSize);
+    DCHECK_LE(size_, kMaxSize);
     // Relies on integer overflow behavior.
     data_[back_index_++ & mask_] = value;
   }
@@ -61,9 +64,9 @@
   }
 
  private:
-  static const size_t mask_ = MaxSize - 1;
+  static const size_t mask_ = kMaxSize - 1;
   size_t back_index_, size_;
-  T data_[MaxSize];
+  T data_[kMaxSize];
 };
 
 }  // namespace art