mod elementwise;
mod gather;
mod matrix;
mod rows;
mod scatter;
mod single;
pub use elementwise::{mul_elementwise_assign_gfni, mul_elementwise_gfni};
pub use gather::mul_add_gather_gfni;
pub use matrix::{
mul_add_matrix_at_gfni_with, mul_add_matrix_gfni_with, mul_into_matrix_gfni_with,
};
#[cfg(test)]
pub(crate) use rows::MATRIX_PREFETCH_MIN;
pub use scatter::mul_add_scatter_gfni;
pub use single::{mul_add_gfni, mul_assign_gfni, mul_into_gfni};
#[cfg(feature = "simd512")]
pub(super) use single::{mul_add_gfni_impl, mul_assign_gfni_impl, mul_into_gfni_impl};
use super::PeelBody;
use crate::kernel::gf8::Prepared;
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
#[inline]
#[archmage::rite(v3_gfni_crypto)]
pub(super) fn bfactor_gfni<const NATIVE: bool>(coeff: Prepared) -> __m256i {
if NATIVE {
_mm256_set1_epi8(coeff.byte().cast_signed())
} else {
_mm256_set1_epi64x(coeff.affine.cast_signed())
}
}
#[inline]
#[archmage::rite(v3_gfni_crypto)]
pub(super) fn bfactor_half_gfni<const NATIVE: bool>(coeff: Prepared) -> __m128i {
if NATIVE {
_mm_set1_epi8(coeff.byte().cast_signed())
} else {
_mm_set1_epi64x(coeff.affine.cast_signed())
}
}
#[inline]
#[archmage::rite(v3_gfni_crypto)]
pub(super) fn bmul_gfni<const NATIVE: bool>(x: __m256i, factor: __m256i) -> __m256i {
if NATIVE {
_mm256_gf2p8mul_epi8(x, factor)
} else {
_mm256_gf2p8affine_epi64_epi8::<0>(x, factor)
}
}
#[inline]
#[archmage::rite(v3_gfni_crypto)]
pub(super) fn bmul_half_gfni<const NATIVE: bool>(x: __m128i, factor: __m128i) -> __m128i {
if NATIVE {
_mm_gf2p8mul_epi8(x, factor)
} else {
_mm_gf2p8affine_epi64_epi8::<0>(x, factor)
}
}
#[archmage::rite(v3_gfni_crypto)]
pub(super) fn brem_gfni<const NATIVE: bool>(dst: &mut [u8], coeff: Prepared, src: &[u8]) {
single::mul_add_gfni_impl::<NATIVE, PeelBody>(dst, coeff, src);
}
#[inline]
fn factor_word_gfni<const NATIVE: bool>(coeff: Prepared) -> u64 {
if NATIVE {
u64::from(coeff.byte())
} else {
coeff.affine
}
}
#[inline]
#[archmage::rite(v3_gfni_crypto)]
pub(super) fn wfactor_gfni<const NATIVE: bool>(word: u64) -> __m256i {
if NATIVE {
_mm256_set1_epi8(word.to_le_bytes()[0].cast_signed())
} else {
_mm256_set1_epi64x(word.cast_signed())
}
}