diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-12-14 23:17:11 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-12-14 23:17:11 +0000 |
commit | 8ae351c9e1c4bdababc210f2d0119b92017a0b7a (patch) | |
tree | 80b42da3383c5b48c6460b1b2de113fcc97a02b7 /searchlib | |
parent | 85eb89cbd200440766975bda21f7e34b0d065c2b (diff) |
Hint at the most likely branches.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp b/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp index 1d6da48f131..6d181c5bbe1 100644 --- a/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp @@ -19,7 +19,7 @@ struct And { void operator () (const IAccelrated & accel, size_t offset, const std::vector<Meta> & src, void *dest) noexcept { accel.and256(offset, src, dest); } - static bool isAnd() noexcept { return true; } + static constexpr bool isAnd() noexcept { return true; } }; struct Or { @@ -27,7 +27,7 @@ struct Or { void operator () (const IAccelrated & accel, size_t offset, const std::vector<Meta> & src, void *dest) noexcept { accel.or256(offset, src, dest); } - static bool isAnd() noexcept { return false; } + static constexpr bool isAnd() noexcept { return false; } }; } @@ -85,21 +85,17 @@ MultiBitVector<Update>::fetchChunk(uint32_t index) noexcept _lastMaxDocIdLimitRequireFetch = (baseIndex + NumWordsInBatch) * BitWord::WordLen; } - - - template<typename Update> uint32_t MultiBitVector<Update>::strictSeek(uint32_t docId) noexcept { bool atEnd; for (atEnd = updateLastValue(docId), _lastValue = _lastValue & BitWord::checkTab(docId); - (_lastValue == 0) && __builtin_expect(! atEnd, true); + __builtin_expect(_lastValue == 0, Update::isAnd()) && __builtin_expect(! atEnd, true); // And is likely to have few bits, while Or has many. atEnd = updateLastValue(_lastMaxDocIdLimit)); - if (__builtin_expect(!atEnd, true)) { - return _lastMaxDocIdLimit - BitWord::WordLen + vespalib::Optimized::lsbIdx(_lastValue); - } - return _numDocs; + return (__builtin_expect(!atEnd, true)) + ? _lastMaxDocIdLimit - BitWord::WordLen + vespalib::Optimized::lsbIdx(_lastValue) + : _numDocs; } template<typename Update> @@ -107,12 +103,8 @@ bool MultiBitVector<Update>::seek(uint32_t docId) noexcept { bool atEnd = updateLastValue(docId); - if (__builtin_expect( ! atEnd, true)) { - if (_lastValue & BitWord::mask(docId)) { - return true; - } - } - return false; + return __builtin_expect( ! atEnd, true) && + __builtin_expect(_lastValue & BitWord::mask(docId), false); } namespace { @@ -167,7 +159,7 @@ template<typename Update> void MultiBitVectorIterator<Update>::doSeek(uint32_t docId) { - if (_mbv.seek(docId)) { + if (_mbv.seek(docId)) [[unlikely]] { setDocId(docId); } } |