Skip to content

Commit db1878a

Browse files
committed
instantiate only for desired limbs
1 parent 295dc5f commit db1878a

File tree

2 files changed

+28
-47
lines changed

2 files changed

+28
-47
lines changed

ff/src/fields/models/fp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use crate::{
1515
};
1616
use ark_serialize::*;
1717

18-
invoke_16!(impl_field_square_in_place);
19-
invoke_16!(impl_field_mul_assign);
18+
invoke_n!(impl_field_square_in_place);
19+
invoke_n!(impl_field_mul_assign);
2020

21-
pub trait FpParams<const N: usize>: FpParameters<N, BigInt = BigInt<N>> {
21+
pub trait FpParams<const N: usize>: FpParameters<BigInt = BigInt<N>> {
2222
// Checking the modulus at compile time
2323
const NO_CARRY: bool = {
2424
let first_bit_set = Self::MODULUS.0[N - 1] >> 63 != 0;
@@ -87,7 +87,7 @@ impl<P, const N: usize> Fp<P, N> {
8787
modulus: BigInt<N>,
8888
inv: u64,
8989
) -> Self {
90-
let mut repr = P::BigInt([0; N]);
90+
let mut repr = BigInt::<N>([0; N]);
9191
let mut i = 0;
9292
while i < limbs.len() {
9393
repr.0[i] = limbs[i];

ff/src/fields/models/mod.rs

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,32 @@
1-
#[macro_export]
2-
macro_rules! match_const {
3-
($fn_name:ident, $N:expr $(, $args:tt)*) => {
4-
paste::paste! {
5-
match $N {
6-
1 => [<$fn_name _ id1>]($($args),*),
7-
2 => [<$fn_name _ id2>]($($args),*),
8-
3 => [<$fn_name _ id3>]($($args),*),
9-
4 => [<$fn_name _ id4>]($($args),*),
10-
5 => [<$fn_name _ id5>]($($args),*),
11-
6 => [<$fn_name _ id6>]($($args),*),
12-
7 => [<$fn_name _ id7>]($($args),*),
13-
8 => [<$fn_name _ id8>]($($args),*),
14-
9 => [<$fn_name _ id9>]($($args),*),
15-
10 => [<$fn_name _ id10>]($($args),*),
16-
11 => [<$fn_name _ id11>]($($args),*),
17-
12 => [<$fn_name _ id12>]($($args),*),
18-
13 => [<$fn_name _ id13>]($($args),*),
19-
14 => [<$fn_name _ id14>]($($args),*),
20-
15 => [<$fn_name _ id15>]($($args),*),
21-
16 => [<$fn_name _ id16>]($($args),*),
22-
_ => unreachable!(),
1+
macro_rules! limb_instantiation {
2+
($($ns:expr),*) => {
3+
macro_rules! make_nested_macro {
4+
($d:tt) => {
5+
macro_rules! match_const {
6+
($fn_name:ident, $N:expr $d(, $d args:tt)*) => {
7+
paste::paste! {
8+
match $N {
9+
$($ns => [<$fn_name _ id$ns>]::<P, N>($d($d args),*),)*
10+
_ => unreachable!(),
11+
};
12+
}
13+
};
14+
}
2315
};
2416
}
25-
};
26-
}
2717

28-
macro_rules! invoke_16 {
29-
($macro_name:ident) => {
30-
$macro_name!(1);
31-
$macro_name!(2);
32-
$macro_name!(3);
33-
$macro_name!(4);
34-
$macro_name!(5);
35-
$macro_name!(6);
36-
$macro_name!(7);
37-
$macro_name!(8);
38-
$macro_name!(9);
39-
$macro_name!(10);
40-
$macro_name!(11);
41-
$macro_name!(12);
42-
$macro_name!(13);
43-
$macro_name!(14);
44-
$macro_name!(15);
45-
$macro_name!(16);
46-
};
18+
make_nested_macro!($);
19+
20+
macro_rules! invoke_n {
21+
($macro_name:ident) => {
22+
$($macro_name!($ns);)*
23+
};
24+
}
25+
}
4726
}
4827

28+
limb_instantiation!(1, 4, 5, 6, 12, 13);
29+
4930
pub mod fp;
5031
pub use self::fp::*;
5132

0 commit comments

Comments
 (0)