prio/
benchmarked.rs

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
8use crate::field::NttFriendlyFieldElement;
9use crate::flp::gadgets::Mul;
10use crate::flp::FlpError;
11use crate::ntt::ntt;
12use crate::polynomial::{ntt_get_roots, poly_ntt, PolyNttTempMemory};
13
14/// Runs NTT on `outp` using the iterative algorithm.
15pub fn benchmarked_iterative_ntt<F: NttFriendlyFieldElement>(outp: &mut [F], inp: &[F]) {
16    ntt(outp, inp, inp.len()).unwrap();
17}
18
19/// Runs NTT on `outp` using the recursive algorithm.
20pub fn benchmarked_recursive_ntt<F: NttFriendlyFieldElement>(outp: &mut [F], inp: &[F]) {
21    let roots_2n = ntt_get_roots(inp.len(), false);
22    let mut ntt_memory = PolyNttTempMemory::new(inp.len());
23    poly_ntt(outp, inp, &roots_2n, inp.len(), false, &mut ntt_memory)
24}
25
26/// Sets `outp` to `inp[0] * inp[1]`, where `inp[0]` and `inp[1]` are polynomials. This function
27/// uses NTT for multiplication.
28pub fn benchmarked_gadget_mul_call_poly_ntt<F: NttFriendlyFieldElement>(
29    g: &mut Mul<F>,
30    outp: &mut [F],
31    inp: &[Vec<F>],
32) -> Result<(), FlpError> {
33    g.call_poly_ntt(outp, inp)
34}
35
36/// Sets `outp` to `inp[0] * inp[1]`, where `inp[0]` and `inp[1]` are polynomials. This function
37/// does the multiplication directly.
38pub fn benchmarked_gadget_mul_call_poly_direct<F: NttFriendlyFieldElement>(
39    g: &mut Mul<F>,
40    outp: &mut [F],
41    inp: &[Vec<F>],
42) -> Result<(), FlpError> {
43    g.call_poly_direct(outp, inp)
44}