| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_BITFIELD_H_ | 5 #ifndef VM_BITFIELD_H_ |
| 6 #define VM_BITFIELD_H_ | 6 #define VM_BITFIELD_H_ |
| 7 | 7 |
| 8 namespace dart { | 8 namespace dart { |
| 9 | 9 |
| 10 static const uword kUwordOne = 1U; | 10 static const uword kUwordOne = 1U; |
| 11 | 11 |
| 12 // BitField is a template for encoding and decoding a bit field inside | 12 // BitField is a template for encoding and decoding a bit field inside |
| 13 // an unsigned machine word. | 13 // an unsigned machine word. |
| 14 template<typename T, int position, int size> | 14 template<typename T, int position, int size> |
| 15 class BitField { | 15 class BitField { |
| 16 public: | 16 public: |
| 17 static const intptr_t kNextBit = position + size; |
| 18 |
| 17 // Tells whether the provided value fits into the bit field. | 19 // Tells whether the provided value fits into the bit field. |
| 18 static bool is_valid(T value) { | 20 static bool is_valid(T value) { |
| 19 return (static_cast<uword>(value) & ~((kUwordOne << size) - 1)) == 0; | 21 return (static_cast<uword>(value) & ~((kUwordOne << size) - 1)) == 0; |
| 20 } | 22 } |
| 21 | 23 |
| 22 // Returns a uword mask of the bit field. | 24 // Returns a uword mask of the bit field. |
| 23 static uword mask() { | 25 static uword mask() { |
| 24 return (kUwordOne << size) - 1; | 26 return (kUwordOne << size) - 1; |
| 25 } | 27 } |
| 26 | 28 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 static uword update(T value, uword original) { | 60 static uword update(T value, uword original) { |
| 59 ASSERT(is_valid(value)); | 61 ASSERT(is_valid(value)); |
| 60 return (static_cast<uword>(value) << position) | | 62 return (static_cast<uword>(value) << position) | |
| 61 (~mask_in_place() & original); | 63 (~mask_in_place() & original); |
| 62 } | 64 } |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 } // namespace dart | 67 } // namespace dart |
| 66 | 68 |
| 67 #endif // VM_BITFIELD_H_ | 69 #endif // VM_BITFIELD_H_ |
| OLD | NEW |