-
Notifications
You must be signed in to change notification settings - Fork 9
SIMD packing for tweak hash tree #21
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
Changes from 4 commits
3585dad
c6c16fc
3cc78ea
c9e234f
c1dfc58
6a182fd
026bf3b
6faeaff
d062347
83a8a3c
755292b
99cbaf5
9571be3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| use rand::Rng; | ||
|
|
||
| use rayon::prelude::*; | ||
|
|
||
| use crate::serialization::Serializable; | ||
| use crate::symmetric::prf::Pseudorandom; | ||
|
|
||
|
|
@@ -46,6 +48,30 @@ pub trait TweakableHash { | |
| message: &[Self::Domain], | ||
| ) -> Self::Domain; | ||
|
|
||
| /// Applies the calculation for a single tweak hash tree layer. | ||
| fn compute_tree_layer( | ||
| parameter: &Self::Parameter, | ||
| level: u8, | ||
| parent_start: usize, | ||
| children: &[Self::Domain], | ||
| ) -> Vec<Self::Domain> { | ||
| // default implementation is scalar. tweak_tree/poseidon.rs provides a SIMD variant | ||
| children | ||
| .par_chunks_exact(2) | ||
| .enumerate() | ||
| .map(|(i, children)| { | ||
| // Parent index in this layer | ||
| let parent_pos = (parent_start + i) as u32; | ||
| // Hash children into their parent using the tweak | ||
| Self::apply( | ||
| parameter, | ||
| &Self::tree_tweak(level + 1, parent_pos), | ||
|
||
| children, | ||
| ) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| /// Computes bottom tree leaves by walking hash chains for multiple epochs. | ||
| /// | ||
| /// This method has a default scalar implementation that processes epochs in parallel. | ||
|
|
||
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.
Here I think that with clippy you can remove the always, should not make big difference (at least from my personal experiments locally because I've just tried to remove it.