Skip to content

Commit

Permalink
Fixed horizontal lookup table packer scaling. (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iluvmagick authored Nov 10, 2023
1 parent 942ecc8 commit a327234
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ namespace nil {
namespace snark {
namespace detail {
std::size_t next_power_of_two_minus_3(std::size_t x) {
BOOST_ASSERT_MSG(x > 2, "x must be greater than 2");
std::size_t result = (1 << __builtin_clz((x | 1) << 1)) - 2;
if (result <= x) {
result = (1 << __builtin_clz(result << 1)) - 2;
std::size_t bit_count = 0;
const std::size_t original_x = x;
while (x >>= 1) {
bit_count++;
}
return result - 2;
std::size_t result = (1 << (bit_count + 1)) - 2;
if (result <= original_x) {
result = (1 << (bit_count + 2)) - 2;
}
return result;
}
};

Expand Down

0 comments on commit a327234

Please sign in to comment.