OLD | NEW |
1 //===- subzero/src/IceUtils.h - Utility functions ---------------*- C++ -*-===// | 1 //===- subzero/src/IceUtils.h - Utility functions ---------------*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file declares some utility functions. | 10 // This file declares some utility functions. |
(...skipping 13 matching lines...) Expand all Loading... |
24 // virtually useless. | 24 // virtually useless. |
25 template <class D, class S> inline D bit_copy(const S &source) { | 25 template <class D, class S> inline D bit_copy(const S &source) { |
26 D destination; | 26 D destination; |
27 // This use of memcpy is safe: source and destination cannot overlap. | 27 // This use of memcpy is safe: source and destination cannot overlap. |
28 memcpy(&destination, reinterpret_cast<const void *>(&source), | 28 memcpy(&destination, reinterpret_cast<const void *>(&source), |
29 sizeof(destination)); | 29 sizeof(destination)); |
30 return destination; | 30 return destination; |
31 } | 31 } |
32 | 32 |
33 class Utils { | 33 class Utils { |
| 34 Utils() = delete; |
| 35 Utils(const Utils &) = delete; |
| 36 Utils &operator=(const Utils &) = delete; |
| 37 |
34 public: | 38 public: |
35 // Check whether an N-bit two's-complement representation can hold value. | 39 // Check whether an N-bit two's-complement representation can hold value. |
36 template <typename T> static inline bool IsInt(int N, T value) { | 40 template <typename T> static inline bool IsInt(int N, T value) { |
37 assert((0 < N) && | 41 assert((0 < N) && |
38 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value)))); | 42 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value)))); |
39 T limit = static_cast<T>(1) << (N - 1); | 43 T limit = static_cast<T>(1) << (N - 1); |
40 return (-limit <= value) && (value < limit); | 44 return (-limit <= value) && (value < limit); |
41 } | 45 } |
42 | 46 |
43 template <typename T> static inline bool IsUint(int N, T value) { | 47 template <typename T> static inline bool IsUint(int N, T value) { |
(...skipping 13 matching lines...) Expand all Loading... |
57 uint64_t Mod = Pos & (Align - 1); | 61 uint64_t Mod = Pos & (Align - 1); |
58 if (Mod == 0) | 62 if (Mod == 0) |
59 return 0; | 63 return 0; |
60 return Align - Mod; | 64 return Align - Mod; |
61 } | 65 } |
62 }; | 66 }; |
63 | 67 |
64 } // end of namespace Ice | 68 } // end of namespace Ice |
65 | 69 |
66 #endif // SUBZERO_SRC_ICEUTILS_H | 70 #endif // SUBZERO_SRC_ICEUTILS_H |
OLD | NEW |