summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/common/bitvector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/vespa/searchlib/common/bitvector.cpp')
-rw-r--r--searchlib/src/vespa/searchlib/common/bitvector.cpp62
1 files changed, 29 insertions, 33 deletions
diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp
index 47ca590c9bc..cba3ef4f842 100644
--- a/searchlib/src/vespa/searchlib/common/bitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp
@@ -23,17 +23,6 @@ using vespalib::alloc::Alloc;
namespace {
-void verifyInclusiveStart(const search::BitVector & a, const search::BitVector & b) __attribute__((noinline));
-
-void verifyInclusiveStart(const search::BitVector & a, const search::BitVector & b)
-{
- if (a.getStartIndex() < b.getStartIndex()) {
- throw IllegalArgumentException(make_string("[%d, %d] starts before which is not allowed currently [%d, %d]",
- a.getStartIndex(), a.size(), b.getStartIndex(), b.size()),
- VESPA_STRLOC);
- }
-}
-
constexpr size_t MMAP_LIMIT = 256_Mi;
}
@@ -90,11 +79,16 @@ void
BitVector::clearInterval(Index start, Index end)
{
clearIntervalNoInvalidation(Range(start, end));
-
invalidateCachedCount();
}
void
+BitVector::store(Word &word, Word value) {
+ assert(!_enable_range_check || ((&word >= getActiveStart()) && (&word < (getActiveStart() + numActiveWords()))));
+ return store_unchecked(word, value);
+}
+
+void
BitVector::clearIntervalNoInvalidation(Range range_in)
{
Range range = sanitize(range_in);
@@ -107,7 +101,7 @@ BitVector::clearIntervalNoInvalidation(Range range_in)
if (endw > startw) {
store(_words[startw], _words[startw] & startBits(range.start()));
for (Index i = startw + 1; i < endw; ++i) {
- store(_words[i], 0);
+ store_unchecked(_words[i], 0);
}
store(_words[endw], _words[endw] & endBits(last));
} else {
@@ -128,7 +122,7 @@ BitVector::setInterval(Index start_in, Index end_in)
if (endw > startw) {
store(_words[startw], _words[startw] | checkTab(range.start()));
for (Index i = startw + 1; i < endw; ++i) {
- store(_words[i], allBits());
+ store_unchecked(_words[i], allBits());
}
store(_words[endw], _words[endw] | ~endBits(last));
} else {
@@ -187,19 +181,18 @@ BitVector::countInterval(Range range_in) const
void
BitVector::orWith(const BitVector & right)
{
- verifyInclusiveStart(*this, right);
+ Range range = sanitize(right.range());
+ if ( ! range.validNonZero()) return;
if (right.size() < size()) {
- if (right.size() > 0) {
- ssize_t commonBytes = numActiveBytes(getStartIndex(), right.size()) - sizeof(Word);
- if (commonBytes > 0) {
- IAccelrated::getAccelerator().orBit(getActiveStart(), right.getWordIndex(getStartIndex()), commonBytes);
- }
- Index last(right.size() - 1);
- store(getWordIndex(last)[0], getWordIndex(last)[0] | (load(right.getWordIndex(last)[0]) & ~endBits(last)));
+ ssize_t commonBytes = numActiveBytes(range.start(), range.end()) - sizeof(Word);
+ if (commonBytes > 0) {
+ IAccelrated::getAccelerator().orBit(getWordIndex(range.start()), right.getWordIndex(range.start()), commonBytes);
}
+ Index last(range.end() - 1);
+ store(getWordIndex(last)[0], getWordIndex(last)[0] | (load(right.getWordIndex(last)[0]) & ~endBits(last)));
} else {
- IAccelrated::getAccelerator().orBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes());
+ IAccelrated::getAccelerator().orBit(getWordIndex(range.start()), right.getWordIndex(range.start()), getActiveBytes());
}
repairEnds();
invalidateCachedCount();
@@ -221,7 +214,11 @@ BitVector::repairEnds()
void
BitVector::andWith(const BitVector & right)
{
- verifyInclusiveStart(*this, right);
+ Range range = sanitize(right.range());
+ if ( ! range.validNonZero()) {
+ clear();
+ return;
+ }
uint32_t commonBytes = std::min(getActiveBytes(), numActiveBytes(getStartIndex(), right.size()));
IAccelrated::getAccelerator().andBit(getActiveStart(), right.getWordIndex(getStartIndex()), commonBytes);
@@ -237,19 +234,18 @@ BitVector::andWith(const BitVector & right)
void
BitVector::andNotWith(const BitVector& right)
{
- verifyInclusiveStart(*this, right);
+ Range range = sanitize(right.range());
+ if ( ! range.validNonZero()) return;
if (right.size() < size()) {
- if (right.size() > 0) {
- ssize_t commonBytes = numActiveBytes(getStartIndex(), right.size()) - sizeof(Word);
- if (commonBytes > 0) {
- IAccelrated::getAccelerator().andNotBit(getActiveStart(), right.getWordIndex(getStartIndex()), commonBytes);
- }
- Index last(right.size() - 1);
- store(getWordIndex(last)[0], getWordIndex(last)[0] & ~(load(right.getWordIndex(last)[0]) & ~endBits(last)));
+ ssize_t commonBytes = numActiveBytes(range.start(), range.end()) - sizeof(Word);
+ if (commonBytes > 0) {
+ IAccelrated::getAccelerator().andNotBit(getWordIndex(range.start()), right.getWordIndex(range.start()), commonBytes);
}
+ Index last(range.end() - 1);
+ store(getWordIndex(last)[0], getWordIndex(last)[0] & ~(load(right.getWordIndex(last)[0]) & ~endBits(last)));
} else {
- IAccelrated::getAccelerator().andNotBit(getActiveStart(), right.getWordIndex(getStartIndex()), getActiveBytes());
+ IAccelrated::getAccelerator().andNotBit(getWordIndex(range.start()), right.getWordIndex(range.start()), getActiveBytes());
}
repairEnds();