Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize select_in_word #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Validark
Copy link

@Validark Validark commented Jan 3, 2024

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.

  1. We can do (k | 0x80) * ones_step_8 rather than (k * ones_step_8) | msbs_step_8. This is helpful because we want to avoid loading msbs_step_8 when not using the popcount implementation.
  2. We do not need & ~uint64_t(0x7). This is easy to prove, since the maximum value it can operate on is 00001000_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.
  3. Rather than doing (x & msbs_step_8) >> 7 we can do (x >> 7) & ones_step_8, which means we do not have to load msbs_step_8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant