OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 185 |
186 | 186 |
187 // Returns true if (addr + offset) is aligned. | 187 // Returns true if (addr + offset) is aligned. |
188 inline bool IsAddressAligned(Address addr, | 188 inline bool IsAddressAligned(Address addr, |
189 intptr_t alignment, | 189 intptr_t alignment, |
190 int offset = 0) { | 190 int offset = 0) { |
191 intptr_t offs = OffsetFrom(addr + offset); | 191 intptr_t offs = OffsetFrom(addr + offset); |
192 return IsAligned(offs, alignment); | 192 return IsAligned(offs, alignment); |
193 } | 193 } |
194 | 194 |
| 195 template <typename T, typename U> |
| 196 inline T RoundUpToMultipleOfPowOf2(T value, U multiple) { |
| 197 DCHECK(multiple && ((multiple & (multiple - 1)) == 0)); |
| 198 return (value + multiple - 1) & ~(multiple - 1); |
| 199 } |
195 | 200 |
196 // Returns the maximum of the two parameters. | 201 // Returns the maximum of the two parameters. |
197 template <typename T> | 202 template <typename T> |
198 T Max(T a, T b) { | 203 T Max(T a, T b) { |
199 return a < b ? b : a; | 204 return a < b ? b : a; |
200 } | 205 } |
201 | 206 |
202 | 207 |
203 // Returns the minimum of the two parameters. | 208 // Returns the minimum of the two parameters. |
204 template <typename T> | 209 template <typename T> |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 private: | 1717 private: |
1713 T value_; | 1718 T value_; |
1714 ThreadedListZoneEntry<T>* next_; | 1719 ThreadedListZoneEntry<T>* next_; |
1715 DISALLOW_COPY_AND_ASSIGN(ThreadedListZoneEntry); | 1720 DISALLOW_COPY_AND_ASSIGN(ThreadedListZoneEntry); |
1716 }; | 1721 }; |
1717 | 1722 |
1718 } // namespace internal | 1723 } // namespace internal |
1719 } // namespace v8 | 1724 } // namespace v8 |
1720 | 1725 |
1721 #endif // V8_UTILS_H_ | 1726 #endif // V8_UTILS_H_ |
OLD | NEW |