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 |
236 // ---------------------------------------------------------------------------- | 255 // ---------------------------------------------------------------------------- |
237 // BitField is a help template for encoding and decode bitfield with | 256 // BitField is a help template for encoding and decode bitfield with |
238 // unsigned content. | 257 // unsigned content. |
239 | 258 |
240 template<class T, int shift, int size, class U> | 259 template<class T, int shift, int size, class U> |
241 class BitFieldBase { | 260 class BitFieldBase { |
242 public: | 261 public: |
243 // A type U mask of bit field. To use all bits of a type U of x bits | 262 // A type U mask of bit field. To use all bits of a type U of x bits |
244 // in a bitfield without compiler warnings we have to compute 2^x | 263 // in a bitfield without compiler warnings we have to compute 2^x |
245 // without using a shift count of x in the computation. | 264 // without using a shift count of x in the computation. |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 // Add formatted contents like printf based on a va_list. | 1566 // Add formatted contents like printf based on a va_list. |
1548 void AddFormattedList(const char* format, va_list list); | 1567 void AddFormattedList(const char* format, va_list list); |
1549 private: | 1568 private: |
1550 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1569 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
1551 }; | 1570 }; |
1552 | 1571 |
1553 | 1572 |
1554 } } // namespace v8::internal | 1573 } } // namespace v8::internal |
1555 | 1574 |
1556 #endif // V8_UTILS_H_ | 1575 #endif // V8_UTILS_H_ |
OLD | NEW |