Skip to content

Commit

Permalink
fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rnburn committed Nov 5, 2024
1 parent 559c83e commit 0692361
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions sxt/multiexp/pippenger2/variable_length_computation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "sxt/multiexp/pippenger2/variable_length_computation.h"

#include <algorithm>
#include <numeric>

#include "sxt/base/error/assert.h"

Expand Down Expand Up @@ -59,4 +60,11 @@ void compute_product_length_table(basct::span<unsigned>& product_lengths,
}
product_lengths = product_lengths.subspan(0, product_index);
}

//--------------------------------------------------------------------------------------------------
// count_products
//--------------------------------------------------------------------------------------------------
size_t count_products(basct::cspan<unsigned> output_bit_table) noexcept {
return std::accumulate(output_bit_table.begin(), output_bit_table.end(), 0ull);
}
} // namespace sxt::mtxpp2
5 changes: 5 additions & 0 deletions sxt/multiexp/pippenger2/variable_length_computation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ void compute_product_length_table(basct::span<unsigned>& product_lengths,
basct::cspan<unsigned> bit_widths,
basct::cspan<unsigned> output_lengths, unsigned first,
unsigned length) noexcept;

//--------------------------------------------------------------------------------------------------
// count_products
//--------------------------------------------------------------------------------------------------
size_t count_products(basct::cspan<unsigned> output_bit_table) noexcept;
} // namespace sxt::mtxpp2
4 changes: 2 additions & 2 deletions sxt/multiexp/pippenger2/variable_length_multiexponentiation.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ multiexponentiate_impl(basct::span<T> res, const partition_table_accessor<U>& ac
basct::cspan<unsigned> output_lengths, basct::cspan<uint8_t> scalars,
const multiexponentiate_options& options) noexcept {
auto num_outputs = res.size();
auto num_products = std::accumulate(output_bit_table.begin(), output_bit_table.end(), 0u);
auto num_products = count_products(output_bit_table);
auto num_output_bytes = basn::divide_up<size_t>(num_products, 8);
if (num_outputs == 0) {
co_return;
Expand Down Expand Up @@ -224,7 +224,7 @@ void multiexponentiate(basct::span<T> res, const partition_table_accessor<U>& ac
basct::cspan<unsigned> output_lengths,
basct::cspan<uint8_t> scalars) noexcept {
auto num_outputs = res.size();
auto num_products = std::accumulate(output_bit_table.begin(), output_bit_table.end(), 0u);
auto num_products = count_products(output_bit_table);
auto num_output_bytes = basn::divide_up<size_t>(num_products, 8);
if (num_outputs == 0) {
return;
Expand Down

0 comments on commit 0692361

Please sign in to comment.