ggmath 0.17.1

A linear algebra library for games and graphics with generic SIMD types.
Documentation
use core::mem::transmute;

use wide::{
    f32x4, f32x8, f32x16, f64x2, f64x4, f64x8, i8x16, i8x32, i16x8, i16x16, i16x32, i32x4, i32x8,
    i32x16, i64x2, i64x4, i64x8, u8x16, u8x32, u16x8, u16x16, u16x32, u32x4, u32x8, u32x16, u64x2,
    u64x4, u64x8,
};

use crate::{Alignment, NegOne, One, Scalar, Zero, backend::DefaultBackend};

macro_rules! float_impl {
    ($T:ident, $F:ident, $N:literal) => {
        impl Scalar for $T {}

        impl<const N: usize, A: Alignment> DefaultBackend<N, A> for $T {}

        impl Zero for $T {
            const ZERO: Self = unsafe { transmute::<[$F; $N], $T>([0.0; $N]) };
        }

        impl One for $T {
            const ONE: Self = unsafe { transmute::<[$F; $N], $T>([1.0; $N]) };
        }

        impl NegOne for $T {
            const NEG_ONE: Self = unsafe { transmute::<[$F; $N], $T>([-1.0; $N]) };
        }
    };
}
float_impl!(f32x4, f32, 4);
float_impl!(f32x8, f32, 8);
float_impl!(f32x16, f32, 16);
float_impl!(f64x2, f64, 2);
float_impl!(f64x4, f64, 4);
float_impl!(f64x8, f64, 8);

macro_rules! int_impl {
    ($T:ident) => {
        impl Scalar for $T {}

        impl<const N: usize, A: Alignment> DefaultBackend<N, A> for $T {}

        impl Zero for $T {
            const ZERO: Self = Self::ZERO;
        }

        impl One for $T {
            const ONE: Self = Self::ONE;
        }

        impl NegOne for $T {
            const NEG_ONE: Self = Self::new([-1; _]);
        }
    };
}
int_impl!(i8x16);
int_impl!(i8x32);
int_impl!(i16x8);
int_impl!(i16x16);
int_impl!(i16x32);
int_impl!(i32x4);
int_impl!(i32x8);
int_impl!(i32x16);
int_impl!(i64x2);
int_impl!(i64x4);
int_impl!(i64x8);

macro_rules! uint_impl {
    ($T:ident) => {
        impl Scalar for $T {}

        impl<const N: usize, A: Alignment> DefaultBackend<N, A> for $T {}

        impl Zero for $T {
            const ZERO: Self = Self::ZERO;
        }

        impl One for $T {
            const ONE: Self = Self::ONE;
        }
    };
}
uint_impl!(u8x16);
uint_impl!(u8x32);
uint_impl!(u16x8);
uint_impl!(u16x16);
uint_impl!(u16x32);
uint_impl!(u32x4);
uint_impl!(u32x8);
uint_impl!(u32x16);
uint_impl!(u64x2);
uint_impl!(u64x4);
uint_impl!(u64x8);