| 1 |
// SPDX-License-Identifier: MPL-2.0 |
| 2 |
|
| 3 |
#![doc(hidden)] |
| 4 |
|
| 5 |
//! This module provides wrappers around internal components of this crate that we want to |
| 6 |
//! benchmark, but which we don't want to expose in the public API. |
| 7 |
|
| 8 |
use crate::fft::discrete_fourier_transform; |
| 9 |
use crate::field::FftFriendlyFieldElement; |
| 10 |
use crate::flp::gadgets::Mul; |
| 11 |
use crate::flp::FlpError; |
| 12 |
use crate::polynomial::{poly_fft, PolyAuxMemory}; |
| 13 |
|
| 14 |
/// Sets `outp` to the Discrete Fourier Transform (DFT) using an iterative FFT algorithm. |
| 15 |
pub fn benchmarked_iterative_fft<F: FftFriendlyFieldElement>(outp: &mut [F], inp: &[F]) { |
| 16 |
discrete_fourier_transform(outp, inp, inp.len()).unwrap(); |
| 17 |
} |
| 18 |
|
| 19 |
/// Sets `outp` to the Discrete Fourier Transform (DFT) using a recursive FFT algorithm. |
| 20 |
pub fn benchmarked_recursive_fft<F: FftFriendlyFieldElement>(outp: &mut [F], inp: &[F]) { |
| 21 |
let mut mem = PolyAuxMemory::new(inp.len() / 2); |
| 22 |
poly_fft( |
| 23 |
outp, |
| 24 |
inp, |
| 25 |
&mem.roots_2n, |
| 26 |
inp.len(), |
| 27 |
false, |
| 28 |
&mut mem.fft_memory, |
| 29 |
) |
| 30 |
} |
| 31 |
|
| 32 |
/// Sets `outp` to `inp[0] * inp[1]`, where `inp[0]` and `inp[1]` are polynomials. This function |
| 33 |
/// uses FFT for multiplication. |
| 34 |
pub fn benchmarked_gadget_mul_call_poly_fft<F: FftFriendlyFieldElement>( |
| 35 |
g: &mut Mul<F>, |
| 36 |
outp: &mut [F], |
| 37 |
inp: &[Vec<F>], |
| 38 |
) -> Result<(), FlpError> { |
| 39 |
g.call_poly_fft(outp, inp) |
| 40 |
} |
| 41 |
|
| 42 |
/// Sets `outp` to `inp[0] * inp[1]`, where `inp[0]` and `inp[1]` are polynomials. This function |
| 43 |
/// does the multiplication directly. |
| 44 |
pub fn benchmarked_gadget_mul_call_poly_direct<F: FftFriendlyFieldElement>( |
| 45 |
g: &mut Mul<F>, |
| 46 |
outp: &mut [F], |
| 47 |
inp: &[Vec<F>], |
| 48 |
) -> Result<(), FlpError> { |
| 49 |
g.call_poly_direct(outp, inp) |
| 50 |
} |