| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_BIT_VECTOR_H_ | 5 #ifndef VM_BIT_VECTOR_H_ |
| 6 #define VM_BIT_VECTOR_H_ | 6 #define VM_BIT_VECTOR_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/zone.h" | 10 #include "vm/zone.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 explicit BitVector(intptr_t length) | 47 explicit BitVector(intptr_t length) |
| 48 : length_(length), | 48 : length_(length), |
| 49 data_length_(SizeFor(length)), | 49 data_length_(SizeFor(length)), |
| 50 data_(Isolate::Current()->current_zone()->Alloc<uword>(data_length_)) { | 50 data_(Isolate::Current()->current_zone()->Alloc<uword>(data_length_)) { |
| 51 ASSERT(length > 0); | 51 ASSERT(length > 0); |
| 52 Clear(); | 52 Clear(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void CopyFrom(const BitVector* other) { |
| 56 Clear(); |
| 57 AddAll(other); |
| 58 } |
| 59 |
| 55 static intptr_t SizeFor(intptr_t length) { | 60 static intptr_t SizeFor(intptr_t length) { |
| 56 return 1 + ((length - 1) / kBitsPerWord); | 61 return 1 + ((length - 1) / kBitsPerWord); |
| 57 } | 62 } |
| 58 | 63 |
| 59 void Add(intptr_t i) { | 64 void Add(intptr_t i) { |
| 60 ASSERT(i >= 0 && i < length()); | 65 ASSERT(i >= 0 && i < length()); |
| 61 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord)); | 66 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord)); |
| 62 } | 67 } |
| 63 | 68 |
| 64 void Remove(intptr_t i) { | 69 void Remove(intptr_t i) { |
| 65 ASSERT(i >= 0 && i < length()); | 70 ASSERT(i >= 0 && i < length()); |
| 66 data_[i / kBitsPerWord] &= ~(static_cast<uword>(1) << (i % kBitsPerWord)); | 71 data_[i / kBitsPerWord] &= ~(static_cast<uword>(1) << (i % kBitsPerWord)); |
| 67 } | 72 } |
| 68 | 73 |
| 74 bool Equals(const BitVector& other) const; |
| 75 |
| 69 // Add all elements that are in the bitvector from. | 76 // Add all elements that are in the bitvector from. |
| 70 bool AddAll(BitVector* from); | 77 bool AddAll(const BitVector* from); |
| 71 | 78 |
| 72 // From the bitvector gen add those elements that are not in the | 79 // From the bitvector gen add those elements that are not in the |
| 73 // bitvector kill. | 80 // bitvector kill. |
| 74 bool KillAndAdd(BitVector* kill, BitVector* gen); | 81 bool KillAndAdd(BitVector* kill, BitVector* gen); |
| 75 | 82 |
| 83 void Intersect(const BitVector& other); |
| 84 |
| 76 bool Contains(int i) const { | 85 bool Contains(int i) const { |
| 77 ASSERT(i >= 0 && i < length()); | 86 ASSERT(i >= 0 && i < length()); |
| 78 uword block = data_[i / kBitsPerWord]; | 87 uword block = data_[i / kBitsPerWord]; |
| 79 return (block & (static_cast<uword>(1) << (i % kBitsPerWord))) != 0; | 88 return (block & (static_cast<uword>(1) << (i % kBitsPerWord))) != 0; |
| 80 } | 89 } |
| 81 | 90 |
| 82 void Clear() { | 91 void Clear() { |
| 83 for (intptr_t i = 0; i < data_length_; i++) { | 92 for (intptr_t i = 0; i < data_length_; i++) { |
| 84 data_[i] = 0; | 93 data_[i] = 0; |
| 85 } | 94 } |
| 86 } | 95 } |
| 87 | 96 |
| 97 void SetAll() { |
| 98 for (intptr_t i = 0; i < data_length_; i++) { |
| 99 data_[i] = static_cast<uword>(-1); |
| 100 } |
| 101 } |
| 102 |
| 88 intptr_t length() const { return length_; } | 103 intptr_t length() const { return length_; } |
| 89 | 104 |
| 105 void Print() const; |
| 106 |
| 90 private: | 107 private: |
| 91 intptr_t length_; | 108 intptr_t length_; |
| 92 intptr_t data_length_; | 109 intptr_t data_length_; |
| 93 uword* data_; | 110 uword* data_; |
| 94 | 111 |
| 95 DISALLOW_COPY_AND_ASSIGN(BitVector); | 112 DISALLOW_COPY_AND_ASSIGN(BitVector); |
| 96 }; | 113 }; |
| 97 | 114 |
| 98 } // namespace dart | 115 } // namespace dart |
| 99 | 116 |
| 100 #endif // VM_BIT_VECTOR_H_ | 117 #endif // VM_BIT_VECTOR_H_ |
| OLD | NEW |