Skip to content

Commit ae4506e

Browse files
rmcilroyCommit Bot
authored andcommitted
[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: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#64920}
1 parent 502261d commit ae4506e

2 files changed

Lines changed: 25 additions & 28 deletions

File tree

src/utils/bit-vector.cc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ void BitVector::Print() {
2525
}
2626
#endif
2727

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-
DCHECK(!target_->is_inline());
35-
val = target_->data_.ptr_[current_index_];
36-
current_ = current_index_ << kDataBitShift;
37-
}
38-
val = SkipZeroBytes(val);
39-
val = SkipZeroBits(val);
40-
current_value_ = val >> 1;
41-
}
42-
4328
int BitVector::Count() const {
4429
if (is_inline()) return base::bits::CountPopulation(data_.inline_);
4530

src/utils/bit-vector.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef V8_UTILS_BIT_VECTOR_H_
66
#define V8_UTILS_BIT_VECTOR_H_
77

8+
#include "src/base/bits.h"
89
#include "src/utils/allocation.h"
910
#include "src/zone/zone.h"
1011

@@ -34,27 +35,38 @@ class V8_EXPORT_PRIVATE BitVector : public ZoneObject {
3435
~Iterator() = default;
3536

3637
bool Done() const { return current_index_ >= target_->data_length_; }
37-
V8_EXPORT_PRIVATE void Advance();
38+
39+
V8_EXPORT_PRIVATE inline void Advance() {
40+
current_++;
41+
42+
// Skip zeroed words.
43+
while (current_value_ == 0) {
44+
current_index_++;
45+
if (Done()) return;
46+
DCHECK(!target_->is_inline());
47+
current_value_ = target_->data_.ptr_[current_index_];
48+
current_ = current_index_ << kDataBitShift;
49+
}
50+
51+
// Skip zeroed bits.
52+
uintptr_t trailing_zeros = base::bits::CountTrailingZeros(current_value_);
53+
current_ += trailing_zeros;
54+
current_value_ >>= trailing_zeros;
55+
56+
// Get current_value ready for next advance.
57+
current_value_ >>= 1;
58+
}
3859

3960
int Current() const {
4061
DCHECK(!Done());
4162
return current_;
4263
}
4364

4465
private:
45-
uintptr_t SkipZeroBytes(uintptr_t val) {
46-
while ((val & 0xFF) == 0) {
47-
val >>= 8;
48-
current_ += 8;
49-
}
50-
return val;
51-
}
5266
uintptr_t SkipZeroBits(uintptr_t val) {
53-
while ((val & 0x1) == 0) {
54-
val >>= 1;
55-
current_++;
56-
}
57-
return val;
67+
uintptr_t trailing_zeros = base::bits::CountTrailingZeros(val);
68+
current_ += trailing_zeros;
69+
return val >> trailing_zeros;
5870
}
5971

6072
BitVector* target_;

0 commit comments

Comments
 (0)