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 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame^] | 8 | namespace art { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 9 | |
| 10 | // Check whether an N-bit two's-complement representation can hold value. |
| 11 | static inline bool IsInt(int N, word value) { |
| 12 | CHECK_LT(0, N); |
| 13 | CHECK_LT(N, kBitsPerWord); |
| 14 | word limit = static_cast<word>(1) << (N - 1); |
| 15 | return (-limit <= value) && (value < limit); |
| 16 | } |
| 17 | |
| 18 | |
| 19 | template<typename T> |
| 20 | static inline bool IsPowerOfTwo(T x) { |
| 21 | return (x & (x - 1)) == 0; |
| 22 | } |
| 23 | |
| 24 | |
| 25 | static inline bool IsUint(int N, word value) { |
| 26 | CHECK_LT(0, N); |
| 27 | CHECK_LT(N, kBitsPerWord); |
| 28 | word limit = static_cast<word>(1) << N; |
| 29 | return (0 <= value) && (value < limit); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | static inline int32_t Low32Bits(int64_t value) { |
| 34 | return static_cast<int32_t>(value); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | static inline int32_t High32Bits(int64_t value) { |
| 39 | return static_cast<int32_t>(value >> 32); |
| 40 | } |
| 41 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame^] | 42 | } // namespace art |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 43 | |
| 44 | #endif // ART_SRC_UTILS_H_ |