rust/crates/core_simd/src/iter.rs

53 lines
1.6 KiB
Rust
Raw Normal View History

2021-06-13 12:52:44 -05:00
macro_rules! impl_traits {
{ $type:ident } => {
2021-06-13 12:52:44 -05:00
impl<const LANES: usize> core::iter::Sum<Self> for crate::$type<LANES>
where
Self: crate::Vector,
2021-06-13 12:52:44 -05:00
{
fn sum<I: core::iter::Iterator<Item = Self>>(iter: I) -> Self {
iter.fold(Default::default(), core::ops::Add::add)
}
}
impl<const LANES: usize> core::iter::Product<Self> for crate::$type<LANES>
where
Self: crate::Vector,
2021-06-13 12:52:44 -05:00
{
fn product<I: core::iter::Iterator<Item = Self>>(iter: I) -> Self {
iter.fold(Default::default(), core::ops::Mul::mul)
}
}
2021-06-13 13:00:47 -05:00
impl<'a, const LANES: usize> core::iter::Sum<&'a Self> for crate::$type<LANES>
where
Self: crate::Vector,
2021-06-13 13:00:47 -05:00
{
fn sum<I: core::iter::Iterator<Item = &'a Self>>(iter: I) -> Self {
iter.fold(Default::default(), core::ops::Add::add)
}
}
impl<'a, const LANES: usize> core::iter::Product<&'a Self> for crate::$type<LANES>
where
Self: crate::Vector,
2021-06-13 13:00:47 -05:00
{
fn product<I: core::iter::Iterator<Item = &'a Self>>(iter: I) -> Self {
iter.fold(Default::default(), core::ops::Mul::mul)
}
}
2021-06-13 12:52:44 -05:00
}
}
impl_traits! { SimdF32 }
impl_traits! { SimdF64 }
impl_traits! { SimdU8 }
impl_traits! { SimdU16 }
impl_traits! { SimdU32 }
impl_traits! { SimdU64 }
impl_traits! { SimdUsize }
impl_traits! { SimdI8 }
impl_traits! { SimdI16 }
impl_traits! { SimdI32 }
impl_traits! { SimdI64 }
impl_traits! { SimdIsize }