wide/
u32x8_.rs

1use super::*;
2
3pick! {
4  if #[cfg(target_feature="avx2")] {
5    #[derive(Default, Clone, Copy, PartialEq, Eq)]
6    #[repr(C, align(32))]
7    pub struct u32x8 { avx2: m256i }
8  } else {
9    #[derive(Default, Clone, Copy, PartialEq, Eq)]
10    #[repr(C, align(32))]
11    pub struct u32x8 { a : u32x4, b : u32x4 }
12  }
13}
14
15int_uint_consts!(u32, 8, u32x8, u32x8, u32a8, const_u32_as_u32x8, 256);
16
17unsafe impl Zeroable for u32x8 {}
18unsafe impl Pod for u32x8 {}
19
20impl Add for u32x8 {
21  type Output = Self;
22  #[inline]
23  #[must_use]
24  fn add(self, rhs: Self) -> Self::Output {
25    pick! {
26      if #[cfg(target_feature="avx2")] {
27        Self { avx2: add_i32_m256i(self.avx2, rhs.avx2) }
28      } else {
29        Self {
30          a : self.a.add(rhs.a),
31          b : self.b.add(rhs.b),
32        }
33      }
34    }
35  }
36}
37
38impl Sub for u32x8 {
39  type Output = Self;
40  #[inline]
41  #[must_use]
42  fn sub(self, rhs: Self) -> Self::Output {
43    pick! {
44      if #[cfg(target_feature="avx2")] {
45        Self { avx2: sub_i32_m256i(self.avx2, rhs.avx2) }
46      } else {
47        Self {
48          a : self.a.sub(rhs.a),
49          b : self.b.sub(rhs.b),
50        }
51      }
52    }
53  }
54}
55
56impl Mul for u32x8 {
57  type Output = Self;
58  #[inline]
59  #[must_use]
60  fn mul(self, rhs: Self) -> Self::Output {
61    pick! {
62      if #[cfg(target_feature="avx2")] {
63        Self { avx2: mul_i32_keep_low_m256i(self.avx2, rhs.avx2) }
64      } else {
65        Self {
66          a : self.a.mul(rhs.a),
67          b : self.b.mul(rhs.b),
68        }
69      }
70    }
71  }
72}
73
74impl BitAnd for u32x8 {
75  type Output = Self;
76  #[inline]
77  #[must_use]
78  fn bitand(self, rhs: Self) -> Self::Output {
79    pick! {
80      if #[cfg(target_feature="avx2")] {
81        Self { avx2: bitand_m256i(self.avx2, rhs.avx2) }
82      } else {
83        Self {
84          a : self.a.bitand(rhs.a),
85          b : self.b.bitand(rhs.b),
86        }
87      }
88    }
89  }
90}
91
92impl BitOr for u32x8 {
93  type Output = Self;
94  #[inline]
95  #[must_use]
96  fn bitor(self, rhs: Self) -> Self::Output {
97    pick! {
98      if #[cfg(target_feature="avx2")] {
99        Self { avx2: bitor_m256i(self.avx2, rhs.avx2) }
100      } else {
101        Self {
102          a : self.a.bitor(rhs.a),
103          b : self.b.bitor(rhs.b),
104        }
105      }
106    }
107  }
108}
109
110impl BitXor for u32x8 {
111  type Output = Self;
112  #[inline]
113  #[must_use]
114  fn bitxor(self, rhs: Self) -> Self::Output {
115    pick! {
116      if #[cfg(target_feature="avx2")] {
117        Self { avx2: bitxor_m256i(self.avx2, rhs.avx2) }
118      } else {
119        Self {
120          a : self.a.bitxor(rhs.a),
121          b : self.b.bitxor(rhs.b),
122        }
123      }
124    }
125  }
126}
127
128macro_rules! impl_shl_t_for_u32x8 {
129  ($($shift_type:ty),+ $(,)?) => {
130    $(impl Shl<$shift_type> for u32x8 {
131      type Output = Self;
132      /// Shifts all lanes by the value given.
133      #[inline]
134      #[must_use]
135      fn shl(self, rhs: $shift_type) -> Self::Output {
136        pick! {
137          if #[cfg(target_feature="avx2")] {
138            let shift = cast([rhs as u64, 0]);
139            Self { avx2: shl_all_u32_m256i(self.avx2, shift) }
140          } else {
141            Self {
142              a : self.a.shl(rhs),
143              b : self.b.shl(rhs),
144            }
145          }
146        }
147      }
148    })+
149  };
150}
151impl_shl_t_for_u32x8!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128);
152
153macro_rules! impl_shr_t_for_u32x8 {
154  ($($shift_type:ty),+ $(,)?) => {
155    $(impl Shr<$shift_type> for u32x8 {
156      type Output = Self;
157      /// Shifts all lanes by the value given.
158      #[inline]
159      #[must_use]
160      fn shr(self, rhs: $shift_type) -> Self::Output {
161        pick! {
162          if #[cfg(target_feature="avx2")] {
163            let shift = cast([rhs as u64, 0]);
164            Self { avx2: shr_all_u32_m256i(self.avx2, shift) }
165          } else {
166            Self {
167              a : self.a.shr(rhs),
168              b : self.b.shr(rhs),
169            }
170          }
171        }
172      }
173    })+
174  };
175}
176
177impl_shr_t_for_u32x8!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128);
178
179impl u32x8 {
180  #[inline]
181  #[must_use]
182  pub fn new(array: [u32; 8]) -> Self {
183    Self::from(array)
184  }
185  #[inline]
186  #[must_use]
187  pub fn cmp_eq(self, rhs: Self) -> Self {
188    pick! {
189      if #[cfg(target_feature="avx2")] {
190        Self { avx2: cmp_eq_mask_i32_m256i(self.avx2, rhs.avx2 ) }
191      } else {
192        Self {
193          a : self.a.cmp_eq(rhs.a),
194          b : self.b.cmp_eq(rhs.b),
195        }
196      }
197    }
198  }
199  #[inline]
200  #[must_use]
201  pub fn cmp_gt(self, rhs: Self) -> Self {
202    pick! {
203      if #[cfg(target_feature="avx2")] {
204        Self { avx2: cmp_gt_mask_i32_m256i(self.avx2, rhs.avx2 ) }
205      } else {
206        Self {
207          a : self.a.cmp_gt(rhs.a),
208          b : self.b.cmp_gt(rhs.b),
209        }
210      }
211    }
212  }
213  #[inline]
214  #[must_use]
215  pub fn cmp_lt(self, rhs: Self) -> Self {
216    pick! {
217      if #[cfg(target_feature="avx2")] {
218        Self { avx2: !cmp_gt_mask_i32_m256i(self.avx2, rhs.avx2) ^ cmp_eq_mask_i32_m256i(self.avx2,rhs.avx2) }
219      } else {
220        Self {
221          a : self.a.cmp_lt(rhs.a),
222          b : self.b.cmp_lt(rhs.b),
223        }
224      }
225    }
226  }
227  #[inline]
228  #[must_use]
229  pub fn blend(self, t: Self, f: Self) -> Self {
230    pick! {
231      if #[cfg(target_feature="avx2")] {
232        Self { avx2: blend_varying_i8_m256i(f.avx2, t.avx2, self.avx2) }
233      } else {
234        Self {
235          a : self.a.blend(t.a, f.a),
236          b : self.b.blend(t.b, f.b),
237        }
238      }
239    }
240  }
241
242  #[inline]
243  #[must_use]
244  pub fn max(self, rhs: Self) -> Self {
245    pick! {
246      if #[cfg(target_feature="avx2")] {
247        Self { avx2: max_i32_m256i(self.avx2, rhs.avx2 ) }
248      } else {
249        Self {
250          a : self.a.max(rhs.a),
251          b : self.b.max(rhs.b),
252        }
253      }
254    }
255  }
256  #[inline]
257  #[must_use]
258  pub fn min(self, rhs: Self) -> Self {
259    pick! {
260      if #[cfg(target_feature="avx2")] {
261        Self { avx2: max_i32_m256i(self.avx2, rhs.avx2 ) }
262      } else {
263        Self {
264          a : self.a.min(rhs.a),
265          b : self.b.min(rhs.b),
266        }
267      }
268    }
269  }
270
271  #[inline]
272  pub fn to_array(self) -> [u32; 8] {
273    cast(self)
274  }
275
276  #[inline]
277  pub fn as_array_ref(&self) -> &[u32; 8] {
278    cast_ref(self)
279  }
280
281  #[inline]
282  pub fn as_array_mut(&mut self) -> &mut [u32; 8] {
283    cast_mut(self)
284  }
285}
286
287impl Not for u32x8 {
288  type Output = Self;
289  #[inline]
290  fn not(self) -> Self {
291    pick! {
292      if #[cfg(target_feature="avx2")] {
293        Self { avx2: self.avx2.not()  }
294      } else {
295        Self {
296          a : self.a.not(),
297          b : self.b.not(),
298        }
299      }
300    }
301  }
302}