OLD | NEW |
---|---|
(Empty) | |
1 //===- subzero/src/IceUtils.h - Utility functions ---------------*- C++ -*-===// | |
2 // | |
3 // The Subzero Code Generator | |
4 // | |
5 // This file is distributed under the University of Illinois Open Source | |
6 // License. See LICENSE.TXT for details. | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 // | |
10 // This file declares some utility functions | |
11 // | |
12 //===----------------------------------------------------------------------===// | |
13 | |
14 #ifndef SUBZERO_SRC_ICEUTILS_H | |
15 #define SUBZERO_SRC_ICEUTILS_H | |
16 | |
17 #include <climits> | |
18 | |
19 namespace Ice { | |
20 | |
21 // TODO(jvoung): why are labels offset by this? | |
22 const uint32_t kWordSize = sizeof(intptr_t); | |
Jim Stichnoth
2014/09/09 14:58:41
It's hard to search the patchsets for uses of kWor
jvoung (off chromium)
2014/09/15 17:19:15
I moved this to the one place it's being used, whi
| |
23 | |
24 // Similar to bit_cast, but allows copying from types of unrelated | |
25 // sizes. This method was introduced to enable the strict aliasing | |
26 // optimizations of GCC 4.4. Basically, GCC mindlessly relies on | |
27 // obscure details in the C++ standard that make reinterpret_cast | |
28 // virtually useless. | |
29 template <class D, class S> inline D bit_copy(const S &source) { | |
30 D destination; | |
31 // This use of memcpy is safe: source and destination cannot overlap. | |
32 memcpy(&destination, reinterpret_cast<const void *>(&source), | |
33 sizeof(destination)); | |
34 return destination; | |
35 } | |
36 | |
37 class Utils { | |
38 public: | |
39 // Check whether an N-bit two's-complement representation can hold value. | |
40 template <typename T> static inline bool IsInt(int N, T value) { | |
41 assert((0 < N) && | |
42 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value)))); | |
Jim Stichnoth
2014/09/09 14:58:42
Same comment as above - is this CHAR_BIT, or the t
jvoung (off chromium)
2014/09/15 17:19:15
I think this is plain CHAR_BIT, since it's used al
| |
43 T limit = static_cast<T>(1) << (N - 1); | |
44 return (-limit <= value) && (value < limit); | |
45 } | |
46 | |
47 template <typename T> static inline bool IsUint(int N, T value) { | |
48 assert((0 < N) && | |
49 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value)))); | |
50 T limit = static_cast<T>(1) << N; | |
51 return (0 <= value) && (value < limit); | |
52 } | |
53 }; | |
54 | |
55 } // end of namespace Ice | |
56 | |
57 #endif // SUBZERO_SRC_ICEUTILS_H | |
OLD | NEW |