1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Shift operations uniquely typically only have a scalar on the right-hand side.
// Here, we implement shifts for scalar RHS arguments.

use crate::simd::{LaneCount, Simd, SupportedLaneCount};

macro_rules! impl_splatted_shifts {
    { impl $trait:ident :: $trait_fn:ident for $ty:ty } => {
        impl<const N: usize> core::ops::$trait<$ty> for Simd<$ty, N>
        where
            LaneCount<N>: SupportedLaneCount,
        {
            type Output = Self;
            #[inline]
            fn $trait_fn(self, rhs: $ty) -> Self::Output {
                self.$trait_fn(Simd::splat(rhs))
            }
        }

        impl<const N: usize> core::ops::$trait<&$ty> for Simd<$ty, N>
        where
            LaneCount<N>: SupportedLaneCount,
        {
            type Output = Self;
            #[inline]
            fn $trait_fn(self, rhs: &$ty) -> Self::Output {
                self.$trait_fn(Simd::splat(*rhs))
            }
        }

        impl<'lhs, const N: usize> core::ops::$trait<$ty> for &'lhs Simd<$ty, N>
        where
            LaneCount<N>: SupportedLaneCount,
        {
            type Output = Simd<$ty, N>;
            #[inline]
            fn $trait_fn(self, rhs: $ty) -> Self::Output {
                self.$trait_fn(Simd::splat(rhs))
            }
        }

        impl<'lhs, const N: usize> core::ops::$trait<&$ty> for &'lhs Simd<$ty, N>
        where
            LaneCount<N>: SupportedLaneCount,
        {
            type Output = Simd<$ty, N>;
            #[inline]
            fn $trait_fn(self, rhs: &$ty) -> Self::Output {
                self.$trait_fn(Simd::splat(*rhs))
            }
        }
    };
    { $($ty:ty),* } => {
        $(
        impl_splatted_shifts! { impl Shl::shl for $ty }
        impl_splatted_shifts! { impl Shr::shr for $ty }
        )*
    }
}

// In the past there were inference issues when generically splatting arguments.
// Enumerate them instead.
impl_splatted_shifts! { i8, i16, i32, i64, isize, u8, u16, u32, u64, usize }