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; |
251 | 252 |
252 // Value for the field with all bits set. | 253 // Value for the field with all bits set. |
253 static const T kMax = static_cast<T>((1U << size) - 1); | 254 static const T kMax = static_cast<T>((1U << size) - 1); |
254 | 255 |
255 // Tells whether the provided value fits into the bit field. | 256 // Tells whether the provided value fits into the bit field. |
256 static bool is_valid(T value) { | 257 static bool is_valid(T value) { |
257 return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0; | 258 return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0; |
258 } | 259 } |
259 | 260 |
260 // Returns a type U with the bit field value encoded. | 261 // Returns a type U with the bit field value encoded. |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 // Add formatted contents like printf based on a va_list. | 1549 // Add formatted contents like printf based on a va_list. |
1549 void AddFormattedList(const char* format, va_list list); | 1550 void AddFormattedList(const char* format, va_list list); |
1550 private: | 1551 private: |
1551 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1552 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
1552 }; | 1553 }; |
1553 | 1554 |
1554 | 1555 |
1555 } } // namespace v8::internal | 1556 } } // namespace v8::internal |
1556 | 1557 |
1557 #endif // V8_UTILS_H_ | 1558 #endif // V8_UTILS_H_ |
OLD | NEW |