Home | History | Annotate | Download | only in src
      1 // Copyright 2010 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "src/bit-vector.h"
      6 
      7 #include "src/base/bits.h"
      8 
      9 namespace v8 {
     10 namespace internal {
     11 
     12 #ifdef DEBUG
     13 void BitVector::Print() {
     14   bool first = true;
     15   PrintF("{");
     16   for (int i = 0; i < length(); i++) {
     17     if (Contains(i)) {
     18       if (!first) PrintF(",");
     19       first = false;
     20       PrintF("%d", i);
     21     }
     22   }
     23   PrintF("}\n");
     24 }
     25 #endif
     26 
     27 
     28 void BitVector::Iterator::Advance() {
     29   current_++;
     30   uintptr_t val = current_value_;
     31   while (val == 0) {
     32     current_index_++;
     33     if (Done()) return;
     34     val = target_->data_[current_index_];
     35     current_ = current_index_ << kDataBitShift;
     36   }
     37   val = SkipZeroBytes(val);
     38   val = SkipZeroBits(val);
     39   current_value_ = val >> 1;
     40 }
     41 
     42 
     43 int BitVector::Count() const {
     44   int count = 0;
     45   for (int i = 0; i < data_length_; i++) {
     46     uintptr_t data = data_[i];
     47     if (sizeof(data) == 8) {
     48       count += base::bits::CountPopulation64(data);
     49     } else {
     50       count += base::bits::CountPopulation32(static_cast<uint32_t>(data));
     51     }
     52   }
     53   return count;
     54 }
     55 
     56 }  // namespace internal
     57 }  // namespace v8
     58