Chromium Code Reviews| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 | 298 |
| 299 // Returns a type U with the bit field value updated. | 299 // Returns a type U with the bit field value updated. |
| 300 static U update(U previous, T value) { | 300 static U update(U previous, T value) { |
| 301 return (previous & ~kMask) | encode(value); | 301 return (previous & ~kMask) | encode(value); |
| 302 } | 302 } |
| 303 | 303 |
| 304 // Extracts the bit field from the value. | 304 // Extracts the bit field from the value. |
| 305 static T decode(U value) { | 305 static T decode(U value) { |
| 306 return static_cast<T>((value & kMask) >> shift); | 306 return static_cast<T>((value & kMask) >> shift); |
| 307 } | 307 } |
| 308 | |
| 309 STATIC_ASSERT((kNext - 1) / 8 < sizeof(U)); | |
|
Jakob Kummerow
2016/08/17 15:47:01
How about:
STATIC_ASSERT(kNext / kBitsPerByte <=
| |
| 308 }; | 310 }; |
| 309 | 311 |
| 310 | |
| 311 template <class T, int shift, int size> | 312 template <class T, int shift, int size> |
| 312 class BitField8 : public BitFieldBase<T, shift, size, uint8_t> {}; | 313 class BitField8 : public BitFieldBase<T, shift, size, uint8_t> {}; |
| 313 | 314 |
| 314 | 315 |
| 315 template <class T, int shift, int size> | 316 template <class T, int shift, int size> |
| 316 class BitField16 : public BitFieldBase<T, shift, size, uint16_t> {}; | 317 class BitField16 : public BitFieldBase<T, shift, size, uint16_t> {}; |
| 317 | 318 |
| 318 | 319 |
| 319 template<class T, int shift, int size> | 320 template<class T, int shift, int size> |
| 320 class BitField : public BitFieldBase<T, shift, size, uint32_t> { }; | 321 class BitField : public BitFieldBase<T, shift, size, uint32_t> { }; |
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1569 byte* dst = reinterpret_cast<byte*>(p); | 1570 byte* dst = reinterpret_cast<byte*>(p); |
| 1570 for (size_t i = 0; i < sizeof(V); i++) { | 1571 for (size_t i = 0; i < sizeof(V); i++) { |
| 1571 dst[i] = src[sizeof(V) - i - 1]; | 1572 dst[i] = src[sizeof(V) - i - 1]; |
| 1572 } | 1573 } |
| 1573 #endif // V8_TARGET_LITTLE_ENDIAN | 1574 #endif // V8_TARGET_LITTLE_ENDIAN |
| 1574 } | 1575 } |
| 1575 } // namespace internal | 1576 } // namespace internal |
| 1576 } // namespace v8 | 1577 } // namespace v8 |
| 1577 | 1578 |
| 1578 #endif // V8_UTILS_H_ | 1579 #endif // V8_UTILS_H_ |
| OLD | NEW |