-
Notifications
You must be signed in to change notification settings - Fork 294
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
refactor(bb): use std::span in pippenger for scalars #8269
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a4d8d8d
use spans in pippenger for scalars
ludamad f31de4d
partial revert
ludamad b7a9ddd
revert
ludamad 56fec15
Update main.cpp
ludamad 5db113d
Merge github.com:AztecProtocol/aztec-packages into ad/use-spans-pippe…
ludamad a9b9344
add size comment
ludamad e72db15
Merge remote-tracking branch 'origin/ad/use-spans-pippenger' into ad/…
ludamad 7b5d95e
revert
ludamad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,7 +199,7 @@ template <typename Curve> | |
void compute_wnaf_states(uint64_t* point_schedule, | ||
bool* input_skew_table, | ||
uint64_t* round_counts, | ||
const typename Curve::ScalarField* scalars, | ||
const std::span<const typename Curve::ScalarField> scalars, | ||
const size_t num_initial_points) | ||
{ | ||
using Fr = typename Curve::ScalarField; | ||
|
@@ -857,21 +857,26 @@ typename Curve::Element evaluate_pippenger_rounds(pippenger_runtime_state<Curve> | |
|
||
template <typename Curve> | ||
typename Curve::Element pippenger_internal(typename Curve::AffineElement* points, | ||
typename Curve::ScalarField* scalars, | ||
std::span<const typename Curve::ScalarField> scalars, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<Curve>& state, | ||
bool handle_edge_cases) | ||
{ | ||
size_t num_initial_points_power_2 = 1 << numeric::get_msb(num_initial_points); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a sente commenting these three lines There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These shouldn't be here actually right now, will remove |
||
if (num_initial_points_power_2 != num_initial_points) { | ||
num_initial_points_power_2 *= 2; // Round up | ||
} | ||
// multiplication_runtime_state state; | ||
compute_wnaf_states<Curve>(state.point_schedule, state.skew_table, state.round_counts, scalars, num_initial_points); | ||
organize_buckets(state.point_schedule, num_initial_points * 2); | ||
compute_wnaf_states<Curve>( | ||
state.point_schedule, state.skew_table, state.round_counts, scalars, num_initial_points_power_2); | ||
organize_buckets(state.point_schedule, num_initial_points_power_2 * 2); | ||
typename Curve::Element result = | ||
evaluate_pippenger_rounds<Curve>(state, points, num_initial_points * 2, handle_edge_cases); | ||
evaluate_pippenger_rounds<Curve>(state, points, num_initial_points_power_2 * 2, handle_edge_cases); | ||
return result; | ||
} | ||
|
||
template <typename Curve> | ||
typename Curve::Element pippenger(typename Curve::ScalarField* scalars, | ||
typename Curve::Element pippenger(std::span<const typename Curve::ScalarField> scalars, | ||
typename Curve::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<Curve>& state, | ||
|
@@ -910,10 +915,9 @@ typename Curve::Element pippenger(typename Curve::ScalarField* scalars, | |
const auto num_slice_points = static_cast<size_t>(1ULL << slice_bits); | ||
|
||
Element result = pippenger_internal(points, scalars, num_slice_points, state, handle_edge_cases); | ||
|
||
if (num_slice_points != num_initial_points) { | ||
const uint64_t leftover_points = num_initial_points - num_slice_points; | ||
return result + pippenger(scalars + num_slice_points, | ||
return result + pippenger(scalars.subspan(num_slice_points), | ||
points + static_cast<size_t>(num_slice_points * 2), | ||
static_cast<size_t>(leftover_points), | ||
state, | ||
|
@@ -938,7 +942,7 @@ typename Curve::Element pippenger(typename Curve::ScalarField* scalars, | |
* | ||
**/ | ||
template <typename Curve> | ||
typename Curve::Element pippenger_unsafe(typename Curve::ScalarField* scalars, | ||
typename Curve::Element pippenger_unsafe(std::span<const typename Curve::ScalarField> scalars, | ||
typename Curve::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<Curve>& state) | ||
|
@@ -947,10 +951,11 @@ typename Curve::Element pippenger_unsafe(typename Curve::ScalarField* scalars, | |
} | ||
|
||
template <typename Curve> | ||
typename Curve::Element pippenger_without_endomorphism_basis_points(typename Curve::ScalarField* scalars, | ||
typename Curve::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<Curve>& state) | ||
typename Curve::Element pippenger_without_endomorphism_basis_points( | ||
std::span<const typename Curve::ScalarField> scalars, | ||
typename Curve::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<Curve>& state) | ||
{ | ||
std::vector<typename Curve::AffineElement> G_mod(num_initial_points * 2); | ||
bb::scalar_multiplication::generate_pippenger_point_table<Curve>(points, &G_mod[0], num_initial_points); | ||
|
@@ -978,7 +983,7 @@ template void evaluate_addition_chains<curve::BN254>(affine_product_runtime_stat | |
const size_t max_bucket_bits, | ||
bool handle_edge_cases); | ||
template curve::BN254::Element pippenger_internal<curve::BN254>(curve::BN254::AffineElement* points, | ||
curve::BN254::ScalarField* scalars, | ||
std::span<const curve::BN254::ScalarField> scalars, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::BN254>& state, | ||
bool handle_edge_cases); | ||
|
@@ -992,19 +997,19 @@ template curve::BN254::AffineElement* reduce_buckets<curve::BN254>(affine_produc | |
bool first_round = true, | ||
bool handle_edge_cases = false); | ||
|
||
template curve::BN254::Element pippenger<curve::BN254>(curve::BN254::ScalarField* scalars, | ||
template curve::BN254::Element pippenger<curve::BN254>(std::span<const curve::BN254::ScalarField> scalars, | ||
curve::BN254::AffineElement* points, | ||
const size_t num_points, | ||
pippenger_runtime_state<curve::BN254>& state, | ||
bool handle_edge_cases = true); | ||
|
||
template curve::BN254::Element pippenger_unsafe<curve::BN254>(curve::BN254::ScalarField* scalars, | ||
template curve::BN254::Element pippenger_unsafe<curve::BN254>(std::span<const curve::BN254::ScalarField> scalars, | ||
curve::BN254::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::BN254>& state); | ||
|
||
template curve::BN254::Element pippenger_without_endomorphism_basis_points<curve::BN254>( | ||
curve::BN254::ScalarField* scalars, | ||
std::span<const curve::BN254::ScalarField> scalars, | ||
curve::BN254::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::BN254>& state); | ||
|
@@ -1028,11 +1033,12 @@ template void add_affine_points_with_edge_cases<curve::Grumpkin>(curve::Grumpkin | |
template void evaluate_addition_chains<curve::Grumpkin>(affine_product_runtime_state<curve::Grumpkin>& state, | ||
const size_t max_bucket_bits, | ||
bool handle_edge_cases); | ||
template curve::Grumpkin::Element pippenger_internal<curve::Grumpkin>(curve::Grumpkin::AffineElement* points, | ||
curve::Grumpkin::ScalarField* scalars, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::Grumpkin>& state, | ||
bool handle_edge_cases); | ||
template curve::Grumpkin::Element pippenger_internal<curve::Grumpkin>( | ||
curve::Grumpkin::AffineElement* points, | ||
std::span<const curve::Grumpkin::ScalarField> scalars, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::Grumpkin>& state, | ||
bool handle_edge_cases); | ||
|
||
template curve::Grumpkin::Element evaluate_pippenger_rounds<curve::Grumpkin>( | ||
pippenger_runtime_state<curve::Grumpkin>& state, | ||
|
@@ -1043,19 +1049,20 @@ template curve::Grumpkin::Element evaluate_pippenger_rounds<curve::Grumpkin>( | |
template curve::Grumpkin::AffineElement* reduce_buckets<curve::Grumpkin>( | ||
affine_product_runtime_state<curve::Grumpkin>& state, bool first_round = true, bool handle_edge_cases = false); | ||
|
||
template curve::Grumpkin::Element pippenger<curve::Grumpkin>(curve::Grumpkin::ScalarField* scalars, | ||
template curve::Grumpkin::Element pippenger<curve::Grumpkin>(std::span<const curve::Grumpkin::ScalarField> scalars, | ||
curve::Grumpkin::AffineElement* points, | ||
const size_t num_points, | ||
pippenger_runtime_state<curve::Grumpkin>& state, | ||
bool handle_edge_cases = true); | ||
|
||
template curve::Grumpkin::Element pippenger_unsafe<curve::Grumpkin>(curve::Grumpkin::ScalarField* scalars, | ||
curve::Grumpkin::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::Grumpkin>& state); | ||
template curve::Grumpkin::Element pippenger_unsafe<curve::Grumpkin>( | ||
std::span<const curve::Grumpkin::ScalarField> scalars, | ||
curve::Grumpkin::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::Grumpkin>& state); | ||
|
||
template curve::Grumpkin::Element pippenger_without_endomorphism_basis_points<curve::Grumpkin>( | ||
curve::Grumpkin::ScalarField* scalars, | ||
std::span<const curve::Grumpkin::ScalarField> scalars, | ||
curve::Grumpkin::AffineElement* points, | ||
const size_t num_initial_points, | ||
pippenger_runtime_state<curve::Grumpkin>& state); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this syntax construct a span from the localation of scalars[0] up to NUM_POINTS? I assume so. It'd be good if you could document this in whatever place you see best
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented