This commit is contained in:
Jean-Philippe Bossuat
2025-04-25 15:24:09 +02:00
parent 90b34e171d
commit 2a96f89047
16 changed files with 864 additions and 895 deletions

View File

@@ -1,5 +1,6 @@
use crate::GALOISGENERATOR;
use crate::ffi::module::{MODULE, delete_module_info, module_info_t, new_module_info};
use std::marker::PhantomData;
#[derive(Copy, Clone)]
#[repr(u8)]
@@ -8,37 +9,50 @@ pub enum BACKEND {
NTT120,
}
pub struct Module {
pub ptr: *mut MODULE,
pub n: usize,
pub backend: BACKEND,
pub trait Backend {
const KIND: BACKEND;
fn module_type() -> u32;
}
impl Module {
pub struct FFT64;
pub struct NTT120;
impl Backend for FFT64 {
const KIND: BACKEND = BACKEND::FFT64;
fn module_type() -> u32 {
0
}
}
impl Backend for NTT120 {
const KIND: BACKEND = BACKEND::NTT120;
fn module_type() -> u32 {
1
}
}
pub struct Module<B: Backend> {
pub ptr: *mut MODULE,
pub n: usize,
_marker: PhantomData<B>,
}
impl<B: Backend> Module<B> {
// Instantiates a new module.
pub fn new(n: usize, module_type: BACKEND) -> Self {
pub fn new(n: usize) -> Self {
unsafe {
let module_type_u32: u32;
match module_type {
BACKEND::FFT64 => module_type_u32 = 0,
BACKEND::NTT120 => module_type_u32 = 1,
}
let m: *mut module_info_t = new_module_info(n as u64, module_type_u32);
let m: *mut module_info_t = new_module_info(n as u64, B::module_type());
if m.is_null() {
panic!("Failed to create module.");
}
Self {
ptr: m,
n: n,
backend: module_type,
_marker: PhantomData,
}
}
}
pub fn backend(&self) -> BACKEND {
self.backend
}
pub fn n(&self) -> usize {
self.n
}