#![allow(clippy::into_iter_on_ref)]
use crate::vector::{
GenericVector,
streaming::{StreamingVector, StreamingVectorMut},
unaligned::{Unaligned, UnalignedMut},
};
pub trait SimdSlice {
type Element;
fn aligned_simd_iter<V>(&self) -> impl Iterator<Item = &'_ V>
where
V: GenericVector<Element = Self::Element>;
fn try_aligned_simd_iter<V>(&self) -> (&Self, impl Iterator<Item = &'_ V>, &Self)
where
V: GenericVector<Element = Self::Element>;
fn streaming_simd_iter<V>(&self) -> impl Iterator<Item = StreamingVector<'_, V>>
where
V: GenericVector<Element = Self::Element>;
fn unaligned_simd_iter<V>(&self) -> (Unaligned<'_, V>, &Self)
where
V: GenericVector<Element = Self::Element>;
fn aligned_simd_iter_mut<V>(&mut self) -> impl Iterator<Item = &'_ mut V>
where
V: GenericVector<Element = Self::Element>;
fn try_aligned_simd_iter_mut<V>(&mut self) -> (&mut Self, impl Iterator<Item = &'_ mut V>, &mut Self)
where
V: GenericVector<Element = Self::Element>;
fn streaming_simd_iter_mut<V>(&mut self) -> impl Iterator<Item = StreamingVectorMut<'_, V>>
where
V: GenericVector<Element = Self::Element>;
fn unaligned_simd_iter_mut<V>(&mut self) -> (UnalignedMut<'_, V>, &mut Self)
where
V: GenericVector<Element = Self::Element>;
}
#[thermite_macros::inline_always]
impl<T> SimdSlice for [T] {
type Element = T;
fn aligned_simd_iter<V>(&self) -> impl Iterator<Item = &'_ V>
where
V: GenericVector<Element = Self::Element>,
{
let (&[], simd, &[]) = V::align_slice(self) else {
panic!("Slice is not exactly aligned");
};
simd.into_iter()
}
fn try_aligned_simd_iter<V>(&self) -> (&Self, impl Iterator<Item = &'_ V>, &Self)
where
V: GenericVector<Element = Self::Element>,
{
let (head, simd, tail) = V::align_slice(self);
(head, simd.into_iter(), tail)
}
fn streaming_simd_iter<V>(&self) -> impl Iterator<Item = StreamingVector<'_, V>>
where
V: GenericVector<Element = Self::Element>,
{
V::stream_aligned_slice(self)
}
fn unaligned_simd_iter<V>(&self) -> (Unaligned<'_, V>, &Self)
where
V: GenericVector<Element = Self::Element>,
{
V::iter_unaligned(self)
}
fn aligned_simd_iter_mut<V>(&mut self) -> impl Iterator<Item = &'_ mut V>
where
V: GenericVector<Element = Self::Element>,
{
let (&mut [], simd, &mut []) = V::align_slice_mut(self) else {
panic!("Slice is not exactly aligned");
};
simd.into_iter()
}
fn try_aligned_simd_iter_mut<V>(&mut self) -> (&mut Self, impl Iterator<Item = &'_ mut V>, &mut Self)
where
V: GenericVector<Element = Self::Element>,
{
let (head, simd, tail) = V::align_slice_mut(self);
(head, simd.into_iter(), tail)
}
fn streaming_simd_iter_mut<V>(&mut self) -> impl Iterator<Item = StreamingVectorMut<'_, V>>
where
V: GenericVector<Element = Self::Element>,
{
V::stream_aligned_slice_mut(self)
}
fn unaligned_simd_iter_mut<V>(&mut self) -> (UnalignedMut<'_, V>, &mut Self)
where
V: GenericVector<Element = Self::Element>,
{
V::iter_mut_unaligned(self)
}
}