reed_solomon_simd/engine/
engine_default.rsuse crate::engine::{Engine, GfElement, NoSimd, ShardsRefMut, GF_ORDER};
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use crate::engine::{Avx2, Ssse3};
#[cfg(target_arch = "aarch64")]
use crate::engine::Neon;
pub struct DefaultEngine(Box<dyn Engine + Send + Sync>);
impl DefaultEngine {
pub fn new() -> Self {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
if is_x86_feature_detected!("avx2") {
return Self(Box::new(Avx2::new()));
}
if is_x86_feature_detected!("ssse3") {
return Self(Box::new(Ssse3::new()));
}
}
#[cfg(target_arch = "aarch64")]
{
if std::arch::is_aarch64_feature_detected!("neon") {
return Self(Box::new(Neon::new()));
}
}
Self(Box::new(NoSimd::new()))
}
}
impl Default for DefaultEngine {
fn default() -> Self {
Self::new()
}
}
impl Engine for DefaultEngine {
fn fft(
&self,
data: &mut ShardsRefMut,
pos: usize,
size: usize,
truncated_size: usize,
skew_delta: usize,
) {
self.0.fft(data, pos, size, truncated_size, skew_delta);
}
fn ifft(
&self,
data: &mut ShardsRefMut,
pos: usize,
size: usize,
truncated_size: usize,
skew_delta: usize,
) {
self.0.ifft(data, pos, size, truncated_size, skew_delta);
}
fn mul(&self, x: &mut [[u8; 64]], log_m: GfElement) {
self.0.mul(x, log_m);
}
fn eval_poly(erasures: &mut [GfElement; GF_ORDER], truncated_size: usize) {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
if is_x86_feature_detected!("avx2") {
return Avx2::eval_poly(erasures, truncated_size);
}
if is_x86_feature_detected!("ssse3") {
return Ssse3::eval_poly(erasures, truncated_size);
}
}
#[cfg(target_arch = "aarch64")]
{
if std::arch::is_aarch64_feature_detected!("neon") {
return Neon::eval_poly(erasures, truncated_size);
}
}
NoSimd::eval_poly(erasures, truncated_size);
}
}