use super::*;
pub(super) enum RecoveryBufferSet {
Normal(Vec<Vec<u16>>),
#[cfg_attr(not(target_arch = "x86_64"), allow(dead_code))]
Altmap(Vec<Vec<u8>>),
#[cfg_attr(not(target_arch = "x86_64"), allow(dead_code))]
Shuffle2x(Vec<Vec<u8>>),
#[cfg_attr(not(target_arch = "x86_64"), allow(dead_code))]
Affine2x(Vec<Vec<u8>>),
#[cfg_attr(not(target_arch = "x86_64"), allow(dead_code))]
Affine(Vec<Vec<u8>>),
#[cfg_attr(not(target_arch = "x86_64"), allow(dead_code))]
Affine512(Affine512Acc),
}
#[cfg_attr(not(target_arch = "x86_64"), allow(dead_code))]
pub(super) struct Affine512Acc {
pub(super) data: Vec<u8>,
pub(super) n_rec: usize,
pub(super) slice_len: usize,
}
impl RecoveryBufferSet {
pub(super) fn as_normal_mut(&mut self) -> &mut Vec<Vec<u16>> {
match self {
Self::Normal(b) => b,
Self::Altmap(_)
| Self::Shuffle2x(_)
| Self::Affine2x(_)
| Self::Affine(_)
| Self::Affine512(_) => panic!("expected Normal recovery buffers"),
}
}
#[allow(dead_code)]
pub(super) fn len(&self) -> usize {
match self {
Self::Normal(b) => b.len(),
Self::Altmap(b) | Self::Shuffle2x(b) | Self::Affine2x(b) | Self::Affine(b) => b.len(),
Self::Affine512(a) => a.n_rec,
}
}
}
pub(super) fn try_zeroed_buffers<T: Clone>(
fill: T,
len: usize,
count: usize,
) -> Result<Vec<Vec<T>>, TryReserveError> {
let mut out: Vec<Vec<T>> = Vec::new();
out.try_reserve_exact(count)?;
for _ in 0..count {
let mut buf: Vec<T> = Vec::new();
buf.try_reserve_exact(len)?;
buf.resize(len, fill.clone());
out.push(buf);
}
Ok(out)
}
pub fn altmap_buffer_size(slice_words: usize) -> usize {
super::altmap::altmap_size(slice_words)
}
pub fn shuffle2x_buffer_size(slice_words: usize) -> usize {
super::shuffle2x::shuffle2x_buffer_size(slice_words)
}
pub fn affine2x_buffer_size(slice_words: usize) -> usize {
super::affine2x::affine2x_buffer_size(slice_words)
}
pub fn affine_buffer_size(slice_words: usize) -> usize {
super::affine::affine_buffer_size(slice_words)
}
pub fn altmap_kernel_available() -> bool {
#[cfg(target_arch = "x86_64")]
{
std::is_x86_feature_detected!("avx2") && !std::is_x86_feature_detected!("gfni")
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
pub fn shuffle2x_kernel_available() -> bool {
#[cfg(target_arch = "x86_64")]
{
std::is_x86_feature_detected!("avx2")
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
pub fn shuffle512_kernel_available() -> bool {
#[cfg(target_arch = "x86_64")]
{
std::is_x86_feature_detected!("avx512f") && std::is_x86_feature_detected!("avx512bw")
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
pub fn affine2x_kernel_available() -> bool {
#[cfg(target_arch = "x86_64")]
{
std::is_x86_feature_detected!("avx2") && std::is_x86_feature_detected!("gfni")
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}
pub fn affine_kernel_available() -> bool {
affine2x_kernel_available()
}
pub fn affine512_kernel_available() -> bool {
#[cfg(target_arch = "x86_64")]
{
std::is_x86_feature_detected!("avx512f")
&& std::is_x86_feature_detected!("avx512bw")
&& std::is_x86_feature_detected!("gfni")
}
#[cfg(not(target_arch = "x86_64"))]
{
false
}
}