1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use core::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};

use crate::{private, ArrayOps};

pub trait ArraySimdOps<T, const N: usize, const M: usize>: ArrayOps<Simd<T, M>, N>
where
    T: SimdElement,
    LaneCount<M>: SupportedLaneCount
{
    fn array_unsimd(self) -> [T; N*M];
    fn array_unsimd_ref(&self) -> &[T; N*M];
    fn array_unsimd_mut(&mut self) -> &mut [T; N*M];
}

impl<T, const N: usize, const M: usize> ArraySimdOps<T, N, M> for [Simd<T, M>; N]
where
    T: SimdElement,
    LaneCount<M>: SupportedLaneCount
{
    fn array_unsimd(self) -> [T; N*M]
    {
        unsafe {private::transmute_unchecked_size(self)}
    }

    fn array_unsimd_ref(&self) -> &[T; N*M]
    {
        unsafe {&*self.as_ptr().cast()}
    }

    fn array_unsimd_mut(&mut self) -> &mut [T; N*M]
    {
        unsafe {&mut *self.as_mut_ptr().cast()}
    }
}