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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 assert((0 < N) && | 46 assert((0 < N) && |
47 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value)))); | 47 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value)))); |
48 T limit = static_cast<T>(1) << N; | 48 T limit = static_cast<T>(1) << N; |
49 return (0 <= value) && (value < limit); | 49 return (0 <= value) && (value < limit); |
50 } | 50 } |
51 | 51 |
52 template <typename T> static inline bool WouldOverflowAdd(T X, T Y) { | 52 template <typename T> static inline bool WouldOverflowAdd(T X, T Y) { |
53 return ((X > 0 && Y > 0 && (X > std::numeric_limits<T>::max() - Y)) || | 53 return ((X > 0 && Y > 0 && (X > std::numeric_limits<T>::max() - Y)) || |
54 (X < 0 && Y < 0 && (X < std::numeric_limits<T>::min() - Y))); | 54 (X < 0 && Y < 0 && (X < std::numeric_limits<T>::min() - Y))); |
55 } | 55 } |
56 | |
57 static inline uint64_t OffsetToAlignment(uint64_t Pos, uint64_t Align) { | |
58 assert(llvm::isPowerOf2_32(Align)); | |
Jim Stichnoth
2015/01/28 20:35:08
isPowerOf2_64 ?
jvoung (off chromium)
2015/01/28 23:37:53
Done.
| |
59 uint64_t Mod = Pos & (Align - 1); | |
60 if (Mod == 0) | |
61 return 0; | |
62 return Align - Mod; | |
63 } | |
56 }; | 64 }; |
57 | 65 |
58 // BoundedProducerConsumerQueue is a work queue that allows multiple | 66 // BoundedProducerConsumerQueue is a work queue that allows multiple |
59 // producers and multiple consumers. A producer adds entries using | 67 // producers and multiple consumers. A producer adds entries using |
60 // blockingPush(), and may block if the queue is "full". A producer | 68 // blockingPush(), and may block if the queue is "full". A producer |
61 // uses notifyEnd() to indicate that no more entries will be added. A | 69 // uses notifyEnd() to indicate that no more entries will be added. A |
62 // consumer removes an item using blockingPop(), which will return | 70 // consumer removes an item using blockingPop(), which will return |
63 // nullptr if notifyEnd() has been called and the queue is empty (it | 71 // nullptr if notifyEnd() has been called and the queue is empty (it |
64 // never returns nullptr if the queue contained any items). | 72 // never returns nullptr if the queue contained any items). |
65 // | 73 // |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 } | 186 } |
179 T *pop() { | 187 T *pop() { |
180 assert(!empty()); | 188 assert(!empty()); |
181 return WorkItems[Front++ & MaxStaticSizeMask]; | 189 return WorkItems[Front++ & MaxStaticSizeMask]; |
182 } | 190 } |
183 }; | 191 }; |
184 | 192 |
185 } // end of namespace Ice | 193 } // end of namespace Ice |
186 | 194 |
187 #endif // SUBZERO_SRC_ICEUTILS_H | 195 #endif // SUBZERO_SRC_ICEUTILS_H |
OLD | NEW |