Skip to content

Commit

Permalink
perf: branchless symbol unpacker
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Mar 24, 2024
1 parent 0fca01c commit fefe679
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/crackcodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,17 @@ std::vector<uint8_t> unpack_codepoints(
std::vector<uint8_t> codepoints;
codepoints.reserve(4 * (code.size() - index_size));

uint8_t last = 0;

for (uint64_t i = index_size; i < code.size(); i++) {
for (uint64_t j = 0; j < 4; j++) {
uint8_t codepoint = static_cast<uint8_t>((code[i] >> (2*j)) & 0b11);
codepoint += last;
codepoint &= 0b11;
last = codepoint;
codepoints.push_back(codepoint);
}
}
for (uint64_t i = 1; i < codepoints.size(); i++) {
codepoints[i] += codepoints[i-1];
if (codepoints[i] > 3) {
codepoints[i] -= 4;
}
}

return codepoints;
}
Expand Down

0 comments on commit fefe679

Please sign in to comment.