Skip to content

Commit b926f92

Browse files
committed
final checkpoint before merging back to other branch
1 parent 48bf0f4 commit b926f92

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

ff/src/fields/models/fp/montgomery_backend.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,23 +1080,16 @@ fn bigint_mul_by_u64<const N: usize>(val: &[u64; N], other: u64) -> (u64, [u64;
10801080
let mut carry: u64; // Start with carry = 0
10811081

10821082
// Calculate the full 128-bit product of the lowest limb
1083-
let prod128_0: u128 = (val[0] as u128) * (other as u128);
1084-
let result_lo = prod128_0 as u64; // Lowest limb of the result
1085-
carry = (prod128_0 >> 64) as u64; // Carry into the high part
1083+
let prod_lo: u128 = (val[0] as u128) * (other as u128);
1084+
let result_lo = prod_lo as u64; // Lowest limb of the result
1085+
carry = (prod_lo >> 64) as u64; // Carry into the high part
10861086

10871087
// Iterate through the remaining limbs of the input BigInt
10881088
for i in 1..N {
10891089
// Calculate the full 128-bit product of the current limb and the u64 multiplier
1090-
let prod128: u128 = (val[i] as u128) * (other as u128);
1091-
1092-
// Add the carry from the previous limb's computation
1093-
let sum128: u128 = prod128 + (carry as u128);
1094-
1095-
// The lower 64 bits of the sum become the current result limb (in the high part)
1096-
result_hi[i - 1] = sum128 as u64; // Store in result_hi[0] to result_hi[N-2]
1097-
1098-
// The upper 64 bits of the sum become the carry for the next limb
1099-
carry = (sum128 >> 64) as u64;
1090+
let prod_hi: u128 = (val[i] as u128) * (other as u128) + (carry as u128);
1091+
result_hi[i - 1] = prod_hi as u64; // Store in result_hi[0] to result_hi[N-2]
1092+
carry = (prod_hi >> 64) as u64;
11001093
}
11011094

11021095
// After the loop, the final carry is the highest limb (N-th limb of the high part)
@@ -1253,7 +1246,7 @@ fn get_n_limbs_from_n_plus_one<const N: usize>(val: (u64, [u64; N])) -> BigInt<N
12531246
/// Performs up to 2 conditional subtractions, instead of 1 in the optimized version.
12541247
/// (though benchmarks show that there is essentially no difference in performance)
12551248
#[inline(always)]
1256-
fn barrett_cond_subtract<T: MontConfig<N>, const N: usize>(r_tmp: (u64, [u64; N])) -> [u64; N] {
1249+
fn _barrett_cond_subtract<T: MontConfig<N>, const N: usize>(r_tmp: (u64, [u64; N])) -> [u64; N] {
12571250
// Final conditional subtractions (optimized based on spare bits)
12581251
let final_limbs: [u64; N];
12591252

@@ -1331,7 +1324,7 @@ fn barrett_cond_subtract<T: MontConfig<N>, const N: usize>(r_tmp: (u64, [u64; N]
13311324
/// Takes an N+1 limb intermediate result `r_tmp` and returns the N-limb final result.
13321325
#[unroll_for_loops(4)]
13331326
#[inline(always)]
1334-
fn _barrett_cond_subtract_prime<T: MontConfig<N>, const N: usize>(r_tmp: (u64, [u64; N])) -> [u64; N] {
1327+
fn barrett_cond_subtract_prime<T: MontConfig<N>, const N: usize>(r_tmp: (u64, [u64; N])) -> [u64; N] {
13351328
let final_limbs: [u64; N];
13361329
let r_n = get_n_limbs_from_n_plus_one::<N>(r_tmp);
13371330

@@ -1439,7 +1432,7 @@ fn barrett_reduce_nplus1_to_n<T: MontConfig<N>, const N: usize>(c: (u64, [u64; N
14391432
let (r_tmp, _) = sub_bigint_plus_one(c, m_times_2p); // r_tmp = (r_tmp_lo, r_tmp_hi)
14401433

14411434
// Use the optimized conditional subtraction
1442-
barrett_cond_subtract::<T, N>(r_tmp)
1435+
barrett_cond_subtract_prime::<T, N>(r_tmp)
14431436
}
14441437

14451438
#[cfg(test)]

test-curves/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ harness = false
8383
name = "small_mul"
8484
path = "benches/small_mul.rs"
8585
harness = false
86-
required-features = ["bn254"]
8786

8887
[[bench]]
8988
name = "bn254"

test-curves/benches/small_mul.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ark_ff::UniformRand;
22
use ark_std::rand::{rngs::StdRng, Rng, SeedableRng};
3-
use ark_test_curves::secp256k1::{Fr, FqConfig, FrConfig};
3+
use ark_test_curves::secp256k1::{Fr, FrConfig};
44
use criterion::{criterion_group, criterion_main, Criterion};
55
use ark_ff::BigInteger;
66
use ark_ff::BigInt;

0 commit comments

Comments
 (0)