lightweight-simd 0.1.1

Lightweight generic fixed-array vector types relying on compiler auto-vectorization
Documentation
// Most or all contents generated by AI (model glm-5.3)

//! Enforced-alignment vector types.
//!
//! [`Aligned4`] through [`Aligned64`] are siblings of [`Simd`]: fixed-length
//! lane vectors over `[T; N]` that share one implementation with it — every
//! impl block in this crate is written once and instantiated for `Simd` and
//! the five aligned types together, so the whole operation surface is
//! identical across the six types. The only difference is the enforced byte
//! alignment of 4/8/16/32/64.
//!
//! The concrete aliases ([`f64x8`](crate::f64x8), …) pick the type whose
//! alignment is the vector's byte size rounded up to a power of two, capped at
//! 64 bytes. Conversions between plain and aligned vectors are `From`/`.0`/
//! `to_simd`.
//!
//! Masks ([`Simd<bool, N>`]) are never aligned: they are register-resident
//! temporaries. Comparisons on any vector type return plain masks, and
//! per-lane selection is `value.mask_select(mask, other)`.

use crate::Simd;

#[duplicate::duplicate_item(
    _vec_       _align_;
    [Aligned4]  [4];
    [Aligned8]  [8];
    [Aligned16] [16];
    [Aligned32] [32];
    [Aligned64] [64];
)]
#[repr(align(_align_))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Copy)]
#[doc = concat!("A fixed-length vector of `N` lanes of element type `T` over `[T; N]` with enforced ", stringify!(_align_), "-byte alignment; see the [module](crate::aligned) docs.")]
pub struct _vec_<T, const N: usize>(pub [T; N]);

#[duplicate::duplicate_item(
    _vec_;
    [Aligned4];
    [Aligned8];
    [Aligned16];
    [Aligned32];
    [Aligned64];
)]
impl<T, const N: usize> From<Simd<T, N>> for _vec_<T, N> {
    #[inline(always)]
    fn from(v: Simd<T, N>) -> Self {
        Self(v.0)
    }
}

#[duplicate::duplicate_item(
    _vec_;
    [Aligned4];
    [Aligned8];
    [Aligned16];
    [Aligned32];
    [Aligned64];
)]
impl<T, const N: usize> From<_vec_<T, N>> for Simd<T, N> {
    #[inline(always)]
    fn from(v: _vec_<T, N>) -> Self {
        Simd(v.0)
    }
}

#[duplicate::duplicate_item(
    _vec_;
    [Aligned4];
    [Aligned8];
    [Aligned16];
    [Aligned32];
    [Aligned64];
)]
impl<T, const N: usize> _vec_<T, N> {
    /// Returns the equivalent plain (naturally aligned) vector.
    #[inline(always)]
    pub fn to_simd(self) -> Simd<T, N> {
        Simd(self.0)
    }
}