rust/crates/core_simd/src/iter.rs

55 lines
1.7 KiB
Rust
Raw Normal View History

2021-07-23 21:54:19 -05:00
use crate::{LaneCount, SupportedLaneCount};
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
2021-07-23 21:54:19 -05:00
LaneCount<LANES>: SupportedLaneCount,
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
2021-07-23 21:54:19 -05:00
LaneCount<LANES>: SupportedLaneCount,
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
2021-07-23 21:54:19 -05:00
LaneCount<LANES>: SupportedLaneCount,
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
2021-07-23 21:54:19 -05:00
LaneCount<LANES>: SupportedLaneCount,
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 }