convert BitVector to use pointer size blocks
additionally rename data-flow.* to bit-vector.* as at some point these file became very inaccurately named BUG= R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/683243005 Cr-Commit-Position: refs/heads/master@{#25030} git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25030 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
f01e08315f
commit
3cace296ee
4
BUILD.gn
4
BUILD.gn
@ -450,6 +450,8 @@ source_set("v8_base") {
|
||||
"src/bignum-dtoa.h",
|
||||
"src/bignum.cc",
|
||||
"src/bignum.h",
|
||||
"src/bit-vector.cc",
|
||||
"src/bit-vector.h",
|
||||
"src/bootstrapper.cc",
|
||||
"src/bootstrapper.h",
|
||||
"src/builtins.cc",
|
||||
@ -602,8 +604,6 @@ source_set("v8_base") {
|
||||
"src/cpu-profiler-inl.h",
|
||||
"src/cpu-profiler.cc",
|
||||
"src/cpu-profiler.h",
|
||||
"src/data-flow.cc",
|
||||
"src/data-flow.h",
|
||||
"src/date.cc",
|
||||
"src/date.h",
|
||||
"src/dateparser-inl.h",
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/data-flow.h"
|
||||
#include "src/bit-vector.h"
|
||||
|
||||
#include "src/base/bits.h"
|
||||
#include "src/scopes.h"
|
||||
@ -28,12 +28,12 @@ void BitVector::Print() {
|
||||
|
||||
void BitVector::Iterator::Advance() {
|
||||
current_++;
|
||||
uint32_t val = current_value_;
|
||||
uintptr_t val = current_value_;
|
||||
while (val == 0) {
|
||||
current_index_++;
|
||||
if (Done()) return;
|
||||
val = target_->data_[current_index_];
|
||||
current_ = current_index_ << 5;
|
||||
current_ = current_index_ << kDataBitShift;
|
||||
}
|
||||
val = SkipZeroBytes(val);
|
||||
val = SkipZeroBits(val);
|
||||
@ -44,8 +44,12 @@ void BitVector::Iterator::Advance() {
|
||||
int BitVector::Count() const {
|
||||
int count = 0;
|
||||
for (int i = 0; i < data_length_; i++) {
|
||||
int data = data_[i];
|
||||
if (data != 0) count += base::bits::CountPopulation32(data);
|
||||
uintptr_t data = data_[i];
|
||||
if (sizeof(data) == 8) {
|
||||
count += base::bits::CountPopulation64(data);
|
||||
} else {
|
||||
count += base::bits::CountPopulation32(static_cast<uint32_t>(data));
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class BitVector: public ZoneObject {
|
||||
class BitVector : public ZoneObject {
|
||||
public:
|
||||
// Iterator for the elements of this BitVector.
|
||||
class Iterator BASE_EMBEDDED {
|
||||
@ -28,7 +28,7 @@ class BitVector: public ZoneObject {
|
||||
DCHECK(target->data_length_ > 0);
|
||||
Advance();
|
||||
}
|
||||
~Iterator() { }
|
||||
~Iterator() {}
|
||||
|
||||
bool Done() const { return current_index_ >= target_->data_length_; }
|
||||
void Advance();
|
||||
@ -39,14 +39,14 @@ class BitVector: public ZoneObject {
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t SkipZeroBytes(uint32_t val) {
|
||||
uintptr_t SkipZeroBytes(uintptr_t val) {
|
||||
while ((val & 0xFF) == 0) {
|
||||
val >>= 8;
|
||||
current_ += 8;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
uint32_t SkipZeroBits(uint32_t val) {
|
||||
uintptr_t SkipZeroBits(uintptr_t val) {
|
||||
while ((val & 0x1) == 0) {
|
||||
val >>= 1;
|
||||
current_++;
|
||||
@ -56,16 +56,20 @@ class BitVector: public ZoneObject {
|
||||
|
||||
BitVector* target_;
|
||||
int current_index_;
|
||||
uint32_t current_value_;
|
||||
uintptr_t current_value_;
|
||||
int current_;
|
||||
|
||||
friend class BitVector;
|
||||
};
|
||||
|
||||
static const int kDataBits = kPointerSize * 8;
|
||||
static const int kDataBitShift = kPointerSize == 8 ? 6 : 5;
|
||||
static const uintptr_t kOne = 1; // This saves some static_casts.
|
||||
|
||||
BitVector(int length, Zone* zone)
|
||||
: length_(length),
|
||||
data_length_(SizeFor(length)),
|
||||
data_(zone->NewArray<uint32_t>(data_length_)) {
|
||||
data_(zone->NewArray<uintptr_t>(data_length_)) {
|
||||
DCHECK(length > 0);
|
||||
Clear();
|
||||
}
|
||||
@ -73,18 +77,11 @@ class BitVector: public ZoneObject {
|
||||
BitVector(const BitVector& other, Zone* zone)
|
||||
: length_(other.length()),
|
||||
data_length_(SizeFor(length_)),
|
||||
data_(zone->NewArray<uint32_t>(data_length_)) {
|
||||
data_(zone->NewArray<uintptr_t>(data_length_)) {
|
||||
CopyFrom(other);
|
||||
}
|
||||
|
||||
static int SizeFor(int length) {
|
||||
return 1 + ((length - 1) / 32);
|
||||
}
|
||||
|
||||
BitVector& operator=(const BitVector& rhs) {
|
||||
if (this != &rhs) CopyFrom(rhs);
|
||||
return *this;
|
||||
}
|
||||
static int SizeFor(int length) { return 1 + ((length - 1) / kDataBits); }
|
||||
|
||||
void CopyFrom(const BitVector& other) {
|
||||
DCHECK(other.length() <= length());
|
||||
@ -98,18 +95,18 @@ class BitVector: public ZoneObject {
|
||||
|
||||
bool Contains(int i) const {
|
||||
DCHECK(i >= 0 && i < length());
|
||||
uint32_t block = data_[i / 32];
|
||||
return (block & (1U << (i % 32))) != 0;
|
||||
uintptr_t block = data_[i / kDataBits];
|
||||
return (block & (kOne << (i % kDataBits))) != 0;
|
||||
}
|
||||
|
||||
void Add(int i) {
|
||||
DCHECK(i >= 0 && i < length());
|
||||
data_[i / 32] |= (1U << (i % 32));
|
||||
data_[i / kDataBits] |= (kOne << (i % kDataBits));
|
||||
}
|
||||
|
||||
void Remove(int i) {
|
||||
DCHECK(i >= 0 && i < length());
|
||||
data_[i / 32] &= ~(1U << (i % 32));
|
||||
data_[i / kDataBits] &= ~(kOne << (i % kDataBits));
|
||||
}
|
||||
|
||||
void Union(const BitVector& other) {
|
||||
@ -123,7 +120,7 @@ class BitVector: public ZoneObject {
|
||||
DCHECK(other.length() == length());
|
||||
bool changed = false;
|
||||
for (int i = 0; i < data_length_; i++) {
|
||||
uint32_t old_data = data_[i];
|
||||
uintptr_t old_data = data_[i];
|
||||
data_[i] |= other.data_[i];
|
||||
if (data_[i] != old_data) changed = true;
|
||||
}
|
||||
@ -141,7 +138,7 @@ class BitVector: public ZoneObject {
|
||||
DCHECK(other.length() == length());
|
||||
bool changed = false;
|
||||
for (int i = 0; i < data_length_; i++) {
|
||||
uint32_t old_data = data_[i];
|
||||
uintptr_t old_data = data_[i];
|
||||
data_[i] &= other.data_[i];
|
||||
if (data_[i] != old_data) changed = true;
|
||||
}
|
||||
@ -184,9 +181,11 @@ class BitVector: public ZoneObject {
|
||||
#endif
|
||||
|
||||
private:
|
||||
int length_;
|
||||
int data_length_;
|
||||
uint32_t* data_;
|
||||
const int length_;
|
||||
const int data_length_;
|
||||
uintptr_t* const data_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BitVector);
|
||||
};
|
||||
|
||||
|
||||
@ -195,19 +194,19 @@ class GrowableBitVector BASE_EMBEDDED {
|
||||
class Iterator BASE_EMBEDDED {
|
||||
public:
|
||||
Iterator(const GrowableBitVector* target, Zone* zone)
|
||||
: it_(target->bits_ == NULL
|
||||
? new(zone) BitVector(1, zone)
|
||||
: target->bits_) { }
|
||||
: it_(target->bits_ == NULL ? new (zone) BitVector(1, zone)
|
||||
: target->bits_) {}
|
||||
bool Done() const { return it_.Done(); }
|
||||
void Advance() { it_.Advance(); }
|
||||
int Current() const { return it_.Current(); }
|
||||
|
||||
private:
|
||||
BitVector::Iterator it_;
|
||||
};
|
||||
|
||||
GrowableBitVector() : bits_(NULL) { }
|
||||
GrowableBitVector() : bits_(NULL) {}
|
||||
GrowableBitVector(int length, Zone* zone)
|
||||
: bits_(new(zone) BitVector(length, zone)) { }
|
||||
: bits_(new (zone) BitVector(length, zone)) {}
|
||||
|
||||
bool Contains(int value) const {
|
||||
if (!InBitsRange(value)) return false;
|
||||
@ -225,7 +224,9 @@ class GrowableBitVector BASE_EMBEDDED {
|
||||
}
|
||||
}
|
||||
|
||||
void Clear() { if (bits_ != NULL) bits_->Clear(); }
|
||||
void Clear() {
|
||||
if (bits_ != NULL) bits_->Clear();
|
||||
}
|
||||
|
||||
private:
|
||||
static const int kInitialLength = 1024;
|
||||
@ -238,7 +239,7 @@ class GrowableBitVector BASE_EMBEDDED {
|
||||
if (InBitsRange(value)) return;
|
||||
int new_length = bits_ == NULL ? kInitialLength : bits_->length();
|
||||
while (new_length <= value) new_length *= 2;
|
||||
BitVector* new_bits = new(zone) BitVector(new_length, zone);
|
||||
BitVector* new_bits = new (zone) BitVector(new_length, zone);
|
||||
if (bits_ != NULL) new_bits->CopyFrom(*bits_);
|
||||
bits_ = new_bits;
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
#define V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
|
||||
|
||||
#include "src/ast.h"
|
||||
#include "src/data-flow.h"
|
||||
#include "src/bit-vector.h"
|
||||
#include "src/v8.h"
|
||||
#include "src/zone-containers.h"
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#include "src/data-flow.h"
|
||||
#include "src/bit-vector.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -7,12 +7,12 @@
|
||||
|
||||
#include "src/compiler/scheduler.h"
|
||||
|
||||
#include "src/bit-vector.h"
|
||||
#include "src/compiler/graph.h"
|
||||
#include "src/compiler/graph-inl.h"
|
||||
#include "src/compiler/node.h"
|
||||
#include "src/compiler/node-properties.h"
|
||||
#include "src/compiler/node-properties-inl.h"
|
||||
#include "src/data-flow.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "src/bit-vector.h"
|
||||
#include "src/compiler/generic-algorithm.h"
|
||||
#include "src/compiler/generic-node-inl.h"
|
||||
#include "src/compiler/generic-node.h"
|
||||
@ -21,7 +22,6 @@
|
||||
#include "src/compiler/operator.h"
|
||||
#include "src/compiler/schedule.h"
|
||||
#include "src/compiler/simplified-operator.h"
|
||||
#include "src/data-flow.h"
|
||||
#include "src/ostreams.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -10,10 +10,10 @@
|
||||
#include "src/allocation.h"
|
||||
#include "src/assert-scope.h"
|
||||
#include "src/ast.h"
|
||||
#include "src/bit-vector.h"
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/codegen.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/data-flow.h"
|
||||
#include "src/globals.h"
|
||||
#include "src/objects.h"
|
||||
|
||||
|
@ -11,9 +11,9 @@
|
||||
|
||||
#include "src/allocation.h"
|
||||
#include "src/base/bits.h"
|
||||
#include "src/bit-vector.h"
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/conversions.h"
|
||||
#include "src/data-flow.h"
|
||||
#include "src/deoptimizer.h"
|
||||
#include "src/hydrogen-types.h"
|
||||
#include "src/small-pointer-list.h"
|
||||
|
@ -102,13 +102,13 @@
|
||||
'test-atomicops.cc',
|
||||
'test-bignum.cc',
|
||||
'test-bignum-dtoa.cc',
|
||||
'test-bit-vector.cc',
|
||||
'test-checks.cc',
|
||||
'test-circular-queue.cc',
|
||||
'test-compiler.cc',
|
||||
'test-constantpool.cc',
|
||||
'test-conversions.cc',
|
||||
'test-cpu-profiler.cc',
|
||||
'test-dataflow.cc',
|
||||
'test-date.cc',
|
||||
'test-debug.cc',
|
||||
'test-declarative-accessors.cc',
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#include "src/data-flow.h"
|
||||
#include "src/bit-vector.h"
|
||||
#include "test/cctest/cctest.h"
|
||||
|
||||
using namespace v8::internal;
|
||||
@ -83,7 +83,7 @@ TEST(BitVector) {
|
||||
BitVector v(15, &zone);
|
||||
v.Add(0);
|
||||
BitVector w(15, &zone);
|
||||
w = v;
|
||||
w.CopyFrom(v);
|
||||
CHECK(w.Contains(0));
|
||||
w.Add(1);
|
||||
BitVector u(w, &zone);
|
@ -363,6 +363,8 @@
|
||||
'../../src/bignum-dtoa.h',
|
||||
'../../src/bignum.cc',
|
||||
'../../src/bignum.h',
|
||||
'../../src/bit-vector.cc',
|
||||
'../../src/bit-vector.h',
|
||||
'../../src/bootstrapper.cc',
|
||||
'../../src/bootstrapper.h',
|
||||
'../../src/builtins.cc',
|
||||
@ -515,8 +517,6 @@
|
||||
'../../src/cpu-profiler-inl.h',
|
||||
'../../src/cpu-profiler.cc',
|
||||
'../../src/cpu-profiler.h',
|
||||
'../../src/data-flow.cc',
|
||||
'../../src/data-flow.h',
|
||||
'../../src/date.cc',
|
||||
'../../src/date.h',
|
||||
'../../src/dateparser-inl.h',
|
||||
|
Loading…
Reference in New Issue
Block a user