Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame^] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_UTILS_H_ |
| 4 | #define ART_SRC_UTILS_H_ |
| 5 | |
| 6 | #include "src/globals.h" |
| 7 | |
| 8 | namespace android { |
| 9 | namespace runtime { |
| 10 | |
| 11 | // Check whether an N-bit two's-complement representation can hold value. |
| 12 | static inline bool IsInt(int N, word value) { |
| 13 | CHECK_LT(0, N); |
| 14 | CHECK_LT(N, kBitsPerWord); |
| 15 | word limit = static_cast<word>(1) << (N - 1); |
| 16 | return (-limit <= value) && (value < limit); |
| 17 | } |
| 18 | |
| 19 | |
| 20 | template<typename T> |
| 21 | static inline bool IsPowerOfTwo(T x) { |
| 22 | return (x & (x - 1)) == 0; |
| 23 | } |
| 24 | |
| 25 | |
| 26 | static inline bool IsUint(int N, word value) { |
| 27 | CHECK_LT(0, N); |
| 28 | CHECK_LT(N, kBitsPerWord); |
| 29 | word limit = static_cast<word>(1) << N; |
| 30 | return (0 <= value) && (value < limit); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | static inline int32_t Low32Bits(int64_t value) { |
| 35 | return static_cast<int32_t>(value); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | static inline int32_t High32Bits(int64_t value) { |
| 40 | return static_cast<int32_t>(value >> 32); |
| 41 | } |
| 42 | |
| 43 | } } // namespace android::runtime |
| 44 | |
| 45 | #endif // ART_SRC_UTILS_H_ |