aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-12-14 23:17:11 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-12-15 15:57:43 +0000
commit82b20e53fc6d1b949955f9cfe6f4048b7de94640 (patch)
treea1290bf3a5a4e3934ec82c4c1715196e29fd0600
parent2a0b850e93cb8d228e9017ab23a0bfc231865b30 (diff)
Hint at the most likely branches.
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp26
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 b13bf4a10e2..66f505581c7 100644
--- a/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp
@@ -20,7 +20,7 @@ struct And {
void operator () (const IAccelrated & accel, size_t offset, const std::vector<Meta> & src, void *dest) noexcept {
accel.and64(offset, src, dest);
}
- static bool isAnd() noexcept { return true; }
+ static constexpr bool isAnd() noexcept { return true; }
};
struct Or {
@@ -28,7 +28,7 @@ struct Or {
void operator () (const IAccelrated & accel, size_t offset, const std::vector<Meta> & src, void *dest) noexcept {
accel.or64(offset, src, dest);
}
- static bool isAnd() noexcept { return false; }
+ static constexpr bool isAnd() noexcept { return false; }
};
}
@@ -86,21 +86,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>
@@ -108,12 +104,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 {
@@ -168,7 +160,7 @@ template<typename Update>
void
MultiBitVectorIterator<Update>::doSeek(uint32_t docId)
{
- if (_mbv.seek(docId)) {
+ if (_mbv.seek(docId)) [[unlikely]] {
setDocId(docId);
}
}