Commit ae4506e2 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[TurboProp] Optimize BitVector::Iterator::Advance.

Optimizes BitVector::Iterator::Advance by using base::bits::CountTrailingZeros to
skip through bitvector. Also inlines Advance in the header. This reduces the
LiveRangeAnalysis phase of TurboFan/Prop by about 2-5% on Octane.

BUG=v8:9684

Change-Id: I3954d50d8ae9bd062a153e1fa2cb0abfd43d73eb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1910948
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64920}
parent 502261d9
...@@ -25,21 +25,6 @@ void BitVector::Print() { ...@@ -25,21 +25,6 @@ void BitVector::Print() {
} }
#endif #endif
void BitVector::Iterator::Advance() {
current_++;
uintptr_t val = current_value_;
while (val == 0) {
current_index_++;
if (Done()) return;
DCHECK(!target_->is_inline());
val = target_->data_.ptr_[current_index_];
current_ = current_index_ << kDataBitShift;
}
val = SkipZeroBytes(val);
val = SkipZeroBits(val);
current_value_ = val >> 1;
}
int BitVector::Count() const { int BitVector::Count() const {
if (is_inline()) return base::bits::CountPopulation(data_.inline_); if (is_inline()) return base::bits::CountPopulation(data_.inline_);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef V8_UTILS_BIT_VECTOR_H_ #ifndef V8_UTILS_BIT_VECTOR_H_
#define V8_UTILS_BIT_VECTOR_H_ #define V8_UTILS_BIT_VECTOR_H_
#include "src/base/bits.h"
#include "src/utils/allocation.h" #include "src/utils/allocation.h"
#include "src/zone/zone.h" #include "src/zone/zone.h"
...@@ -34,7 +35,27 @@ class V8_EXPORT_PRIVATE BitVector : public ZoneObject { ...@@ -34,7 +35,27 @@ class V8_EXPORT_PRIVATE BitVector : public ZoneObject {
~Iterator() = default; ~Iterator() = default;
bool Done() const { return current_index_ >= target_->data_length_; } bool Done() const { return current_index_ >= target_->data_length_; }
V8_EXPORT_PRIVATE void Advance();
V8_EXPORT_PRIVATE inline void Advance() {
current_++;
// Skip zeroed words.
while (current_value_ == 0) {
current_index_++;
if (Done()) return;
DCHECK(!target_->is_inline());
current_value_ = target_->data_.ptr_[current_index_];
current_ = current_index_ << kDataBitShift;
}
// Skip zeroed bits.
uintptr_t trailing_zeros = base::bits::CountTrailingZeros(current_value_);
current_ += trailing_zeros;
current_value_ >>= trailing_zeros;
// Get current_value ready for next advance.
current_value_ >>= 1;
}
int Current() const { int Current() const {
DCHECK(!Done()); DCHECK(!Done());
...@@ -42,19 +63,10 @@ class V8_EXPORT_PRIVATE BitVector : public ZoneObject { ...@@ -42,19 +63,10 @@ class V8_EXPORT_PRIVATE BitVector : public ZoneObject {
} }
private: private:
uintptr_t SkipZeroBytes(uintptr_t val) {
while ((val & 0xFF) == 0) {
val >>= 8;
current_ += 8;
}
return val;
}
uintptr_t SkipZeroBits(uintptr_t val) { uintptr_t SkipZeroBits(uintptr_t val) {
while ((val & 0x1) == 0) { uintptr_t trailing_zeros = base::bits::CountTrailingZeros(val);
val >>= 1; current_ += trailing_zeros;
current_++; return val >> trailing_zeros;
}
return val;
} }
BitVector* target_; BitVector* target_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment