Skip to content

Commit 6dca18b

Browse files
committed
faster combine_statement
1 parent a94fbfd commit 6dca18b

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

crates/whir/src/open.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,16 +593,26 @@ where
593593
for (e, &scalar) in smt.values.iter().zip(&next_gamma_powers) {
594594
combined_sum += e.value * scalar;
595595
}
596-
for (out_buff, &(origin_index, _)) in chunks_mut.iter_mut().zip(&indexed_smt_values) {
597-
let out = &mut out_buff[..1 << shift];
598-
let scalar = next_gamma_powers[origin_index];
599-
parallel::par_for_each_mut(out, |i, out_elem| {
600-
*out_elem += inner_poly[i] * scalar;
601-
});
602-
}
596+
let n = 1usize << shift;
597+
let mask = n - 1;
598+
let ptrs: Vec<(parallel::SendPtr<EFPacking<EF>>, EF)> = chunks_mut
599+
.iter_mut()
600+
.zip(&indexed_smt_values)
601+
.map(|(out_buff, &(origin_index, _))| {
602+
(
603+
parallel::SendPtr(out_buff.as_mut_ptr()),
604+
next_gamma_powers[origin_index],
605+
)
606+
})
607+
.collect();
608+
let inner = inner_poly.as_slice();
609+
parallel::for_each_index(ptrs.len() << shift, |flat| {
610+
let (ptr, scalar) = &ptrs[flat >> shift];
611+
let i = flat & mask;
612+
unsafe { *ptr.add(i) += inner[i] * *scalar };
613+
});
603614
gamma_pow = *next_gamma_powers.last().unwrap() * gamma;
604615
}
605616
}
606-
607617
(combined_weights, combined_sum)
608618
}

0 commit comments

Comments
 (0)