|
| 1 | +// Shift operations uniquely typically only have a scalar on the right-hand side. |
| 2 | +// Here, we implement shifts for scalar RHS arguments. |
| 3 | + |
| 4 | +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; |
| 5 | + |
| 6 | +macro_rules! impl_splatted_shifts { |
| 7 | + { impl $trait:ident :: $trait_fn:ident for $ty:ty } => { |
| 8 | + impl<const N: usize> core::ops::$trait<$ty> for Simd<$ty, N> |
| 9 | + where |
| 10 | + LaneCount<N>: SupportedLaneCount, |
| 11 | + { |
| 12 | + type Output = Self; |
| 13 | + fn $trait_fn(self, rhs: $ty) -> Self::Output { |
| 14 | + self.$trait_fn(Simd::splat(rhs)) |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + impl<const N: usize> core::ops::$trait<&$ty> for Simd<$ty, N> |
| 19 | + where |
| 20 | + LaneCount<N>: SupportedLaneCount, |
| 21 | + { |
| 22 | + type Output = Self; |
| 23 | + fn $trait_fn(self, rhs: &$ty) -> Self::Output { |
| 24 | + self.$trait_fn(Simd::splat(*rhs)) |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + impl<'lhs, const N: usize> core::ops::$trait<$ty> for &'lhs Simd<$ty, N> |
| 29 | + where |
| 30 | + LaneCount<N>: SupportedLaneCount, |
| 31 | + { |
| 32 | + type Output = Simd<$ty, N>; |
| 33 | + fn $trait_fn(self, rhs: $ty) -> Self::Output { |
| 34 | + self.$trait_fn(Simd::splat(rhs)) |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + impl<'lhs, const N: usize> core::ops::$trait<&$ty> for &'lhs Simd<$ty, N> |
| 39 | + where |
| 40 | + LaneCount<N>: SupportedLaneCount, |
| 41 | + { |
| 42 | + type Output = Simd<$ty, N>; |
| 43 | + fn $trait_fn(self, rhs: &$ty) -> Self::Output { |
| 44 | + self.$trait_fn(Simd::splat(*rhs)) |
| 45 | + } |
| 46 | + } |
| 47 | + }; |
| 48 | + { $($ty:ty),* } => { |
| 49 | + $( |
| 50 | + impl_splatted_shifts! { impl Shl::shl for $ty } |
| 51 | + impl_splatted_shifts! { impl Shr::shr for $ty } |
| 52 | + )* |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// In the past there were inference issues when generically splatting arguments. |
| 57 | +// Enumerate them instead. |
| 58 | +impl_splatted_shifts! { i8, i16, i32, i64, isize, u8, u16, u32, u64, usize } |
0 commit comments