5#ifndef V8_UTILS_BIT_VECTOR_H_
6#define V8_UTILS_BIT_VECTOR_H_
22 int bit_in_word = current_index_ & (kDataBits - 1);
23 if (bit_in_word < kDataBits - 1) {
24 uintptr_t remaining_bits = *
ptr_ >> (bit_in_word + 1);
26 int next_bit_in_word = base::bits::CountTrailingZeros(remaining_bits);
27 current_index_ += next_bit_in_word + 1;
34 current_index_ =
RoundDown(current_index_, kDataBits);
37 current_index_ += kDataBits;
41 uintptr_t trailing_zeros = base::bits::CountTrailingZeros(*
ptr_);
42 current_index_ += trailing_zeros;
47 DCHECK(target_->Contains(current_index_));
48 return current_index_;
56 return current_index_ == other.current_index_;
72 ptr_(target->data_begin_),
73 end_(target->data_end_),
78 current_index_ += kDataBits;
81 current_index_ += base::bits::CountTrailingZeros(*
ptr_);
89 ptr_(target->data_end_),
90 end_(target->data_end_),
91 current_index_(target->data_length() * kDataBits) {
111 int data_length = (length + kDataBits - 1) >> kDataBitShift;
112 if (data_length > 1) {
114 std::fill_n(
data_.ptr_, data_length, 0);
115 data_begin_ =
data_.ptr_;
116 data_end_ = data_begin_ + data_length;
122 if (!other.is_inline()) {
123 int data_length = other.data_length();
124 DCHECK_LT(1, data_length);
125 data_.ptr_ = zone->AllocateArray<uintptr_t>(data_length);
126 data_begin_ = data_.ptr_;
127 data_end_ = data_begin_ + data_length;
128 std::copy_n(other.data_begin_, data_length, data_begin_);
141 if (other.is_inline()) {
142 data_begin_ = &
data_.inline_;
143 data_end_ = data_begin_ + other.data_length();
145 data_begin_ = other.data_begin_;
146 data_end_ = other.data_end_;
149 other.data_begin_ = &other.data_.inline_;
150 other.data_end_ = other.data_begin_ + 1;
157 DCHECK_EQ(is_inline(), other.is_inline());
158 std::copy_n(other.data_begin_, data_length(), data_begin_);
163 int old_data_length = data_length();
165 int new_data_length = (
new_length + kDataBits - 1) >> kDataBitShift;
166 if (new_data_length > old_data_length) {
167 uintptr_t* new_data = zone->
AllocateArray<uintptr_t>(new_data_length);
170 std::copy_n(data_begin_, old_data_length, new_data);
172 std::fill(new_data + old_data_length, new_data + new_data_length, 0);
174 data_begin_ = new_data;
175 data_end_ = new_data + new_data_length;
182 return (data_begin_[word(
i)] & bit(
i)) != 0;
187 data_begin_[word(
i)] |= bit(
i);
194 memset(data_begin_, -1,
sizeof(*data_begin_) * data_length());
199 data_begin_[word(
i)] &= ~bit(
i);
204 for (
int i = 0;
i < data_length();
i++) {
205 data_begin_[
i] |= other.data_begin_[
i];
210 DCHECK(other.length() == length());
211 bool changed =
false;
212 for (
int i = 0;
i < data_length();
i++) {
213 uintptr_t old_data = data_begin_[
i];
214 data_begin_[
i] |= other.data_begin_[
i];
215 if (data_begin_[
i] != old_data) changed =
true;
221 DCHECK(other.length() == length());
222 for (
int i = 0;
i < data_length();
i++) {
223 data_begin_[
i] &= other.data_begin_[
i];
228 DCHECK(other.length() == length());
229 bool changed =
false;
230 for (
int i = 0;
i < data_length();
i++) {
231 uintptr_t old_data = data_begin_[
i];
232 data_begin_[
i] &= other.data_begin_[
i];
233 if (data_begin_[
i] != old_data) changed =
true;
239 DCHECK(other.length() == length());
240 for (
int i = 0;
i < data_length();
i++) {
241 data_begin_[
i] &= ~other.data_begin_[
i];
245 void Clear() { std::fill_n(data_begin_, data_length(), 0); }
248 return std::all_of(data_begin_, data_end_, std::logical_not<uintptr_t>{});
252 return std::equal(data_begin_, data_end_, other.data_begin_);
276 int data_length()
const {
return static_cast<int>(data_end_ - data_begin_); }
280 return index >> kDataBitShift;
283 return uintptr_t{1} << (index & (kDataBits - 1));
289 uintptr_t* data_end_ = &
data_.inline_ + 1;
336 static_cast<uint32_t
>(needed_value + 1))));
uint8_t data_[MAX_STACK_LENGTH]
bool operator==(const Iterator &other) const
Iterator(const BitVector *target, StartTag)
V8_EXPORT_PRIVATE void operator++()
bool operator!=(const Iterator &other) const
Iterator(const BitVector *target, EndTag)
void Subtract(const BitVector &other)
static V8_INLINE uintptr_t bit(int index)
bool IntersectIsChanged(const BitVector &other)
BitVector & operator=(const BitVector &)=delete
BitVector & operator=(BitVector &&other) V8_NOEXCEPT
bool UnionIsChanged(const BitVector &other)
void CopyFrom(const BitVector &other)
void Intersect(const BitVector &other)
BitVector(const BitVector &)=delete
BitVector(const BitVector &other, Zone *zone)
BitVector(BitVector &&other) V8_NOEXCEPT
bool Contains(int i) const
static V8_INLINE int word(int index)
void Resize(int new_length, Zone *zone)
void Union(const BitVector &other)
bool Equals(const BitVector &other) const
BitVector(int length, Zone *zone)
V8_NOINLINE void Grow(int needed_value, Zone *zone)
static constexpr int kMaxSupportedValue
BitVector::Iterator end() const
static constexpr int kInitialLength
bool Contains(int value) const
BitVector::Iterator begin() const
bool Equals(const GrowableBitVector &other) const
bool InBitsRange(int value) const
GrowableBitVector(int length, Zone *zone)
void Add(int value, Zone *zone)
GrowableBitVector()=default
T * AllocateArray(size_t length)
const v8::base::TimeTicks end_
V8_BASE_EXPORT constexpr uint32_t RoundUpToPowerOfTwo32(uint32_t value)
constexpr int kBitsPerSystemPointer
constexpr int kBitsPerSystemPointerLog2
#define DCHECK_LE(v1, v2)
#define CHECK_GE(lhs, rhs)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_NE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)
constexpr T RoundDown(T x, intptr_t m)
#define V8_EXPORT_PRIVATE
DataStorage(uintptr_t value)
#define V8_UNLIKELY(condition)