From f5ec9f726a2a42432569e5a9bb6d2661d665d413 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 15 Nov 2024 13:05:11 -0800 Subject: [PATCH] Remove getFirstChildExists Once we know the type, for Node3 and higher we know the first child exists anyway --- ConflictSet.cpp | 83 +++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 62 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 408d892..93fe440 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -1413,24 +1413,23 @@ TaggedNodePointer getChildGeq(Node *self, int child) { } } -Node *getFirstChild(Node0 *) { return nullptr; } -Node *getFirstChild(Node3 *self) { +TaggedNodePointer getFirstChild(Node0 *) { return nullptr; } +TaggedNodePointer getFirstChild(Node3 *self) { __builtin_prefetch(self->children[1]); - return self->numChildren == 0 ? nullptr : self->children[0]; + return self->children[0]; } -Node *getFirstChild(Node16 *self) { +TaggedNodePointer getFirstChild(Node16 *self) { __builtin_prefetch(self->children[1]); - return self->numChildren == 0 ? nullptr : self->children[0]; + return self->children[0]; } -Node *getFirstChild(Node48 *self) { - int index = self->index[self->bitSet.firstSetGeq(0)]; - return index < 0 ? nullptr : self->children[index]; +TaggedNodePointer getFirstChild(Node48 *self) { + return self->children[self->index[self->bitSet.firstSetGeq(0)]]; } -Node *getFirstChild(Node256 *self) { +TaggedNodePointer getFirstChild(Node256 *self) { return self->children[self->bitSet.firstSetGeq(0)]; } -Node *getFirstChild(Node *self) { +TaggedNodePointer getFirstChild(Node *self) { // Only require that the node-specific overloads are covered // GCOVR_EXCL_START switch (self->getType()) { @@ -1450,46 +1449,6 @@ Node *getFirstChild(Node *self) { // GCOVR_EXCL_STOP } -// Precondition: self has a child -TaggedNodePointer getFirstChildExists(Node3 *self) { - assert(self->numChildren > 0); - return self->children[0]; -} -// Precondition: self has a child -TaggedNodePointer getFirstChildExists(Node16 *self) { - assert(self->numChildren > 0); - return self->children[0]; -} -// Precondition: self has a child -TaggedNodePointer getFirstChildExists(Node48 *self) { - return self->children[self->index[self->bitSet.firstSetGeq(0)]]; -} -// Precondition: self has a child -TaggedNodePointer getFirstChildExists(Node256 *self) { - return self->children[self->bitSet.firstSetGeq(0)]; -} - -// Precondition: self has a child -TaggedNodePointer getFirstChildExists(Node *self) { - // Only require that the node-specific overloads are covered - // GCOVR_EXCL_START - switch (self->getType()) { - case Type_Node0: - __builtin_unreachable(); - case Type_Node3: - return getFirstChildExists(static_cast(self)); - case Type_Node16: - return getFirstChildExists(static_cast(self)); - case Type_Node48: - return getFirstChildExists(static_cast(self)); - case Type_Node256: - return getFirstChildExists(static_cast(self)); - default: - __builtin_unreachable(); - } - // GCOVR_EXCL_STOP -} - // self must not be the root void maybeDecreaseCapacity(Node *&self, WriteContext *writeContext, ConflictSet::Impl *impl); @@ -1779,7 +1738,7 @@ Node *nextLogical(Node *node) { } } downLeftSpine: - for (; !node->entryPresent; node = getFirstChildExists(node)) { + for (; !node->entryPresent; node = getFirstChild(node)) { } return node; } @@ -2827,7 +2786,7 @@ bool checkRangeStartsWith(NodeT *nTyped, TrivialSpan key, int begin, int end, __builtin_unreachable(); // GCOVR_EXCL_LINE downLeftSpine: - for (; !n->entryPresent; n = getFirstChildExists(n)) { + for (; !n->entryPresent; n = getFirstChild(n)) { } return n->entry.rangeVersion <= readVersion; } @@ -3284,7 +3243,7 @@ PRESERVE_NONE void down_left_spine(Job *job, Context *context) { job->setResult(n->entry.rangeVersion <= job->readVersion); MUSTTAIL return complete(job, context); } - auto child = getFirstChildExists(n); + auto child = getFirstChild(n); job->n = child; __builtin_prefetch(job->n); job->continuation = downLeftSpineTable[child.getType()]; @@ -3379,7 +3338,7 @@ template void iter(Job *job, Context *context) { job->setResult(n->entry.pointVersion <= job->readVersion); MUSTTAIL return complete(job, context); } - auto c = getFirstChildExists(n); + auto c = getFirstChild(n); job->n = c; job->continuation = downLeftSpineTable[c.getType()]; __builtin_prefetch(job->n); @@ -3903,7 +3862,7 @@ void left_side_down_left_spine(Job *job, Context *context) { } MUSTTAIL return done_left_side_iter(job, context); } - auto c = getFirstChildExists(n); + auto c = getFirstChild(n); job->n = c; job->continuation = leftSideDownLeftSpineTable[c.getType()]; __builtin_prefetch(job->n); @@ -4566,7 +4525,7 @@ bool checkPointRead(Node *n, const TrivialSpan key, if (n->entryPresent) { return n->entry.pointVersion <= readVersion; } - n = getFirstChildExists(n); + n = getFirstChild(n); goto downLeftSpine; } @@ -4620,7 +4579,7 @@ bool checkPointRead(Node *n, const TrivialSpan key, } } downLeftSpine: - for (; !n->entryPresent; n = getFirstChildExists(n)) { + for (; !n->entryPresent; n = getFirstChild(n)) { } return n->entry.rangeVersion <= readVersion; } @@ -4695,7 +4654,7 @@ bool checkPrefixRead(Node *n, const TrivialSpan key, } } downLeftSpine: - for (; !n->entryPresent; n = getFirstChildExists(n)) { + for (; !n->entryPresent; n = getFirstChild(n)) { } return n->entry.rangeVersion <= readVersion; } @@ -4782,7 +4741,7 @@ bool checkRangeLeftSide(Node *n, TrivialSpan key, int prefixLen, } } downLeftSpine: - for (; !n->entryPresent; n = getFirstChildExists(n)) { + for (; !n->entryPresent; n = getFirstChild(n)) { } return n->entry.rangeVersion <= readVersion; } @@ -4878,7 +4837,7 @@ backtrack: } } downLeftSpine: - for (; !n->entryPresent; n = getFirstChildExists(n)) { + for (; !n->entryPresent; n = getFirstChild(n)) { } return n->entry.rangeVersion <= readVersion; } @@ -5651,7 +5610,7 @@ Node *firstGeqLogical(Node *n, const TrivialSpan key) { if (n->entryPresent) { return n; } - n = getFirstChildExists(n); + n = getFirstChild(n); goto downLeftSpine; } @@ -5696,7 +5655,7 @@ Node *firstGeqLogical(Node *n, const TrivialSpan key) { } } downLeftSpine: - for (; !n->entryPresent; n = getFirstChildExists(n)) { + for (; !n->entryPresent; n = getFirstChild(n)) { } return n; }