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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 return a < 0 ? a : -a; | 226 return a < 0 ? a : -a; |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 // TODO(svenpanne) Clean up the whole power-of-2 mess. | 230 // TODO(svenpanne) Clean up the whole power-of-2 mess. |
231 inline int32_t WhichPowerOf2Abs(int32_t x) { | 231 inline int32_t WhichPowerOf2Abs(int32_t x) { |
232 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); | 232 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 // Obtains the unsigned type corresponding to T | |
237 // available in C++11 as std::make_unsigned | |
238 template<typename T> | |
239 struct make_unsigned { | |
240 typedef T type; | |
241 }; | |
242 | |
243 | |
244 // Template specializations necessary to have make_unsigned work | |
245 template<> struct make_unsigned<int32_t> { | |
246 typedef uint32_t type; | |
247 }; | |
248 | |
249 | |
250 template<> struct make_unsigned<int64_t> { | |
251 typedef uint64_t type; | |
252 }; | |
253 | |
254 | |
255 // ---------------------------------------------------------------------------- | 236 // ---------------------------------------------------------------------------- |
256 // BitField is a help template for encoding and decode bitfield with | 237 // BitField is a help template for encoding and decode bitfield with |
257 // unsigned content. | 238 // unsigned content. |
258 | 239 |
259 template<class T, int shift, int size, class U> | 240 template<class T, int shift, int size, class U> |
260 class BitFieldBase { | 241 class BitFieldBase { |
261 public: | 242 public: |
262 // A type U mask of bit field. To use all bits of a type U of x bits | 243 // A type U mask of bit field. To use all bits of a type U of x bits |
263 // in a bitfield without compiler warnings we have to compute 2^x | 244 // in a bitfield without compiler warnings we have to compute 2^x |
264 // without using a shift count of x in the computation. | 245 // without using a shift count of x in the computation. |
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 // Add formatted contents like printf based on a va_list. | 1468 // Add formatted contents like printf based on a va_list. |
1488 void AddFormattedList(const char* format, va_list list); | 1469 void AddFormattedList(const char* format, va_list list); |
1489 private: | 1470 private: |
1490 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1471 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
1491 }; | 1472 }; |
1492 | 1473 |
1493 | 1474 |
1494 } } // namespace v8::internal | 1475 } } // namespace v8::internal |
1495 | 1476 |
1496 #endif // V8_UTILS_H_ | 1477 #endif // V8_UTILS_H_ |
OLD | NEW |