use crate::alphabet::Alphabet;
mod avx2;
mod avx512;
mod dispatch;
pub(crate) use dispatch::Path;
#[cfg(feature = "internals")]
pub use dispatch::{available, force, force_stream_floor, AVX2, PORTABLE, UNKNOWN, WIDE};
#[cfg(not(miri))]
const STREAM_CANDIDATE: usize = 1 << 16;
#[cfg(miri)]
const STREAM_CANDIDATE: usize = 1 << 10;
pub(crate) fn encode_bulk<A: Alphabet>(input: &[u8], out: &mut [u8], groups: usize) -> usize {
match dispatch::path() {
Path::Wide => unsafe { avx512::encode_bulk::<A>(input, out, groups) },
Path::Avx2 => {
let is_streaming = input.len() >= STREAM_CANDIDATE
&& input.len() >= dispatch::stream_floor()
&& out.as_ptr().align_offset(16) == 0;
unsafe {
if is_streaming {
avx2::encode_bulk::<A, true>(input, out, groups)
} else {
avx2::encode_bulk::<A, false>(input, out, groups)
}
}
}
Path::Portable => 0,
}
}
pub(crate) fn decode_bulk<A: Alphabet>(input: &[u8], out: &mut [u8], quads: usize) -> usize {
match dispatch::path() {
Path::Wide => unsafe { avx512::decode_bulk::<A>(input, out, quads) },
Path::Avx2 => unsafe { avx2::decode_bulk::<A>(input, out, quads) },
Path::Portable => 0,
}
}