summaryrefslogtreecommitdiffstats
path: root/runtime/utils.h
diff options
context:
space:
mode:
authorDavid Brazdil <dbrazdil@google.com>2015-03-27 10:31:38 +0000
committerDavid Brazdil <dbrazdil@google.com>2015-03-27 11:02:20 +0000
commitf6468109a49aff6e4a1d28787de625bfb214a761 (patch)
treea662906fca20ace8fb42ebe4872822d00015596c /runtime/utils.h
parent03910065cd025ecb07781b85c2240be69c202d75 (diff)
downloadart-f6468109a49aff6e4a1d28787de625bfb214a761.tar.gz
art-f6468109a49aff6e4a1d28787de625bfb214a761.tar.bz2
art-f6468109a49aff6e4a1d28787de625bfb214a761.zip
ART: Fix IsInt when N==32, add tests
Implicit type conversion caused IsInt to always return true for N==32 on 32-bit platforms. This patch templetizes the function to avoid the conversion and adds tests of this and similar functions. Change-Id: Ie526b68b7c3e7cb7b658253d51840794224785fe
Diffstat (limited to 'runtime/utils.h')
-rw-r--r--runtime/utils.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/runtime/utils.h b/runtime/utils.h
index 1a7fdfb4dc..e6a6b1dfad 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -109,12 +109,17 @@ static inline bool IsAlignedParam(T x, int n) {
DCHECK(::art::IsAlignedParam(value, alignment)) << reinterpret_cast<const void*>(value)
// Check whether an N-bit two's-complement representation can hold value.
-static inline bool IsInt(int N, intptr_t value) {
- if (N == kBitsPerIntPtrT) return true;
- CHECK_LT(0, N);
- CHECK_LT(N, kBitsPerIntPtrT);
- intptr_t limit = static_cast<intptr_t>(1) << (N - 1);
- return (-limit <= value) && (value < limit);
+template <typename T>
+static inline bool IsInt(int N, T value) {
+ int bitsPerT = sizeof(T) * kBitsPerByte;
+ if (N == bitsPerT) {
+ return true;
+ } else {
+ CHECK_LT(0, N);
+ CHECK_LT(N, bitsPerT);
+ T limit = static_cast<T>(1) << (N - 1);
+ return (-limit <= value) && (value < limit);
+ }
}
template <typename T>