macro_rules! unsafe_map_binary_op {
($type:ty, $trait:path, $func:ident, $intrinsic:expr, $requires:literal) => {
impl $trait for $type {
type Output = Self;
#[inline(always)]
fn $func(self, rhs: Self) -> Self::Output {
Self(unsafe { $intrinsic(self.0, rhs.0) })
}
}
};
}
macro_rules! unsafe_map_unary_op {
($type:ty, $trait:path, $func:ident, $intrinsic:expr, $requires:literal) => {
impl $trait for $type {
#[inline(always)]
fn $func(self) -> Self {
Self(unsafe { $intrinsic(self.0) })
}
}
};
}
macro_rules! unsafe_map_conversion {
($from:ty, $to:ty, $intrinsic:expr, $requires:literal) => {
impl From<$from> for $to {
#[inline(always)]
fn from(value: $from) -> $to {
Self(unsafe { $intrinsic(value.0) })
}
}
};
}
macro_rules! unsafe_map_cast {
($from:ty => ($scalar:ty, $to:ty), $intrinsic:expr, $requires:literal) => {
impl SIMDCast<$scalar> for $from {
type Cast = $to;
#[inline(always)]
fn simd_cast(self) -> Self::Cast {
use crate::SIMDVector;
Self::Cast::from_underlying(self.arch(), unsafe { $intrinsic(self.0) })
}
}
};
}
macro_rules! scalar_shift_by_splat {
($T:ty, $scalar:ty) => {
impl std::ops::Shr<$scalar> for $T {
type Output = Self;
#[inline(always)]
fn shr(self, rhs: $scalar) -> Self {
self.shr(<Self as SIMDVector>::splat(self.arch(), rhs))
}
}
impl std::ops::Shl<$scalar> for $T {
type Output = Self;
#[inline(always)]
fn shl(self, rhs: $scalar) -> Self {
self.shl(<Self as SIMDVector>::splat(self.arch(), rhs))
}
}
};
}
pub(crate) use scalar_shift_by_splat;
pub(crate) use unsafe_map_binary_op;
pub(crate) use unsafe_map_cast;
pub(crate) use unsafe_map_conversion;
pub(crate) use unsafe_map_unary_op;