polylane 0.12.0

Portable and versatile SIMD.
Documentation
// Copyright 2025 Gabriel Bjørnager Jensen.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, you
// can obtain one at:
// <https://mozilla.org/MPL/2.0/>.

use crate::compat::{Freeze, Thin};
use crate::compat::bytemuck;
use crate::compat::zerocopy;

use crate::detail::DataKind;

/// Denotes a type suitable as a [SIMD vector](crate::simd::Simd) element.
///
/// # Safety
///
/// Only primitive, arithmetic types may be vector elements.
pub unsafe trait SimdScalar:
	crate::simd::seal::SimdScalar
	+ Copy
	+ Default
	+ Freeze
	+ zerocopy::FromZeros
	+ zerocopy::KnownLayout
	+ Thin
	+ Unpin
	+ bytemuck::Zeroable
{}

macro_rules! impl_simd_scalar {
	{
		$($Ty:ty: $data_kind:ident $(= $feature:literal)?),*$(,)?
	} => {
		$(
			$(#[cfg(feature = $feature)])?
			unsafe impl ::polylane::simd::seal::SimdScalar for $Ty {
				const DATA_KIND: ::polylane::detail::DataKind = ::polylane::detail::DataKind::$data_kind;
			}

			$(#[cfg(feature = $feature)])?
			unsafe impl ::polylane::simd::SimdScalar for $Ty {}
		)*
	};
}

impl_simd_scalar! {
	u8:    U8,
	u16:   U16,
	u32:   U32,
	u64:   U64,
	u128:  U128,
	usize: Usize,

	i8:    I8,
	i16:   I16,
	i32:   I32,
	i64:   I64,
	i128:  I128,
	isize: Isize,

	f16:  F16  = "f16",
	f32:  F32,
	f64:  F64,
	f128: F128 = "f128",
}

unsafe impl<T: Sized> crate::simd::seal::SimdScalar for *const T {
	const DATA_KIND: DataKind = DataKind::ConstPtr;
}

unsafe impl<T: Sized> SimdScalar for *const T {}

unsafe impl<T: Sized> crate::simd::seal::SimdScalar for *mut T {
	const DATA_KIND: DataKind = DataKind::MutPtr;
}

unsafe impl<T: Sized> SimdScalar for *mut T {}