diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 5acfce9..8568c9e 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -1243,15 +1243,11 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl, (parent->numChildren - (nodeIndex + 1))); --parent->numChildren; - if (parent->numChildren == 0 && !parent->entryPresent && - parent->parent != nullptr) { - return erase(parent, allocators, impl, dontInvalidate); - } else { - const bool update = result == dontInvalidate; - maybeDownsize(parent, allocators, impl, result); - if (update) { - dontInvalidate = result; - } + assert(parent->numChildren > 0 || parent->entryPresent); + const bool update = result == dontInvalidate; + maybeDownsize(parent, allocators, impl, result); + if (update) { + dontInvalidate = result; } } break; case Type_Node16: { @@ -1266,16 +1262,16 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl, (parent->numChildren - (nodeIndex + 1))); --parent->numChildren; - if (parent->numChildren == 0 && !parent->entryPresent && - parent->parent != nullptr) { - return erase(parent, allocators, impl, dontInvalidate); - } else { - const bool update = result == dontInvalidate; - maybeDownsize(parent, allocators, impl, result); - if (update) { - dontInvalidate = result; - } + + // By kMinChildrenNode16 + assert(parent->numChildren > 0); + + const bool update = result == dontInvalidate; + maybeDownsize(parent, allocators, impl, result); + if (update) { + dontInvalidate = result; } + } break; case Type_Node48: { auto *parent48 = static_cast(parent); @@ -1293,15 +1289,14 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl, } --parent->numChildren; - if (parent->numChildren == 0 && !parent->entryPresent && - parent->parent != nullptr) { - return erase(parent, allocators, impl, dontInvalidate); - } else { - const bool update = result == dontInvalidate; - maybeDownsize(parent, allocators, impl, result); - if (update) { - dontInvalidate = result; - } + + // By kMinChildrenNode48 + assert(parent->numChildren > 0); + + const bool update = result == dontInvalidate; + maybeDownsize(parent, allocators, impl, result); + if (update) { + dontInvalidate = result; } } break; case Type_Node256: { @@ -1310,15 +1305,14 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl, parent256->children[parentsIndex].child = nullptr; --parent->numChildren; - if (parent->numChildren == 0 && !parent->entryPresent && - parent->parent != nullptr) { - return erase(parent, allocators, impl, dontInvalidate); - } else { - const bool update = result == dontInvalidate; - maybeDownsize(parent, allocators, impl, result); - if (update) { - dontInvalidate = result; - } + + // By kMinChildrenNode256 + assert(parent->numChildren > 0); + + const bool update = result == dontInvalidate; + maybeDownsize(parent, allocators, impl, result); + if (update) { + dontInvalidate = result; } } break; default: // GCOVR_EXCL_LINE @@ -1358,7 +1352,7 @@ constexpr int kUnrollFactor = 4; bool compareStride(const uint8_t *ap, const uint8_t *bp) { #if defined(HAS_ARM_NEON) static_assert(kStride == 64); - uint8x16_t x[4]; + uint8x16_t x[4]; // GCOVR_EXCL_LINE for (int i = 0; i < 4; ++i) { x[i] = vceqq_u8(vld1q_u8(ap + i * 16), vld1q_u8(bp + i * 16)); } @@ -1368,7 +1362,7 @@ bool compareStride(const uint8_t *ap, const uint8_t *bp) { uint64_t(-1); #elif defined(HAS_AVX) static_assert(kStride == 64); - __m128i x[4]; + __m128i x[4]; // GCOVR_EXCL_LINE for (int i = 0; i < 4; ++i) { x[i] = _mm_cmpeq_epi8(_mm_loadu_si128((__m128i *)(ap + i * 16)), _mm_loadu_si128((__m128i *)(bp + i * 16))); @@ -1387,7 +1381,7 @@ bool compareStride(const uint8_t *ap, const uint8_t *bp) { int firstNeqStride(const uint8_t *ap, const uint8_t *bp) { #if defined(HAS_AVX) static_assert(kStride == 64); - uint64_t c[kStride / 16]; + uint64_t c[kStride / 16]; // GCOVR_EXCL_LINE for (int i = 0; i < kStride; i += 16) { const auto a = _mm_loadu_si128((__m128i *)(ap + i)); const auto b = _mm_loadu_si128((__m128i *)(bp + i)); @@ -1422,6 +1416,7 @@ int firstNeqStride(const uint8_t *ap, const uint8_t *bp) { int longestCommonPrefix(const uint8_t *ap, const uint8_t *bp, int cl) { assume(cl >= 0); + printf("cl: %d\n", cl); int i = 0; int end; @@ -1429,18 +1424,6 @@ int longestCommonPrefix(const uint8_t *ap, const uint8_t *bp, int cl) { goto bytes; } - // Optimistic early return - { - uint64_t a; - uint64_t b; - memcpy(&a, ap, 8); - memcpy(&b, bp, 8); - const auto mismatched = a ^ b; - if (mismatched) { - return std::countr_zero(mismatched) / 8; - } - } - // kStride * kUnrollCount at a time end = cl & ~(kStride * kUnrollFactor - 1); while (i < end) { @@ -1468,8 +1451,8 @@ int longestCommonPrefix(const uint8_t *ap, const uint8_t *bp, int cl) { // word at a time end = cl & ~(sizeof(uint64_t) - 1); while (i < end) { - uint64_t a; - uint64_t b; + uint64_t a; // GCOVR_EXCL_LINE + uint64_t b; // GCOVR_EXCL_LINE memcpy(&a, ap, 8); memcpy(&b, bp, 8); const auto mismatched = a ^ b; @@ -1624,7 +1607,7 @@ int64_t maxBetweenExclusive(Node *n, int begin, int end) { } } switch (n->getType()) { - case Type_Node0: + case Type_Node0: // GCOVR_EXCL_LINE // We would have returned above, after not finding a child __builtin_unreachable(); // GCOVR_EXCL_LINE case Type_Node3: { @@ -1687,7 +1670,7 @@ Vector getSearchPath(Arena &arena, Node *n) { } std::reverse(result.begin(), result.end()); return result; -} +} // GCOVR_EXCL_LINE // Return true if the max version among all keys that start with key + [child], // where begin < child < end, is <= readVersion diff --git a/script_tests/long-common-prefix.txt b/script_tests/long-common-prefix.txt new file mode 100644 index 0000000..0bbc74b --- /dev/null +++ b/script_tests/long-common-prefix.txt @@ -0,0 +1,19 @@ +begin aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +end aaaaaaaaa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