| 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> |
| 11 | 11 |
| 12 #include "src/allocation.h" | 12 #include "src/allocation.h" |
| 13 #include "src/base/macros.h" |
| 13 #include "src/checks.h" | 14 #include "src/checks.h" |
| 14 #include "src/globals.h" | 15 #include "src/globals.h" |
| 15 #include "src/list.h" | 16 #include "src/list.h" |
| 16 #include "src/platform.h" | 17 #include "src/platform.h" |
| 17 #include "src/vector.h" | 18 #include "src/vector.h" |
| 18 | 19 |
| 19 namespace v8 { | 20 namespace v8 { |
| 20 namespace internal { | 21 namespace internal { |
| 21 | 22 |
| 22 // ---------------------------------------------------------------------------- | 23 // ---------------------------------------------------------------------------- |
| 23 // General helper functions | 24 // General helper functions |
| 24 | 25 |
| 25 #define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) | |
| 26 | |
| 27 // Returns true iff x is a power of 2. Cannot be used with the maximally | 26 // Returns true iff x is a power of 2. Cannot be used with the maximally |
| 28 // negative value of the type T (the -1 overflows). | 27 // negative value of the type T (the -1 overflows). |
| 29 template <typename T> | 28 template <typename T> |
| 30 inline bool IsPowerOf2(T x) { | 29 inline bool IsPowerOf2(T x) { |
| 31 return IS_POWER_OF_TWO(x); | 30 return IS_POWER_OF_TWO(x); |
| 32 } | 31 } |
| 33 | 32 |
| 34 | 33 |
| 35 // X must be a power of 2. Returns the number of trailing zeros. | 34 // X must be a power of 2. Returns the number of trailing zeros. |
| 36 inline int WhichPowerOf2(uint32_t x) { | 35 inline int WhichPowerOf2(uint32_t x) { |
| (...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 } | 1604 } |
| 1606 | 1605 |
| 1607 *index = result; | 1606 *index = result; |
| 1608 return true; | 1607 return true; |
| 1609 } | 1608 } |
| 1610 | 1609 |
| 1611 | 1610 |
| 1612 } } // namespace v8::internal | 1611 } } // namespace v8::internal |
| 1613 | 1612 |
| 1614 #endif // V8_UTILS_H_ | 1613 #endif // V8_UTILS_H_ |
| OLD | NEW |