Skip to content

Commit 127a131

Browse files
committed
Merge branch 'feat/fewer-reductions' into dev/twist-shout
2 parents a90d709 + ebb26fd commit 127a131

File tree

10 files changed

+2642
-448
lines changed

10 files changed

+2642
-448
lines changed

ff/src/biginteger/arithmetic.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,35 @@ pub fn mac_discard(a: u64, b: u64, c: u64, carry: &mut u64) {
123123
*carry = (tmp >> 64) as u64;
124124
}
125125

126+
/// Accumulate `limbs` into an N-limb accumulator starting at `lane_offset` (64-bit lanes),
127+
/// returning the final carry. This is a helper for building wide accumulators.
128+
#[inline(always)]
129+
pub fn add_limbs_shifted_inplace<const N: usize>(
130+
acc: &mut [u64; N],
131+
limbs: &[u64],
132+
lane_offset: usize,
133+
) -> u64 {
134+
let mut carry = 0u64;
135+
let mut i = 0usize;
136+
while i < limbs.len() {
137+
let idx = lane_offset + i;
138+
if idx >= N { break; }
139+
let tmp = (acc[idx] as u128) + (limbs[i] as u128) + (carry as u128);
140+
acc[idx] = tmp as u64;
141+
carry = (tmp >> 64) as u64;
142+
i += 1;
143+
}
144+
// propagate carry across remaining lanes if any
145+
let mut idx = lane_offset + i;
146+
while carry != 0 && idx < N {
147+
let tmp = (acc[idx] as u128) + (carry as u128);
148+
acc[idx] = tmp as u64;
149+
carry = (tmp >> 64) as u64;
150+
idx += 1;
151+
}
152+
carry
153+
}
154+
126155
macro_rules! mac_with_carry {
127156
($a:expr, $b:expr, $c:expr, &mut $carry:expr$(,)?) => {{
128157
let tmp =

0 commit comments

Comments
 (0)