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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 size_t size) { | 513 size_t size) { |
509 memmove(dest, src, size); | 514 memmove(dest, src, size); |
510 } | 515 } |
511 const int kMinComplexMemCopy = 8; | 516 const int kMinComplexMemCopy = 8; |
512 #endif // V8_TARGET_ARCH_IA32 | 517 #endif // V8_TARGET_ARCH_IA32 |
513 | 518 |
514 | 519 |
515 // ---------------------------------------------------------------------------- | 520 // ---------------------------------------------------------------------------- |
516 // Miscellaneous | 521 // Miscellaneous |
517 | 522 |
| 523 // Memory offset for lower and higher bits in a 64 bit integer. |
| 524 #if defined(V8_TARGET_LITTLE_ENDIAN) |
| 525 static const int kInt64LowerHalfMemoryOffset = 0; |
| 526 static const int kInt64UpperHalfMemoryOffset = 4; |
| 527 #elif defined(V8_TARGET_BIG_ENDIAN) |
| 528 static const int kInt64LowerHalfMemoryOffset = 4; |
| 529 static const int kInt64UpperHalfMemoryOffset = 0; |
| 530 #endif // V8_TARGET_LITTLE_ENDIAN |
| 531 |
518 // A static resource holds a static instance that can be reserved in | 532 // A static resource holds a static instance that can be reserved in |
519 // a local scope using an instance of Access. Attempts to re-reserve | 533 // a local scope using an instance of Access. Attempts to re-reserve |
520 // the instance will cause an error. | 534 // the instance will cause an error. |
521 template <typename T> | 535 template <typename T> |
522 class StaticResource { | 536 class StaticResource { |
523 public: | 537 public: |
524 StaticResource() : is_reserved_(false) {} | 538 StaticResource() : is_reserved_(false) {} |
525 | 539 |
526 private: | 540 private: |
527 template <typename S> friend class Access; | 541 template <typename S> friend class Access; |
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 private: | 1726 private: |
1713 T value_; | 1727 T value_; |
1714 ThreadedListZoneEntry<T>* next_; | 1728 ThreadedListZoneEntry<T>* next_; |
1715 DISALLOW_COPY_AND_ASSIGN(ThreadedListZoneEntry); | 1729 DISALLOW_COPY_AND_ASSIGN(ThreadedListZoneEntry); |
1716 }; | 1730 }; |
1717 | 1731 |
1718 } // namespace internal | 1732 } // namespace internal |
1719 } // namespace v8 | 1733 } // namespace v8 |
1720 | 1734 |
1721 #endif // V8_UTILS_H_ | 1735 #endif // V8_UTILS_H_ |
OLD | NEW |