core_simd/ops/
assign.rs

1//! Assignment operators
2
3use super::*;
4use core::ops::{AddAssign, MulAssign}; // commutative binary op-assignment
5use core::ops::{BitAndAssign, BitOrAssign, BitXorAssign}; // commutative bit binary op-assignment
6use core::ops::{DivAssign, RemAssign, SubAssign}; // non-commutative binary op-assignment
7use core::ops::{ShlAssign, ShrAssign}; // non-commutative bit binary op-assignment
8
9// Arithmetic
10
11macro_rules! assign_ops {
12    ($(impl<T, U, const N: usize> $assignTrait:ident<U> for Simd<T, N>
13        where
14            Self: $trait:ident,
15        {
16            fn $assign_call:ident(rhs: U) {
17                $call:ident
18            }
19        })*) => {
20        $(impl<T, U, const N: usize> $assignTrait<U> for Simd<T, N>
21        where
22            Self: $trait<U, Output = Self>,
23            T: SimdElement,
24        {
25            #[inline]
26            fn $assign_call(&mut self, rhs: U) {
27                *self = self.$call(rhs);
28            }
29        })*
30    }
31}
32
33assign_ops! {
34    // Arithmetic
35    impl<T, U, const N: usize> AddAssign<U> for Simd<T, N>
36    where
37        Self: Add,
38    {
39        fn add_assign(rhs: U) {
40            add
41        }
42    }
43
44    impl<T, U, const N: usize> MulAssign<U> for Simd<T, N>
45    where
46        Self: Mul,
47    {
48        fn mul_assign(rhs: U) {
49            mul
50        }
51    }
52
53    impl<T, U, const N: usize> SubAssign<U> for Simd<T, N>
54    where
55        Self: Sub,
56    {
57        fn sub_assign(rhs: U) {
58            sub
59        }
60    }
61
62    impl<T, U, const N: usize> DivAssign<U> for Simd<T, N>
63    where
64        Self: Div,
65    {
66        fn div_assign(rhs: U) {
67            div
68        }
69    }
70    impl<T, U, const N: usize> RemAssign<U> for Simd<T, N>
71    where
72        Self: Rem,
73    {
74        fn rem_assign(rhs: U) {
75            rem
76        }
77    }
78
79    // Bitops
80    impl<T, U, const N: usize> BitAndAssign<U> for Simd<T, N>
81    where
82        Self: BitAnd,
83    {
84        fn bitand_assign(rhs: U) {
85            bitand
86        }
87    }
88
89    impl<T, U, const N: usize> BitOrAssign<U> for Simd<T, N>
90    where
91        Self: BitOr,
92    {
93        fn bitor_assign(rhs: U) {
94            bitor
95        }
96    }
97
98    impl<T, U, const N: usize> BitXorAssign<U> for Simd<T, N>
99    where
100        Self: BitXor,
101    {
102        fn bitxor_assign(rhs: U) {
103            bitxor
104        }
105    }
106
107    impl<T, U, const N: usize> ShlAssign<U> for Simd<T, N>
108    where
109        Self: Shl,
110    {
111        fn shl_assign(rhs: U) {
112            shl
113        }
114    }
115
116    impl<T, U, const N: usize> ShrAssign<U> for Simd<T, N>
117    where
118        Self: Shr,
119    {
120        fn shr_assign(rhs: U) {
121            shr
122        }
123    }
124}