blob: 96ce02fa4ae9ce6f2f01013903fdf0dcaeba4670 [file] [log] [blame]
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001// 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 Shapiro6b6b5f02011-06-21 15:05:09 -07008namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07009
10// Check whether an N-bit two's-complement representation can hold value.
11static 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
19template<typename T>
20static inline bool IsPowerOfTwo(T x) {
21 return (x & (x - 1)) == 0;
22}
23
24
25static 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
33static inline int32_t Low32Bits(int64_t value) {
34 return static_cast<int32_t>(value);
35}
36
37
38static inline int32_t High32Bits(int64_t value) {
39 return static_cast<int32_t>(value >> 32);
40}
41
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070042} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070043
44#endif // ART_SRC_UTILS_H_