Remove most usage of type aliases
This commit is contained in:
parent
e11286a362
commit
5ed57b4c85
@ -1,54 +1,58 @@
|
|||||||
use crate::{LaneCount, SupportedLaneCount};
|
use crate::{LaneCount, Simd, SupportedLaneCount};
|
||||||
|
use core::{
|
||||||
|
iter::{Product, Sum},
|
||||||
|
ops::{Add, Mul},
|
||||||
|
};
|
||||||
|
|
||||||
macro_rules! impl_traits {
|
macro_rules! impl_traits {
|
||||||
{ $type:ident } => {
|
{ $type:ty } => {
|
||||||
impl<const LANES: usize> core::iter::Sum<Self> for crate::$type<LANES>
|
impl<const LANES: usize> Sum<Self> for Simd<$type, LANES>
|
||||||
where
|
where
|
||||||
LaneCount<LANES>: SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
fn sum<I: core::iter::Iterator<Item = Self>>(iter: I) -> Self {
|
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
|
||||||
iter.fold(Default::default(), core::ops::Add::add)
|
iter.fold(Simd::splat(0 as $type), Add::add)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const LANES: usize> core::iter::Product<Self> for crate::$type<LANES>
|
impl<const LANES: usize> core::iter::Product<Self> for Simd<$type, LANES>
|
||||||
where
|
where
|
||||||
LaneCount<LANES>: SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
fn product<I: core::iter::Iterator<Item = Self>>(iter: I) -> Self {
|
fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
|
||||||
iter.fold(Default::default(), core::ops::Mul::mul)
|
iter.fold(Simd::splat(1 as $type), Mul::mul)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, const LANES: usize> core::iter::Sum<&'a Self> for crate::$type<LANES>
|
impl<'a, const LANES: usize> Sum<&'a Self> for Simd<$type, LANES>
|
||||||
where
|
where
|
||||||
LaneCount<LANES>: SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
fn sum<I: core::iter::Iterator<Item = &'a Self>>(iter: I) -> Self {
|
fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
|
||||||
iter.fold(Default::default(), core::ops::Add::add)
|
iter.fold(Simd::splat(0 as $type), Add::add)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, const LANES: usize> core::iter::Product<&'a Self> for crate::$type<LANES>
|
impl<'a, const LANES: usize> Product<&'a Self> for Simd<$type, LANES>
|
||||||
where
|
where
|
||||||
LaneCount<LANES>: SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
fn product<I: core::iter::Iterator<Item = &'a Self>>(iter: I) -> Self {
|
fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
|
||||||
iter.fold(Default::default(), core::ops::Mul::mul)
|
iter.fold(Simd::splat(1 as $type), Mul::mul)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_traits! { SimdF32 }
|
impl_traits! { f32 }
|
||||||
impl_traits! { SimdF64 }
|
impl_traits! { f64 }
|
||||||
impl_traits! { SimdU8 }
|
impl_traits! { u8 }
|
||||||
impl_traits! { SimdU16 }
|
impl_traits! { u16 }
|
||||||
impl_traits! { SimdU32 }
|
impl_traits! { u32 }
|
||||||
impl_traits! { SimdU64 }
|
impl_traits! { u64 }
|
||||||
impl_traits! { SimdUsize }
|
impl_traits! { usize }
|
||||||
impl_traits! { SimdI8 }
|
impl_traits! { i8 }
|
||||||
impl_traits! { SimdI16 }
|
impl_traits! { i16 }
|
||||||
impl_traits! { SimdI32 }
|
impl_traits! { i32 }
|
||||||
impl_traits! { SimdI64 }
|
impl_traits! { i64 }
|
||||||
impl_traits! { SimdIsize }
|
impl_traits! { isize }
|
||||||
|
@ -522,21 +522,21 @@ pub type masksizex4 = MaskSize<4>;
|
|||||||
pub type masksizex8 = MaskSize<8>;
|
pub type masksizex8 = MaskSize<8>;
|
||||||
|
|
||||||
macro_rules! impl_from {
|
macro_rules! impl_from {
|
||||||
{ $from:ident ($from_inner:ident) => $($to:ident ($to_inner:ident)),* } => {
|
{ $from:ty => $($to:ty),* } => {
|
||||||
$(
|
$(
|
||||||
impl<const LANES: usize> From<$from<LANES>> for $to<LANES>
|
impl<const LANES: usize> From<Mask<$from, LANES>> for Mask<$to, LANES>
|
||||||
where
|
where
|
||||||
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
fn from(value: $from<LANES>) -> Self {
|
fn from(value: Mask<$from, LANES>) -> Self {
|
||||||
Self(value.0.convert())
|
Self(value.0.convert())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl_from! { Mask8 (SimdI8) => Mask16 (SimdI16), Mask32 (SimdI32), Mask64 (SimdI64), MaskSize (SimdIsize) }
|
impl_from! { i8 => i16, i32, i64, isize }
|
||||||
impl_from! { Mask16 (SimdI16) => Mask32 (SimdI32), Mask64 (SimdI64), MaskSize (SimdIsize), Mask8 (SimdI8) }
|
impl_from! { i16 => i32, i64, isize, i8 }
|
||||||
impl_from! { Mask32 (SimdI32) => Mask64 (SimdI64), MaskSize (SimdIsize), Mask8 (SimdI8), Mask16 (SimdI16) }
|
impl_from! { i32 => i64, isize, i8, i16 }
|
||||||
impl_from! { Mask64 (SimdI64) => MaskSize (SimdIsize), Mask8 (SimdI8), Mask16 (SimdI16), Mask32 (SimdI32) }
|
impl_from! { i64 => isize, i8, i16, i32 }
|
||||||
impl_from! { MaskSize (SimdIsize) => Mask8 (SimdI8), Mask16 (SimdI16), Mask32 (SimdI32), Mask64 (SimdI64) }
|
impl_from! { isize => i8, i16, i32, i64 }
|
||||||
|
@ -158,6 +158,16 @@ where
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn any(self) -> bool {
|
||||||
|
unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn all(self) -> bool {
|
||||||
|
unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Element, const LANES: usize> core::convert::From<Mask<Element, LANES>> for Simd<Element, LANES>
|
impl<Element, const LANES: usize> core::convert::From<Mask<Element, LANES>> for Simd<Element, LANES>
|
||||||
@ -217,5 +227,3 @@ where
|
|||||||
Self::splat(true) ^ self
|
Self::splat(true) ^ self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_full_mask_reductions! {}
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
use crate::{LaneCount, Simd, SupportedLaneCount};
|
||||||
|
|
||||||
macro_rules! impl_uint_arith {
|
macro_rules! impl_uint_arith {
|
||||||
($(($name:ident, $n:ident)),+) => {
|
($($ty:ty),+) => {
|
||||||
$( impl<const LANES: usize> $name<LANES> where crate::LaneCount<LANES>: crate::SupportedLaneCount {
|
$( impl<const LANES: usize> Simd<$ty, LANES> where LaneCount<LANES>: SupportedLaneCount {
|
||||||
|
|
||||||
/// Lanewise saturating add.
|
/// Lanewise saturating add.
|
||||||
///
|
///
|
||||||
@ -8,9 +10,9 @@ macro_rules! impl_uint_arith {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(portable_simd)]
|
/// # #![feature(portable_simd)]
|
||||||
/// # use core_simd::*;
|
/// # use core_simd::*;
|
||||||
#[doc = concat!("# use core::", stringify!($n), "::MAX;")]
|
#[doc = concat!("# use core::", stringify!($ty), "::MAX;")]
|
||||||
#[doc = concat!("let x = ", stringify!($name), "::from_array([2, 1, 0, MAX]);")]
|
/// let x = Simd::from_array([2, 1, 0, MAX]);
|
||||||
#[doc = concat!("let max = ", stringify!($name), "::splat(MAX);")]
|
/// let max = Simd::splat(MAX);
|
||||||
/// let unsat = x + max;
|
/// let unsat = x + max;
|
||||||
/// let sat = x.saturating_add(max);
|
/// let sat = x.saturating_add(max);
|
||||||
/// assert_eq!(x - 1, unsat);
|
/// assert_eq!(x - 1, unsat);
|
||||||
@ -27,13 +29,13 @@ macro_rules! impl_uint_arith {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(portable_simd)]
|
/// # #![feature(portable_simd)]
|
||||||
/// # use core_simd::*;
|
/// # use core_simd::*;
|
||||||
#[doc = concat!("# use core::", stringify!($n), "::MAX;")]
|
#[doc = concat!("# use core::", stringify!($ty), "::MAX;")]
|
||||||
#[doc = concat!("let x = ", stringify!($name), "::from_array([2, 1, 0, MAX]);")]
|
/// let x = Simd::from_array([2, 1, 0, MAX]);
|
||||||
#[doc = concat!("let max = ", stringify!($name), "::splat(MAX);")]
|
/// let max = Simd::splat(MAX);
|
||||||
/// let unsat = x - max;
|
/// let unsat = x - max;
|
||||||
/// let sat = x.saturating_sub(max);
|
/// let sat = x.saturating_sub(max);
|
||||||
/// assert_eq!(unsat, x + 1);
|
/// assert_eq!(unsat, x + 1);
|
||||||
#[doc = concat!("assert_eq!(sat, ", stringify!($name), "::splat(0));")]
|
/// assert_eq!(sat, Simd::splat(0));
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_sub(self, second: Self) -> Self {
|
pub fn saturating_sub(self, second: Self) -> Self {
|
||||||
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
|
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
|
||||||
@ -43,8 +45,8 @@ macro_rules! impl_uint_arith {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_int_arith {
|
macro_rules! impl_int_arith {
|
||||||
($(($name:ident, $n:ident)),+) => {
|
($($ty:ty),+) => {
|
||||||
$( impl<const LANES: usize> $name<LANES> where crate::LaneCount<LANES>: crate::SupportedLaneCount {
|
$( impl<const LANES: usize> Simd<$ty, LANES> where LaneCount<LANES>: SupportedLaneCount {
|
||||||
|
|
||||||
/// Lanewise saturating add.
|
/// Lanewise saturating add.
|
||||||
///
|
///
|
||||||
@ -52,13 +54,13 @@ macro_rules! impl_int_arith {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(portable_simd)]
|
/// # #![feature(portable_simd)]
|
||||||
/// # use core_simd::*;
|
/// # use core_simd::*;
|
||||||
#[doc = concat!("# use core::", stringify!($n), "::{MIN, MAX};")]
|
#[doc = concat!("# use core::", stringify!($ty), "::{MIN, MAX};")]
|
||||||
#[doc = concat!("let x = ", stringify!($name), "::from_array([MIN, 0, 1, MAX]);")]
|
/// let x = Simd::from_array([MIN, 0, 1, MAX]);
|
||||||
#[doc = concat!("let max = ", stringify!($name), "::splat(MAX);")]
|
/// let max = Simd::splat(MAX);
|
||||||
/// let unsat = x + max;
|
/// let unsat = x + max;
|
||||||
/// let sat = x.saturating_add(max);
|
/// let sat = x.saturating_add(max);
|
||||||
#[doc = concat!("assert_eq!(unsat, ", stringify!($name), "::from_array([-1, MAX, MIN, -2]));")]
|
/// assert_eq!(unsat, Simd::from_array([-1, MAX, MIN, -2]));
|
||||||
#[doc = concat!("assert_eq!(sat, ", stringify!($name), "::from_array([-1, MAX, MAX, MAX]));")]
|
/// assert_eq!(sat, Simd::from_array([-1, MAX, MAX, MAX]));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_add(self, second: Self) -> Self {
|
pub fn saturating_add(self, second: Self) -> Self {
|
||||||
@ -71,13 +73,13 @@ macro_rules! impl_int_arith {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(portable_simd)]
|
/// # #![feature(portable_simd)]
|
||||||
/// # use core_simd::*;
|
/// # use core_simd::*;
|
||||||
#[doc = concat!("# use core::", stringify!($n), "::{MIN, MAX};")]
|
#[doc = concat!("# use core::", stringify!($ty), "::{MIN, MAX};")]
|
||||||
#[doc = concat!("let x = ", stringify!($name), "::from_array([MIN, -2, -1, MAX]);")]
|
/// let x = Simd::from_array([MIN, -2, -1, MAX]);
|
||||||
#[doc = concat!("let max = ", stringify!($name), "::splat(MAX);")]
|
/// let max = Simd::splat(MAX);
|
||||||
/// let unsat = x - max;
|
/// let unsat = x - max;
|
||||||
/// let sat = x.saturating_sub(max);
|
/// let sat = x.saturating_sub(max);
|
||||||
#[doc = concat!("assert_eq!(unsat, ", stringify!($name), "::from_array([1, MAX, MIN, 0]));")]
|
/// assert_eq!(unsat, Simd::from_array([1, MAX, MIN, 0]));
|
||||||
#[doc = concat!("assert_eq!(sat, ", stringify!($name), "::from_array([MIN, MIN, MIN, 0]));")]
|
/// assert_eq!(sat, Simd::from_array([MIN, MIN, MIN, 0]));
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_sub(self, second: Self) -> Self {
|
pub fn saturating_sub(self, second: Self) -> Self {
|
||||||
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
|
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
|
||||||
@ -90,13 +92,13 @@ macro_rules! impl_int_arith {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(portable_simd)]
|
/// # #![feature(portable_simd)]
|
||||||
/// # use core_simd::*;
|
/// # use core_simd::*;
|
||||||
#[doc = concat!("# use core::", stringify!($n), "::{MIN, MAX};")]
|
#[doc = concat!("# use core::", stringify!($ty), "::{MIN, MAX};")]
|
||||||
#[doc = concat!("let xs = ", stringify!($name), "::from_array([MIN, MIN +1, -5, 0]);")]
|
/// let xs = Simd::from_array([MIN, MIN +1, -5, 0]);
|
||||||
#[doc = concat!("assert_eq!(xs.abs(), ", stringify!($name), "::from_array([MIN, MAX, 5, 0]));")]
|
/// assert_eq!(xs.abs(), Simd::from_array([MIN, MAX, 5, 0]));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn abs(self) -> Self {
|
pub fn abs(self) -> Self {
|
||||||
const SHR: $n = <$n>::BITS as $n - 1;
|
const SHR: $ty = <$ty>::BITS as $ty - 1;
|
||||||
let m = self >> SHR;
|
let m = self >> SHR;
|
||||||
(self^m) - m
|
(self^m) - m
|
||||||
}
|
}
|
||||||
@ -108,17 +110,17 @@ macro_rules! impl_int_arith {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(portable_simd)]
|
/// # #![feature(portable_simd)]
|
||||||
/// # use core_simd::*;
|
/// # use core_simd::*;
|
||||||
#[doc = concat!("# use core::", stringify!($n), "::{MIN, MAX};")]
|
#[doc = concat!("# use core::", stringify!($ty), "::{MIN, MAX};")]
|
||||||
#[doc = concat!("let xs = ", stringify!($name), "::from_array([MIN, -2, 0, 3]);")]
|
/// let xs = Simd::from_array([MIN, -2, 0, 3]);
|
||||||
/// let unsat = xs.abs();
|
/// let unsat = xs.abs();
|
||||||
/// let sat = xs.saturating_abs();
|
/// let sat = xs.saturating_abs();
|
||||||
#[doc = concat!("assert_eq!(unsat, ", stringify!($name), "::from_array([MIN, 2, 0, 3]));")]
|
/// assert_eq!(unsat, Simd::from_array([MIN, 2, 0, 3]));
|
||||||
#[doc = concat!("assert_eq!(sat, ", stringify!($name), "::from_array([MAX, 2, 0, 3]));")]
|
/// assert_eq!(sat, Simd::from_array([MAX, 2, 0, 3]));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_abs(self) -> Self {
|
pub fn saturating_abs(self) -> Self {
|
||||||
// arith shift for -1 or 0 mask based on sign bit, giving 2s complement
|
// arith shift for -1 or 0 mask based on sign bit, giving 2s complement
|
||||||
const SHR: $n = <$n>::BITS as $n - 1;
|
const SHR: $ty = <$ty>::BITS as $ty - 1;
|
||||||
let m = self >> SHR;
|
let m = self >> SHR;
|
||||||
(self^m).saturating_sub(m)
|
(self^m).saturating_sub(m)
|
||||||
}
|
}
|
||||||
@ -130,12 +132,12 @@ macro_rules! impl_int_arith {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(portable_simd)]
|
/// # #![feature(portable_simd)]
|
||||||
/// # use core_simd::*;
|
/// # use core_simd::*;
|
||||||
#[doc = concat!("# use core::", stringify!($n), "::{MIN, MAX};")]
|
#[doc = concat!("# use core::", stringify!($ty), "::{MIN, MAX};")]
|
||||||
#[doc = concat!("let x = ", stringify!($name), "::from_array([MIN, -2, 3, MAX]);")]
|
/// let x = Simd::from_array([MIN, -2, 3, MAX]);
|
||||||
/// let unsat = -x;
|
/// let unsat = -x;
|
||||||
/// let sat = x.saturating_neg();
|
/// let sat = x.saturating_neg();
|
||||||
#[doc = concat!("assert_eq!(unsat, ", stringify!($name), "::from_array([MIN, 2, -3, MIN + 1]));")]
|
/// assert_eq!(unsat, Simd::from_array([MIN, 2, -3, MIN + 1]));
|
||||||
#[doc = concat!("assert_eq!(sat, ", stringify!($name), "::from_array([MAX, 2, -3, MIN + 1]));")]
|
/// assert_eq!(sat, Simd::from_array([MAX, 2, -3, MIN + 1]));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_neg(self) -> Self {
|
pub fn saturating_neg(self) -> Self {
|
||||||
@ -145,7 +147,5 @@ macro_rules! impl_int_arith {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::vector::*;
|
impl_uint_arith! { u8, u16, u32, u64, usize }
|
||||||
|
impl_int_arith! { i8, i16, i32, i64, isize }
|
||||||
impl_uint_arith! { (SimdU8, u8), (SimdU16, u16), (SimdU32, u32), (SimdU64, u64), (SimdUsize, usize) }
|
|
||||||
impl_int_arith! { (SimdI8, i8), (SimdI16, i16), (SimdI32, i32), (SimdI64, i64), (SimdIsize, isize) }
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
use crate::{LaneCount, Simd, SupportedLaneCount};
|
||||||
|
|
||||||
macro_rules! impl_integer_reductions {
|
macro_rules! impl_integer_reductions {
|
||||||
{ $name:ident, $scalar:ty } => {
|
{ $scalar:ty } => {
|
||||||
impl<const LANES: usize> crate::$name<LANES>
|
impl<const LANES: usize> Simd<$scalar, LANES>
|
||||||
where
|
where
|
||||||
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
/// Horizontal wrapping add. Returns the sum of the lanes of the vector, with wrapping addition.
|
/// Horizontal wrapping add. Returns the sum of the lanes of the vector, with wrapping addition.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -52,11 +54,22 @@ macro_rules! impl_integer_reductions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_integer_reductions! { i8 }
|
||||||
|
impl_integer_reductions! { i16 }
|
||||||
|
impl_integer_reductions! { i32 }
|
||||||
|
impl_integer_reductions! { i64 }
|
||||||
|
impl_integer_reductions! { isize }
|
||||||
|
impl_integer_reductions! { u8 }
|
||||||
|
impl_integer_reductions! { u16 }
|
||||||
|
impl_integer_reductions! { u32 }
|
||||||
|
impl_integer_reductions! { u64 }
|
||||||
|
impl_integer_reductions! { usize }
|
||||||
|
|
||||||
macro_rules! impl_float_reductions {
|
macro_rules! impl_float_reductions {
|
||||||
{ $name:ident, $scalar:ty } => {
|
{ $scalar:ty } => {
|
||||||
impl<const LANES: usize> crate::$name<LANES>
|
impl<const LANES: usize> Simd<$scalar, LANES>
|
||||||
where
|
where
|
||||||
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Horizontal add. Returns the sum of the lanes of the vector.
|
/// Horizontal add. Returns the sum of the lanes of the vector.
|
||||||
@ -102,22 +115,5 @@ macro_rules! impl_float_reductions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_full_mask_reductions {
|
impl_float_reductions! { f32 }
|
||||||
{} => {
|
impl_float_reductions! { f64 }
|
||||||
impl<Element, const LANES: usize> Mask<Element, LANES>
|
|
||||||
where
|
|
||||||
Element: MaskElement,
|
|
||||||
LaneCount<LANES>: SupportedLaneCount,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
pub fn any(self) -> bool {
|
|
||||||
unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn all(self) -> bool {
|
|
||||||
unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
|
use crate::{LaneCount, Simd, SupportedLaneCount};
|
||||||
|
|
||||||
macro_rules! implement {
|
macro_rules! implement {
|
||||||
{
|
{
|
||||||
$type:ident, $int_type:ident
|
$type:ty, $int_type:ty
|
||||||
} => {
|
} => {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<const LANES: usize> crate::$type<LANES>
|
impl<const LANES: usize> Simd<$type, LANES>
|
||||||
where
|
where
|
||||||
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
/// Returns the smallest integer greater than or equal to each lane.
|
/// Returns the smallest integer greater than or equal to each lane.
|
||||||
#[must_use = "method returns a new vector and does not mutate the original value"]
|
#[must_use = "method returns a new vector and does not mutate the original value"]
|
||||||
@ -43,9 +45,9 @@ macro_rules! implement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const LANES: usize> crate::$type<LANES>
|
impl<const LANES: usize> Simd<$type, LANES>
|
||||||
where
|
where
|
||||||
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
/// Rounds toward zero and converts to the same-width integer type, assuming that
|
/// Rounds toward zero and converts to the same-width integer type, assuming that
|
||||||
/// the value is finite and fits in that type.
|
/// the value is finite and fits in that type.
|
||||||
@ -57,19 +59,19 @@ macro_rules! implement {
|
|||||||
/// * Not be infinite
|
/// * Not be infinite
|
||||||
/// * Be representable in the return type, after truncating off its fractional part
|
/// * Be representable in the return type, after truncating off its fractional part
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn to_int_unchecked(self) -> crate::$int_type<LANES> {
|
pub unsafe fn to_int_unchecked(self) -> Simd<$int_type, LANES> {
|
||||||
crate::intrinsics::simd_cast(self)
|
crate::intrinsics::simd_cast(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a floating-point vector from an integer vector. Rounds values that are
|
/// Creates a floating-point vector from an integer vector. Rounds values that are
|
||||||
/// not exactly representable.
|
/// not exactly representable.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn round_from_int(value: crate::$int_type<LANES>) -> Self {
|
pub fn round_from_int(value: Simd<$int_type, LANES>) -> Self {
|
||||||
unsafe { crate::intrinsics::simd_cast(value) }
|
unsafe { crate::intrinsics::simd_cast(value) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implement! { SimdF32, SimdI32 }
|
implement! { f32, i32 }
|
||||||
implement! { SimdF64, SimdI64 }
|
implement! { f64, i64 }
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
macro_rules! impl_to_bytes {
|
macro_rules! impl_to_bytes {
|
||||||
{ $name:ident, $size:literal } => {
|
{ $ty:ty, $size:literal } => {
|
||||||
impl<const LANES: usize> crate::$name<LANES>
|
impl<const LANES: usize> crate::Simd<$ty, LANES>
|
||||||
where
|
where
|
||||||
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
||||||
crate::LaneCount<{{ $size * LANES }}>: crate::SupportedLaneCount,
|
crate::LaneCount<{{ $size * LANES }}>: crate::SupportedLaneCount,
|
||||||
{
|
{
|
||||||
/// Return the memory representation of this integer as a byte array in native byte
|
/// Return the memory representation of this integer as a byte array in native byte
|
||||||
/// order.
|
/// order.
|
||||||
pub fn to_ne_bytes(self) -> crate::SimdU8<{{ $size * LANES }}> {
|
pub fn to_ne_bytes(self) -> crate::Simd<u8, {{ $size * LANES }}> {
|
||||||
unsafe { core::mem::transmute_copy(&self) }
|
unsafe { core::mem::transmute_copy(&self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a native endian integer value from its memory representation as a byte array
|
/// Create a native endian integer value from its memory representation as a byte array
|
||||||
/// in native endianness.
|
/// in native endianness.
|
||||||
pub fn from_ne_bytes(bytes: crate::SimdU8<{{ $size * LANES }}>) -> Self {
|
pub fn from_ne_bytes(bytes: crate::Simd<u8, {{ $size * LANES }}>) -> Self {
|
||||||
unsafe { core::mem::transmute_copy(&bytes) }
|
unsafe { core::mem::transmute_copy(&bytes) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_to_bytes! { SimdU8, 1 }
|
impl_to_bytes! { u8, 1 }
|
||||||
impl_to_bytes! { SimdU16, 2 }
|
impl_to_bytes! { u16, 2 }
|
||||||
impl_to_bytes! { SimdU32, 4 }
|
impl_to_bytes! { u32, 4 }
|
||||||
impl_to_bytes! { SimdU64, 8 }
|
impl_to_bytes! { u64, 8 }
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
impl_to_bytes! { SimdUsize, 4 }
|
impl_to_bytes! { usize, 4 }
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
impl_to_bytes! { SimdUsize, 8 }
|
impl_to_bytes! { usize, 8 }
|
||||||
|
|
||||||
impl_to_bytes! { SimdI8, 1 }
|
impl_to_bytes! { i8, 1 }
|
||||||
impl_to_bytes! { SimdI16, 2 }
|
impl_to_bytes! { i16, 2 }
|
||||||
impl_to_bytes! { SimdI32, 4 }
|
impl_to_bytes! { i32, 4 }
|
||||||
impl_to_bytes! { SimdI64, 8 }
|
impl_to_bytes! { i64, 8 }
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
impl_to_bytes! { SimdIsize, 4 }
|
impl_to_bytes! { isize, 4 }
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
impl_to_bytes! { SimdIsize, 8 }
|
impl_to_bytes! { isize, 8 }
|
||||||
|
@ -7,8 +7,6 @@ use crate::{LaneCount, SupportedLaneCount};
|
|||||||
/// representation. Called from `define_float_vector!`.
|
/// representation. Called from `define_float_vector!`.
|
||||||
macro_rules! impl_float_vector {
|
macro_rules! impl_float_vector {
|
||||||
{ $name:ident, $type:ident, $bits_ty:ident, $mask_ty:ident, $mask_impl_ty:ident } => {
|
{ $name:ident, $type:ident, $bits_ty:ident, $mask_ty:ident, $mask_impl_ty:ident } => {
|
||||||
impl_float_reductions! { $name, $type }
|
|
||||||
|
|
||||||
impl<const LANES: usize> $name<LANES>
|
impl<const LANES: usize> $name<LANES>
|
||||||
where
|
where
|
||||||
LaneCount<LANES>: SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
|
@ -5,8 +5,6 @@ use crate::{LaneCount, SupportedLaneCount};
|
|||||||
/// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`.
|
/// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`.
|
||||||
macro_rules! impl_integer_vector {
|
macro_rules! impl_integer_vector {
|
||||||
{ $name:ident, $type:ty, $mask_ty:ident, $mask_impl_ty:ident } => {
|
{ $name:ident, $type:ty, $mask_ty:ident, $mask_impl_ty:ident } => {
|
||||||
impl_integer_reductions! { $name, $type }
|
|
||||||
|
|
||||||
impl<const LANES: usize> $name<LANES>
|
impl<const LANES: usize> $name<LANES>
|
||||||
where
|
where
|
||||||
LaneCount<LANES>: SupportedLaneCount,
|
LaneCount<LANES>: SupportedLaneCount,
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
/// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`.
|
|
||||||
macro_rules! impl_unsigned_vector {
|
|
||||||
{ $name:ident, $type:ty } => {
|
|
||||||
impl_integer_reductions! { $name, $type }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A SIMD vector of containing `LANES` `u8` values.
|
/// A SIMD vector of containing `LANES` `u8` values.
|
||||||
pub type SimdU8<const LANES: usize> = crate::Simd<u8, LANES>;
|
pub type SimdU8<const LANES: usize> = crate::Simd<u8, LANES>;
|
||||||
|
|
||||||
@ -22,12 +15,6 @@ pub type SimdU64<const LANES: usize> = crate::Simd<u64, LANES>;
|
|||||||
/// A SIMD vector of containing `LANES` `usize` values.
|
/// A SIMD vector of containing `LANES` `usize` values.
|
||||||
pub type SimdUsize<const LANES: usize> = crate::Simd<usize, LANES>;
|
pub type SimdUsize<const LANES: usize> = crate::Simd<usize, LANES>;
|
||||||
|
|
||||||
impl_unsigned_vector! { SimdUsize, usize }
|
|
||||||
impl_unsigned_vector! { SimdU16, u16 }
|
|
||||||
impl_unsigned_vector! { SimdU32, u32 }
|
|
||||||
impl_unsigned_vector! { SimdU64, u64 }
|
|
||||||
impl_unsigned_vector! { SimdU8, u8 }
|
|
||||||
|
|
||||||
/// Vector of two `usize` values
|
/// Vector of two `usize` values
|
||||||
pub type usizex2 = SimdUsize<2>;
|
pub type usizex2 = SimdUsize<2>;
|
||||||
|
|
||||||
|
16
crates/core_simd/src/vendor/arm.rs
vendored
16
crates/core_simd/src/vendor/arm.rs
vendored
@ -28,26 +28,26 @@ from_transmute! { unsafe u32x4 => uint32x4_t }
|
|||||||
from_transmute! { unsafe i32x2 => int32x2_t }
|
from_transmute! { unsafe i32x2 => int32x2_t }
|
||||||
from_transmute! { unsafe i32x4 => int32x4_t }
|
from_transmute! { unsafe i32x4 => int32x4_t }
|
||||||
|
|
||||||
from_transmute! { unsafe SimdU64<1> => uint64x1_t }
|
from_transmute! { unsafe Simd<u64, 1> => uint64x1_t }
|
||||||
from_transmute! { unsafe u64x2 => uint64x2_t }
|
from_transmute! { unsafe u64x2 => uint64x2_t }
|
||||||
from_transmute! { unsafe SimdI64<1> => int64x1_t }
|
from_transmute! { unsafe Simd<i64, 1> => int64x1_t }
|
||||||
from_transmute! { unsafe i64x2 => int64x2_t }
|
from_transmute! { unsafe i64x2 => int64x2_t }
|
||||||
from_transmute! { unsafe SimdU64<1> => poly64x1_t }
|
from_transmute! { unsafe Simd<u64, 1> => poly64x1_t }
|
||||||
from_transmute! { unsafe u64x2 => poly64x2_t }
|
from_transmute! { unsafe u64x2 => poly64x2_t }
|
||||||
|
|
||||||
#[cfg(target_arch = "arm")]
|
#[cfg(target_arch = "arm")]
|
||||||
mod arm {
|
mod arm {
|
||||||
use super::*;
|
use super::*;
|
||||||
from_transmute! { unsafe SimdU8<4> => uint8x4_t }
|
from_transmute! { unsafe Simd<u8, 4> => uint8x4_t }
|
||||||
from_transmute! { unsafe SimdI8<4> => int8x4_t }
|
from_transmute! { unsafe Simd<i8, 4> => int8x4_t }
|
||||||
|
|
||||||
from_transmute! { unsafe SimdU16<2> => uint16x2_t }
|
from_transmute! { unsafe Simd<u16, 2> => uint16x2_t }
|
||||||
from_transmute! { unsafe SimdI16<2> => int16x2_t }
|
from_transmute! { unsafe Simd<i16, 2> => int16x2_t }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
mod aarch64 {
|
mod aarch64 {
|
||||||
use super::*;
|
use super::*;
|
||||||
from_transmute! { unsafe SimdF64<1> => float64x1_t }
|
from_transmute! { unsafe Simd<f64, 1> => float64x1_t }
|
||||||
from_transmute! { unsafe f64x2 => float64x2_t }
|
from_transmute! { unsafe f64x2 => float64x2_t }
|
||||||
}
|
}
|
||||||
|
4
crates/core_simd/src/vendor/x86.rs
vendored
4
crates/core_simd/src/vendor/x86.rs
vendored
@ -45,10 +45,10 @@ mod p32 {
|
|||||||
use super::*;
|
use super::*;
|
||||||
from_transmute! { unsafe usizex4 => __m128i }
|
from_transmute! { unsafe usizex4 => __m128i }
|
||||||
from_transmute! { unsafe usizex8 => __m256i }
|
from_transmute! { unsafe usizex8 => __m256i }
|
||||||
from_transmute! { unsafe SimdUsize<16> => __m512i }
|
from_transmute! { unsafe Simd<usize, 16> => __m512i }
|
||||||
from_transmute! { unsafe isizex4 => __m128i }
|
from_transmute! { unsafe isizex4 => __m128i }
|
||||||
from_transmute! { unsafe isizex8 => __m256i }
|
from_transmute! { unsafe isizex8 => __m256i }
|
||||||
from_transmute! { unsafe SimdIsize<16> => __m512i }
|
from_transmute! { unsafe Simd<isize, 16> => __m512i }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user