blob: 6f38e7fe01825b3f540a778ce68e4cc92f77062c [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
8namespace android {
9namespace runtime {
10
11// Check whether an N-bit two's-complement representation can hold value.
12static 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
20template<typename T>
21static inline bool IsPowerOfTwo(T x) {
22 return (x & (x - 1)) == 0;
23}
24
25
26static 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
34static inline int32_t Low32Bits(int64_t value) {
35 return static_cast<int32_t>(value);
36}
37
38
39static 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_