Add D/CHECK_CONSTEXPR macros for use in constexpr context.
Make most RegStorage methods constexpr, make StorageSize()
const.
Change-Id: Ie63faa3b081094b3dd30352c6240fdf10ef8b87e
diff --git a/runtime/base/logging.h b/runtime/base/logging.h
index 814195c..caeb946 100644
--- a/runtime/base/logging.h
+++ b/runtime/base/logging.h
@@ -66,6 +66,16 @@
} \
} while (false)
+// CHECK that can be used in a constexpr function. For example,
+// constexpr int half(int n) {
+// return
+// DCHECK_CONSTEXPR(n >= 0, , 0)
+// CHECK_CONSTEXPR((n & 1) == 0), << "Extra debugging output: n = " << n, 0)
+// n / 2;
+// }
+#define CHECK_CONSTEXPR(x, out, dummy) \
+ (UNLIKELY(!(x))) ? (LOG(FATAL) << "Check failed: " << #x out, dummy) :
+
#ifndef NDEBUG
#define DCHECK(x) CHECK(x)
@@ -77,6 +87,7 @@
#define DCHECK_GT(x, y) CHECK_GT(x, y)
#define DCHECK_STREQ(s1, s2) CHECK_STREQ(s1, s2)
#define DCHECK_STRNE(s1, s2) CHECK_STRNE(s1, s2)
+#define DCHECK_CONSTEXPR(x, out, dummy) CHECK_CONSTEXPR(x, out, dummy)
#else // NDEBUG
@@ -116,6 +127,9 @@
while (false) \
CHECK_STRNE(str1, str2)
+#define DCHECK_CONSTEXPR(x, out, dummy) \
+ (false && (x)) ? (dummy) :
+
#endif
#define LOG(severity) ::art::LogMessage(__FILE__, __LINE__, severity, -1).stream()
diff --git a/runtime/utils.h b/runtime/utils.h
index 6a4198f..6d52459 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -140,9 +140,8 @@
template<typename T>
static constexpr T RoundDown(T x, typename TypeIdentity<T>::type n) {
return
- // DCHECK(IsPowerOfTwo(n)) in a form acceptable in a constexpr function:
- (kIsDebugBuild && !IsPowerOfTwo(n)) ? (LOG(FATAL) << n << " isn't a power of 2", T(0))
- : (x & -n);
+ DCHECK_CONSTEXPR(IsPowerOfTwo(n), , T(0))
+ (x & -n);
}
template<typename T>