-
Notifications
You must be signed in to change notification settings - Fork 175
Open
Description
While adding QM31 support to starknet-io/types-rs, some concerns were raised on the performance impact of as_representative()
. Original comment: starknet-io/types-rs#163 (comment).
The current implementation uses branching to check if the inner value is equal to MERSENNE_31_PRIME_FIELD_ORDER
lambdaworks/crates/math/src/field/fields/mersenne31/field.rs
Lines 30 to 35 in ad2a380
fn as_representative(n: &u32) -> u32 { | |
if *n == MERSENNE_31_PRIME_FIELD_ORDER { | |
0 | |
} else { | |
*n | |
} |
Would changing the implementation to be branchless improve performance? Using either:
- Modulo:
n % MERSENNE_31_PRIME_FIELD_ORDER
. - Mask:
n & (1u32 << 31) - 1
.
Metadata
Metadata
Assignees
Labels
No labels