| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 template<class T, int shift, int size, class U> | 241 template<class T, int shift, int size, class U> |
| 242 class BitFieldBase { | 242 class BitFieldBase { |
| 243 public: | 243 public: |
| 244 // A type U mask of bit field. To use all bits of a type U of x bits | 244 // A type U mask of bit field. To use all bits of a type U of x bits |
| 245 // in a bitfield without compiler warnings we have to compute 2^x | 245 // in a bitfield without compiler warnings we have to compute 2^x |
| 246 // without using a shift count of x in the computation. | 246 // without using a shift count of x in the computation. |
| 247 static const U kOne = static_cast<U>(1U); | 247 static const U kOne = static_cast<U>(1U); |
| 248 static const U kMask = ((kOne << shift) << size) - (kOne << shift); | 248 static const U kMask = ((kOne << shift) << size) - (kOne << shift); |
| 249 static const U kShift = shift; | 249 static const U kShift = shift; |
| 250 static const U kSize = size; | 250 static const U kSize = size; |
| 251 static const U kNext = kShift + kSize; | |
| 252 | 251 |
| 253 // Value for the field with all bits set. | 252 // Value for the field with all bits set. |
| 254 static const T kMax = static_cast<T>((1U << size) - 1); | 253 static const T kMax = static_cast<T>((1U << size) - 1); |
| 255 | 254 |
| 256 // Tells whether the provided value fits into the bit field. | 255 // Tells whether the provided value fits into the bit field. |
| 257 static bool is_valid(T value) { | 256 static bool is_valid(T value) { |
| 258 return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0; | 257 return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0; |
| 259 } | 258 } |
| 260 | 259 |
| 261 // Returns a type U with the bit field value encoded. | 260 // Returns a type U with the bit field value encoded. |
| (...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 // Add formatted contents like printf based on a va_list. | 1548 // Add formatted contents like printf based on a va_list. |
| 1550 void AddFormattedList(const char* format, va_list list); | 1549 void AddFormattedList(const char* format, va_list list); |
| 1551 private: | 1550 private: |
| 1552 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1551 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
| 1553 }; | 1552 }; |
| 1554 | 1553 |
| 1555 | 1554 |
| 1556 } } // namespace v8::internal | 1555 } } // namespace v8::internal |
| 1557 | 1556 |
| 1558 #endif // V8_UTILS_H_ | 1557 #endif // V8_UTILS_H_ |
| OLD | NEW |