| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PLATFORM_UTILS_H_ | 5 #ifndef PLATFORM_UTILS_H_ |
| 6 #define PLATFORM_UTILS_H_ | 6 #define PLATFORM_UTILS_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 ASSERT(IsPowerOfTwo(x)); | 38 ASSERT(IsPowerOfTwo(x)); |
| 39 int num_shifts = 0; | 39 int num_shifts = 0; |
| 40 while (x > 1) { | 40 while (x > 1) { |
| 41 num_shifts++; | 41 num_shifts++; |
| 42 x = x >> 1; | 42 x = x >> 1; |
| 43 } | 43 } |
| 44 return num_shifts; | 44 return num_shifts; |
| 45 } | 45 } |
| 46 | 46 |
| 47 template<typename T> | 47 template<typename T> |
| 48 static inline bool IsAligned(T x, int n) { | 48 static inline bool IsAligned(T x, intptr_t n) { |
| 49 ASSERT(IsPowerOfTwo(n)); | 49 ASSERT(IsPowerOfTwo(n)); |
| 50 return (x & (n - 1)) == 0; | 50 return (x & (n - 1)) == 0; |
| 51 } | 51 } |
| 52 | 52 |
| 53 template<typename T> | 53 template<typename T> |
| 54 static inline bool IsAligned(T* x, int n) { | 54 static inline bool IsAligned(T* x, intptr_t n) { |
| 55 return IsAligned(reinterpret_cast<uword>(x), n); | 55 return IsAligned(reinterpret_cast<uword>(x), n); |
| 56 } | 56 } |
| 57 | 57 |
| 58 template<typename T> | 58 template<typename T> |
| 59 static inline T RoundDown(T x, int n) { | 59 static inline T RoundDown(T x, intptr_t n) { |
| 60 ASSERT(IsPowerOfTwo(n)); | 60 ASSERT(IsPowerOfTwo(n)); |
| 61 return (x & -n); | 61 return (x & -n); |
| 62 } | 62 } |
| 63 | 63 |
| 64 template<typename T> | 64 template<typename T> |
| 65 static inline T* RoundDown(T* x, int n) { | 65 static inline T* RoundDown(T* x, intptr_t n) { |
| 66 return reinterpret_cast<T*>(RoundDown(reinterpret_cast<uword>(x), n)); | 66 return reinterpret_cast<T*>(RoundDown(reinterpret_cast<uword>(x), n)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 template<typename T> | 69 template<typename T> |
| 70 static inline T RoundUp(T x, int n) { | 70 static inline T RoundUp(T x, intptr_t n) { |
| 71 return RoundDown(x + n - 1, n); | 71 return RoundDown(x + n - 1, n); |
| 72 } | 72 } |
| 73 | 73 |
| 74 template<typename T> | 74 template<typename T> |
| 75 static inline T* RoundUp(T* x, int n) { | 75 static inline T* RoundUp(T* x, intptr_t n) { |
| 76 return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uword>(x), n)); | 76 return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uword>(x), n)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 static uint32_t RoundUpToPowerOfTwo(uint32_t x); | 79 static uint32_t RoundUpToPowerOfTwo(uint32_t x); |
| 80 static int CountOneBits(uint32_t x); | 80 static int CountOneBits(uint32_t x); |
| 81 | 81 |
| 82 static int HighestBit(int64_t v); | 82 static int HighestBit(int64_t v); |
| 83 | 83 |
| 84 static int CountTrailingZeros(uword x); | 84 static int CountTrailingZeros(uword x); |
| 85 | 85 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 #include "platform/utils_linux.h" | 189 #include "platform/utils_linux.h" |
| 190 #elif defined(TARGET_OS_MACOS) | 190 #elif defined(TARGET_OS_MACOS) |
| 191 #include "platform/utils_macos.h" | 191 #include "platform/utils_macos.h" |
| 192 #elif defined(TARGET_OS_WINDOWS) | 192 #elif defined(TARGET_OS_WINDOWS) |
| 193 #include "platform/utils_win.h" | 193 #include "platform/utils_win.h" |
| 194 #else | 194 #else |
| 195 #error Unknown target os. | 195 #error Unknown target os. |
| 196 #endif | 196 #endif |
| 197 | 197 |
| 198 #endif // PLATFORM_UTILS_H_ | 198 #endif // PLATFORM_UTILS_H_ |
| OLD | NEW |