| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Computes a hash value for the given string. | 82 // Computes a hash value for the given string. |
| 83 static uint32_t StringHash(const char* data, int length); | 83 static uint32_t StringHash(const char* data, int length); |
| 84 | 84 |
| 85 // Computes a hash value for the given word. | 85 // Computes a hash value for the given word. |
| 86 static uint32_t WordHash(word key); | 86 static uint32_t WordHash(word key); |
| 87 | 87 |
| 88 // Check whether an N-bit two's-complement representation can hold value. | 88 // Check whether an N-bit two's-complement representation can hold value. |
| 89 static inline bool IsInt(int N, word value) { | 89 template<typename T> |
| 90 ASSERT((0 < N) && (N < kBitsPerWord)); | 90 static inline bool IsInt(int N, T value) { |
| 91 word limit = static_cast<word>(1) << (N - 1); | 91 ASSERT((0 < N) && |
| 92 (static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value)))); |
| 93 T limit = static_cast<T>(1) << (N - 1); |
| 92 return (-limit <= value) && (value < limit); | 94 return (-limit <= value) && (value < limit); |
| 93 } | 95 } |
| 94 | 96 |
| 95 static inline bool IsUint(int N, word value) { | 97 template<typename T> |
| 96 ASSERT((0 < N) && (N < kBitsPerWord)); | 98 static inline bool IsUint(int N, T value) { |
| 97 word limit = static_cast<word>(1) << N; | 99 ASSERT((0 < N) && |
| 100 (static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value)))); |
| 101 T limit = static_cast<T>(1) << N; |
| 98 return (0 <= value) && (value < limit); | 102 return (0 <= value) && (value < limit); |
| 99 } | 103 } |
| 100 | 104 |
| 101 // Check whether the magnitude of value fits in N bits, i.e., whether an | 105 // Check whether the magnitude of value fits in N bits, i.e., whether an |
| 102 // (N+1)-bit sign-magnitude representation can hold value. | 106 // (N+1)-bit sign-magnitude representation can hold value. |
| 103 static inline bool IsAbsoluteUint(int N, word value) { | 107 template<typename T> |
| 104 ASSERT((0 < N) && (N < kBitsPerWord)); | 108 static inline bool IsAbsoluteUint(int N, T value) { |
| 109 ASSERT((0 < N) && |
| 110 (static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value)))); |
| 105 if (value < 0) value = -value; | 111 if (value < 0) value = -value; |
| 106 return IsUint(N, value); | 112 return IsUint(N, value); |
| 107 } | 113 } |
| 108 | 114 |
| 109 static inline int32_t Low16Bits(int32_t value) { | 115 static inline int32_t Low16Bits(int32_t value) { |
| 110 return static_cast<int32_t>(value & 0xffff); | 116 return static_cast<int32_t>(value & 0xffff); |
| 111 } | 117 } |
| 112 | 118 |
| 113 static inline int32_t High16Bits(int32_t value) { | 119 static inline int32_t High16Bits(int32_t value) { |
| 114 return static_cast<int32_t>(value >> 16); | 120 return static_cast<int32_t>(value >> 16); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 static char IntToHexDigit(int i) { | 152 static char IntToHexDigit(int i) { |
| 147 ASSERT(0 <= i && i < 16); | 153 ASSERT(0 <= i && i < 16); |
| 148 if (i < 10) return static_cast<char>('0' + i); | 154 if (i < 10) return static_cast<char>('0' + i); |
| 149 return static_cast<char>('A' + (i - 10)); | 155 return static_cast<char>('A' + (i - 10)); |
| 150 } | 156 } |
| 151 }; | 157 }; |
| 152 | 158 |
| 153 } // namespace dart | 159 } // namespace dart |
| 154 | 160 |
| 155 #endif // PLATFORM_UTILS_H_ | 161 #endif // PLATFORM_UTILS_H_ |
| OLD | NEW |