Ian Rogers | e77493c | 2014-08-20 15:08:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_BASE_BIT_VECTOR_INL_H_ |
| 18 | #define ART_RUNTIME_BASE_BIT_VECTOR_INL_H_ |
| 19 | |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 20 | #include "base/bit_utils.h" |
Ian Rogers | e77493c | 2014-08-20 15:08:45 -0700 | [diff] [blame] | 21 | #include "bit_vector.h" |
| 22 | #include "logging.h" |
Ian Rogers | e77493c | 2014-08-20 15:08:45 -0700 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | inline bool BitVector::IndexIterator::operator==(const IndexIterator& other) const { |
| 27 | DCHECK(bit_storage_ == other.bit_storage_); |
| 28 | DCHECK_EQ(storage_size_, other.storage_size_); |
| 29 | return bit_index_ == other.bit_index_; |
| 30 | } |
| 31 | |
Vladimir Marko | 0407196 | 2015-01-02 17:00:44 +0000 | [diff] [blame] | 32 | inline uint32_t BitVector::IndexIterator::operator*() const { |
Ian Rogers | e77493c | 2014-08-20 15:08:45 -0700 | [diff] [blame] | 33 | DCHECK_LT(bit_index_, BitSize()); |
| 34 | return bit_index_; |
| 35 | } |
| 36 | |
| 37 | inline BitVector::IndexIterator& BitVector::IndexIterator::operator++() { |
| 38 | DCHECK_LT(bit_index_, BitSize()); |
| 39 | bit_index_ = FindIndex(bit_index_ + 1u); |
| 40 | return *this; |
| 41 | } |
| 42 | |
| 43 | inline BitVector::IndexIterator BitVector::IndexIterator::operator++(int) { |
| 44 | IndexIterator result(*this); |
| 45 | ++*this; |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | inline uint32_t BitVector::IndexIterator::FindIndex(uint32_t start_index) const { |
| 50 | DCHECK_LE(start_index, BitSize()); |
| 51 | uint32_t word_index = start_index / kWordBits; |
| 52 | if (UNLIKELY(word_index == storage_size_)) { |
| 53 | return start_index; |
| 54 | } |
| 55 | uint32_t word = bit_storage_[word_index]; |
| 56 | // Mask out any bits in the first word we've already considered. |
| 57 | word &= static_cast<uint32_t>(-1) << (start_index & 0x1f); |
| 58 | while (word == 0u) { |
| 59 | ++word_index; |
| 60 | if (UNLIKELY(word_index == storage_size_)) { |
| 61 | return BitSize(); |
| 62 | } |
| 63 | word = bit_storage_[word_index]; |
| 64 | } |
| 65 | return word_index * 32u + CTZ(word); |
| 66 | } |
| 67 | |
| 68 | inline void BitVector::ClearAllBits() { |
| 69 | memset(storage_, 0, storage_size_ * kWordBytes); |
| 70 | } |
| 71 | |
| 72 | inline bool BitVector::Equal(const BitVector* src) const { |
| 73 | return (storage_size_ == src->GetStorageSize()) && |
| 74 | (expandable_ == src->IsExpandable()) && |
| 75 | (memcmp(storage_, src->GetRawStorage(), storage_size_ * sizeof(uint32_t)) == 0); |
| 76 | } |
| 77 | |
| 78 | } // namespace art |
| 79 | |
| 80 | #endif // ART_RUNTIME_BASE_BIT_VECTOR_INL_H_ |