2010-01-29 09:42:13 +00:00
|
|
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-01-29 09:42:13 +00:00
|
|
|
|
2014-10-31 10:44:04 +00:00
|
|
|
#include "src/bit-vector.h"
|
2014-08-20 12:10:41 +00:00
|
|
|
|
|
|
|
#include "src/base/bits.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/scopes.h"
|
2010-01-29 09:42:13 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2010-03-16 10:54:02 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void BitVector::Print() {
|
|
|
|
bool first = true;
|
|
|
|
PrintF("{");
|
|
|
|
for (int i = 0; i < length(); i++) {
|
|
|
|
if (Contains(i)) {
|
|
|
|
if (!first) PrintF(",");
|
|
|
|
first = false;
|
2010-09-30 07:22:53 +00:00
|
|
|
PrintF("%d", i);
|
2010-03-16 10:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
PrintF("}");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void BitVector::Iterator::Advance() {
|
|
|
|
current_++;
|
2014-10-31 10:44:04 +00:00
|
|
|
uintptr_t val = current_value_;
|
2010-12-07 11:31:57 +00:00
|
|
|
while (val == 0) {
|
|
|
|
current_index_++;
|
|
|
|
if (Done()) return;
|
|
|
|
val = target_->data_[current_index_];
|
2014-10-31 10:44:04 +00:00
|
|
|
current_ = current_index_ << kDataBitShift;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
val = SkipZeroBytes(val);
|
|
|
|
val = SkipZeroBits(val);
|
|
|
|
current_value_ = val >> 1;
|
|
|
|
}
|
|
|
|
|
2014-08-20 12:10:41 +00:00
|
|
|
|
|
|
|
int BitVector::Count() const {
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < data_length_; i++) {
|
2014-10-31 10:44:04 +00:00
|
|
|
uintptr_t data = data_[i];
|
|
|
|
if (sizeof(data) == 8) {
|
|
|
|
count += base::bits::CountPopulation64(data);
|
|
|
|
} else {
|
|
|
|
count += base::bits::CountPopulation32(static_cast<uint32_t>(data));
|
|
|
|
}
|
2014-08-20 12:10:41 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|