OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 template <typename T> | 150 template <typename T> |
151 int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) { | 151 int HandleObjectPointerCompare(const Handle<T>* a, const Handle<T>* b) { |
152 return Compare<T*>(*(*a), *(*b)); | 152 return Compare<T*>(*(*a), *(*b)); |
153 } | 153 } |
154 | 154 |
155 | 155 |
156 // Returns the smallest power of two which is >= x. If you pass in a | 156 // Returns the smallest power of two which is >= x. If you pass in a |
157 // number that is already a power of two, it is returned as is. | 157 // number that is already a power of two, it is returned as is. |
158 // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., | 158 // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., |
159 // figure 3-3, page 48, where the function is called clp2. | 159 // figure 3-3, page 48, where the function is called clp2. |
160 inline uint32_t RoundUpToPowerOf2(uint32_t x) { | 160 template<typename uint_type> |
161 inline uint_type RoundUpToPowerOf2(uint_type x) { | |
161 ASSERT(x <= 0x80000000u); | 162 ASSERT(x <= 0x80000000u); |
162 x = x - 1; | 163 x = x - 1; |
163 x = x | (x >> 1); | 164 x = x | (x >> 1); |
164 x = x | (x >> 2); | 165 x = x | (x >> 2); |
165 x = x | (x >> 4); | 166 x = x | (x >> 4); |
166 x = x | (x >> 8); | 167 x = x | (x >> 8); |
167 x = x | (x >> 16); | 168 x = x | (x >> 16); |
168 return x + 1; | 169 return x + 1; |
169 } | 170 } |
170 | 171 |
171 | 172 |
173 template<typename int_type> | |
174 inline int SignedRoundUpToPowerOf2(int_type x_argument) { | |
175 uintptr_t x = static_cast<uintptr_t>(x_argument); | |
Vyacheslav Egorov (Chromium)
2011/12/21 13:22:12
inline int SignedRoundUpToPowerOf2(int_type x_argu
| |
176 ASSERT(x <= 0x80000000u); | |
177 x = x - 1; | |
178 x = x | (x >> 1); | |
179 x = x | (x >> 2); | |
180 x = x | (x >> 4); | |
181 x = x | (x >> 8); | |
182 x = x | (x >> 16); | |
183 return static_cast<int>(x + 1); | |
184 } | |
185 | |
186 | |
172 inline uint32_t RoundDownToPowerOf2(uint32_t x) { | 187 inline uint32_t RoundDownToPowerOf2(uint32_t x) { |
173 uint32_t rounded_up = RoundUpToPowerOf2(x); | 188 uint32_t rounded_up = RoundUpToPowerOf2(x); |
174 if (rounded_up > x) return rounded_up >> 1; | 189 if (rounded_up > x) return rounded_up >> 1; |
175 return rounded_up; | 190 return rounded_up; |
176 } | 191 } |
177 | 192 |
178 | 193 |
179 template <typename T, typename U> | 194 template <typename T, typename U> |
180 inline bool IsAligned(T value, U alignment) { | 195 inline bool IsAligned(T value, U alignment) { |
181 return (value & (alignment - 1)) == 0; | 196 return (value & (alignment - 1)) == 0; |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); | 953 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); |
939 return 1 << element; | 954 return 1 << element; |
940 } | 955 } |
941 | 956 |
942 T bits_; | 957 T bits_; |
943 }; | 958 }; |
944 | 959 |
945 } } // namespace v8::internal | 960 } } // namespace v8::internal |
946 | 961 |
947 #endif // V8_UTILS_H_ | 962 #endif // V8_UTILS_H_ |
OLD | NEW |