1 | //! Assignment operators |
2 | use super::*; |
3 | use core::ops::{AddAssign, MulAssign}; // commutative binary op-assignment |
4 | use core::ops::{BitAndAssign, BitOrAssign, BitXorAssign}; // commutative bit binary op-assignment |
5 | use core::ops::{DivAssign, RemAssign, SubAssign}; // non-commutative binary op-assignment |
6 | use core::ops::{ShlAssign, ShrAssign}; // non-commutative bit binary op-assignment |
7 | |
8 | // Arithmetic |
9 | |
10 | macro_rules! assign_ops { |
11 | ($(impl<T, U, const N: usize> $assignTrait:ident<U> for Simd<T, N> |
12 | where |
13 | Self: $trait:ident, |
14 | { |
15 | fn $assign_call:ident(rhs: U) { |
16 | $call:ident |
17 | } |
18 | })*) => { |
19 | $(impl<T, U, const N: usize> $assignTrait<U> for Simd<T, N> |
20 | where |
21 | Self: $trait<U, Output = Self>, |
22 | T: SimdElement, |
23 | LaneCount<N>: SupportedLaneCount, |
24 | { |
25 | #[inline] |
26 | fn $assign_call(&mut self, rhs: U) { |
27 | *self = self.$call(rhs); |
28 | } |
29 | })* |
30 | } |
31 | } |
32 | |
33 | assign_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 | } |
125 | |