From fefe679d3b035170f2f343f2e79273d49da8af52 Mon Sep 17 00:00:00 2001 From: William Silversmith Date: Sun, 24 Mar 2024 00:17:32 -0400 Subject: [PATCH] perf: branchless symbol unpacker --- src/crackcodes.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/crackcodes.hpp b/src/crackcodes.hpp index 532b682..bbc8c2d 100644 --- a/src/crackcodes.hpp +++ b/src/crackcodes.hpp @@ -624,18 +624,17 @@ std::vector unpack_codepoints( std::vector 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((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; }