From d388f6488d15dba8b0cc6349efea8c318333db63 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 8 Feb 2024 10:13:53 -0800 Subject: [PATCH] Remove dead code --- ConflictSet.cpp | 257 +++++++++++++----------------------------------- 1 file changed, 69 insertions(+), 188 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index decbc79..d235de9 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -115,21 +115,6 @@ struct BitSet { return -1; } - int lastSetLeq(int i) const { - if (i >= 128) { - int a = std::countl_zero(hi << (255 - i)); - if (a < 128) { - return i - a; - } - i = 127; - } - int b = std::countl_zero(lo << (127 - i)); - if (b < 128) { - return i - b; - } - return -1; - } - private: __uint128_t lo = 0; __uint128_t hi = 0; @@ -318,83 +303,6 @@ int getChildGeq(Node *self, int child) { return -1; } -int getChildLeq(Node *self, int child) { - if (child < 0) { - return -1; - } - if (self->type == Type::Node4) { - auto *self4 = static_cast(self); - for (int i = self->numChildren - 1; i >= 0; --i) { - if (i > 0) { - assert(self4->index[i - 1] < self4->index[i]); - } - if (self4->index[i] <= child) { - return self4->index[i]; - } - } - } else if (self->type == Type::Node16) { - auto *self16 = static_cast(self); -#ifdef HAS_AVX - __m128i key_vec = _mm_set1_epi8(child); - __m128i indices; - memcpy(&indices, self16->index, sizeof(self16->index)); - __m128i results = _mm_cmpeq_epi8(key_vec, _mm_max_epu8(key_vec, indices)); - int mask = (1 << self16->numChildren) - 1; - uint32_t bitfield = _mm_movemask_epi8(results) & mask; - int result = - bitfield == 0 ? -1 : self16->index[31 - std::countl_zero(bitfield)]; - assert(result == [&]() -> int { - for (int i = self16->numChildren - 1; i >= 0; --i) { - if (self16->index[i] <= child) { - return self16->index[i]; - } - } - return -1; - }()); - return result; -#elif defined(HAS_ARM_NEON) - uint8x16_t indices; - memcpy(&indices, self16->index, sizeof(self16->index)); - // 0xff for each leq - auto results = vcleq_u8(indices, vdupq_n_u8(child)); - uint64_t mask = self->numChildren == 16 - ? uint64_t(-1) - : (uint64_t(1) << (self->numChildren * 4)) - 1; - // 0xf for each 0xff (within mask) - uint64_t bitfield = - vget_lane_u64( - vreinterpret_u64_u8(vshrn_n_u16(vreinterpretq_u16_u8(results), 4)), - 0) & - mask; - int simd = - bitfield == 0 ? -1 : self16->index[15 - std::countl_zero(bitfield) / 4]; - assert(simd == [&]() -> int { - for (int i = self->numChildren - 1; i >= 0; --i) { - if (self16->index[i] <= child) { - return self16->index[i]; - } - } - return -1; - }()); - return simd; -#else - for (int i = self->numChildren - 1; i >= 0; --i) { - if (self16->index[i] <= child) { - return self16->index[i]; - } - } - return -1; -#endif - } else if (self->type == Type::Node48) { - auto *self48 = static_cast(self); - return self48->bitSet.lastSetLeq(child); - } else { - auto *self256 = static_cast(self); - return self256->bitSet.lastSetLeq(child); - } - return -1; -} - void setChildrenParents(Node *node) { for (int i = getChildGeq(node, 0); i >= 0; i = getChildGeq(node, i + 1)) { getChildExists(node, i)->parent = node; @@ -584,102 +492,11 @@ Node *nextLogical(Node *node) { return node; } -Node *prevPhysical(Node *node) { - assert(node->parent != nullptr); - auto prevChild = getChildLeq(node->parent, node->parentsIndex - 1); - assert(prevChild < node->parentsIndex); - if (prevChild >= 0) { - node = getChildExists(node->parent, prevChild); - // Move down the right spine - for (;;) { - auto rightMostChild = getChildLeq(node, 255); - if (rightMostChild >= 0) { - node = getChildExists(node, rightMostChild); - } else { - return node; - } - } - } else { - return node->parent; - } -} - -Node *prevLogical(Node *node) { - for (node = prevPhysical(node); node != nullptr && !node->entryPresent; - node = prevPhysical(node)) - ; - return node; -} - struct Iterator { Node *n; int cmp; }; -namespace { -std::string getSearchPathPrintable(Node *n) { - Arena arena; - if (n == nullptr) { - return ""; - } - auto result = vector(arena); - for (;;) { - for (int i = n->partialKeyLen - 1; i >= 0; --i) { - result.push_back(n->partialKey[i]); - } - if (n->parent == nullptr) { - break; - } - result.push_back(n->parentsIndex); - n = n->parent; - } - std::reverse(result.begin(), result.end()); - if (result.size() > 0) { - return printable(std::string_view((const char *)&result[0], - result.size())); // NOLINT - } else { - return std::string(); - } -} - -std::string strinc(std::string_view str, bool &ok) { - int index; - for (index = str.size() - 1; index >= 0; index--) - if (str[index] != 255) - break; - - // Must not be called with a string that consists only of zero or more '\xff' - // bytes. - if (index < 0) { - ok = false; - return {}; - } - ok = true; - - auto r = std::string(str.substr(0, index + 1)); - ((uint8_t &)r[r.size() - 1])++; - return r; -} - -std::string getSearchPath(Node *n) { - assert(n != nullptr); - Arena arena; - auto result = vector(arena); - for (;;) { - for (int i = n->partialKeyLen - 1; i >= 0; --i) { - result.push_back(n->partialKey[i]); - } - if (n->parent == nullptr) { - break; - } - result.push_back(n->parentsIndex); - n = n->parent; - } - std::reverse(result.begin(), result.end()); - return std::string((const char *)result.data(), result.size()); -} -} // namespace - struct FirstGeqStepwise { Node *n; std::span remaining; @@ -729,6 +546,7 @@ struct FirstGeqStepwise { } } } + [[fallthrough]]; case Init: phase = Search; if (n->partialKeyLen > 0) { @@ -766,6 +584,7 @@ struct FirstGeqStepwise { n = getChildExists(n, c); return false; } + __builtin_unreachable(); // GCOVR_EXCL_LINE } bool downLeftSpine() { @@ -785,11 +604,6 @@ Iterator firstGeq(Node *n, const std::span key) { return {stepwise.n, stepwise.cmp}; } -Iterator firstGeq(Node *n, std::string_view key) { - return firstGeq( - n, std::span((const uint8_t *)key.data(), key.size())); -} - // Logically this is the same as performing firstGeq and then checking against // point or range version according to cmp, but this version short circuits as // soon as it can prove that there's no conflict @@ -1191,6 +1005,68 @@ __attribute__((__visibility__("default"))) void ConflictSet_destroy(void *cs) { namespace { +std::string getSearchPathPrintable(Node *n) { + Arena arena; + if (n == nullptr) { + return ""; + } + auto result = vector(arena); + for (;;) { + for (int i = n->partialKeyLen - 1; i >= 0; --i) { + result.push_back(n->partialKey[i]); + } + if (n->parent == nullptr) { + break; + } + result.push_back(n->parentsIndex); + n = n->parent; + } + std::reverse(result.begin(), result.end()); + if (result.size() > 0) { + return printable(std::string_view((const char *)&result[0], + result.size())); // NOLINT + } else { + return std::string(); + } +} + +std::string strinc(std::string_view str, bool &ok) { + int index; + for (index = str.size() - 1; index >= 0; index--) + if (str[index] != 255) + break; + + // Must not be called with a string that consists only of zero or more '\xff' + // bytes. + if (index < 0) { + ok = false; + return {}; + } + ok = true; + + auto r = std::string(str.substr(0, index + 1)); + ((uint8_t &)r[r.size() - 1])++; + return r; +} + +std::string getSearchPath(Node *n) { + assert(n != nullptr); + Arena arena; + auto result = vector(arena); + for (;;) { + for (int i = n->partialKeyLen - 1; i >= 0; --i) { + result.push_back(n->partialKey[i]); + } + if (n->parent == nullptr) { + break; + } + result.push_back(n->parentsIndex); + n = n->parent; + } + std::reverse(result.begin(), result.end()); + return std::string((const char *)result.data(), result.size()); +} + [[maybe_unused]] void debugPrintDot(FILE *file, Node *node) { constexpr int kSeparation = 2; @@ -1245,6 +1121,11 @@ void checkParentPointers(Node *node, bool &success) { } } +Iterator firstGeq(Node *n, std::string_view key) { + return firstGeq( + n, std::span((const uint8_t *)key.data(), key.size())); +} + [[maybe_unused]] int64_t checkMaxVersion(Node *root, Node *node, bool &success) { int64_t expected = std::numeric_limits::lowest();