Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Today I decided to reinvent this algorithm. Then I remembered this project, and decided to see if this repository had a better idea.
Turns out, my version had a few slight improvements over the implementation here.
(k | 0x80) * ones_step_8
rather than(k * ones_step_8) | msbs_step_8
. This is helpful because we want to avoid loadingmsbs_step_8
when not using the popcount implementation.& ~uint64_t(0x7)
. This is easy to prove, since the maximum value it can operate on is00001000_00000111_00000110_00000101_00000100_00000011_00000010_00000001
. Since the byte under the most significant byte can be a 7 at most, the upper 3 bits of that second byte are always 0. Therefore we do not need to zero them out.(x & msbs_step_8) >> 7
we can do(x >> 7) & ones_step_8
, which means we do not have to loadmsbs_step_8
.