-
Notifications
You must be signed in to change notification settings - Fork 31
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
fp: Unifying implementations of prime fields that fit in a single word. #1099
Conversation
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.
It uses a macro since the implementation with generic types introduced a non-small performance overhead.
Interesting. What benchmarks did you see regress? Did it make Field64 slower, or just Field32?
src/fp/single_word.rs
Outdated
//! where `W` is a specified word size. | ||
|
||
/// impl_field_single_word implements field operations for prime modulus | ||
/// that fits in one word of `W` bits. |
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.
Is this true if W
is u128
? The mul()
looks to be tailored for u64
(and maybe u32
).
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.
The u128
case is different because it needs multiprecision formulas, as we don't have a widening multiplication primitive from u128 to 256-bit integers. Thus, we need to say something about the $W2 type in order for the conditions to be necessary and sufficient.
/// that fits in one word of `W` bits. | |
/// that fits in one word of `W` bits. It requires a multiplication operation on unsigned integers | |
/// with `2*W` bits. |
src/fp/single_word.rs
Outdated
} | ||
} | ||
|
||
#[cfg(test)] |
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.
Instead of making this code match the API of the tests, I'd suggest making the tests generic in the word size.
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.
I have updated the code and tests to rely on a generic implementation.
74ee996
to
4cfebf2
Compare
Hi folks, this is ready for another round of reviews. |
This is a refactor of the FieldParameters struct to use generic datatypes providing implementations for primes that fit in one primitive word. Tests script and documentation parameters were updated to support the new structure. Performance for FieldPrio2 operation is twice faster.
9fd8536
to
7468ad1
Compare
I have included the latest review comments and squashed all commits. |
Thanks! |
It adds a new generic structure that implements field operations specialized for prime moduli that fit in a single word. Implementation is generic for basic datatypes.
Field32 is now 1.8x faster. No performance changes for Field64 and Field128.
Field32