Debian Codegraph @

debian/missing-sources/glam/src/bool/coresimd/bvec4a.rs

raw
1 // Generated from vec_mask.rs.tera template. Edit the template, not the generated file.
2
3 use core::fmt;
4 use core::ops::*;
5
6 use core::simd::*;
7
8 #[repr(C)]
9 union UnionCast {
10 a: [u32; 4],
11 v: BVec4A,
12 }
13
14 /// Creates a 4-dimensional `bool` vector mask.
15 #[inline(always)]
16 #[must_use]
17 pub const fn bvec4a(x: bool, y: bool, z: bool, w: bool) -> BVec4A {
18 BVec4A::new(x, y, z, w)
19 }
20
21 /// A 4-dimensional SIMD vector mask.
22 ///
23 /// This type is 16 byte aligned.
24 #[derive(Clone, Copy)]
25 #[repr(transparent)]
26 pub struct BVec4A(pub(crate) mask32x4);
27
28 const MASK: [u32; 2] = [0, 0xff_ff_ff_ff];
29
30 impl BVec4A {
31 /// All false.
32 pub const FALSE: Self = Self::splat(false);
33
34 /// All true.
35 pub const TRUE: Self = Self::splat(true);
36
37 /// Creates a new vector mask.
38 #[inline(always)]
39 #[must_use]
40 pub const fn new(x: bool, y: bool, z: bool, w: bool) -> Self {
41 unsafe {
42 UnionCast {
43 a: [
44 MASK[x as usize],
45 MASK[y as usize],
46 MASK[z as usize],
47 MASK[w as usize],
48 ],
49 }
50 .v
51 }
52 }
53
54 /// Creates a vector mask with all elements set to `v`.
55 #[inline]
56 #[must_use]
57 pub const fn splat(v: bool) -> Self {
58 Self::new(v, v, v, v)
59 }
60
61 /// Creates a new vector mask from a bool array.
62 #[inline]
63 #[must_use]
64 pub const fn from_array(a: [bool; 4]) -> Self {
65 Self::new(a[0], a[1], a[2], a[3])
66 }
67
68 /// Returns a bitmask with the lowest 4 bits set from the elements of `self`.
69 ///
70 /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes
71 /// into the first lowest bit, element `y` into the second, etc.
72 #[inline]
73 #[must_use]
74 pub fn bitmask(self) -> u32 {
75 self.0.to_bitmask() as u32
76 }
77
78 /// Returns true if any of the elements are true, false otherwise.
79 #[inline]
80 #[must_use]
81 pub fn any(self) -> bool {
82 self.bitmask() != 0
83 }
84
85 /// Returns true if all the elements are true, false otherwise.
86 #[inline]
87 #[must_use]
88 pub fn all(self) -> bool {
89 self.bitmask() == 0xf
90 }
91
92 /// Tests the value at `index`.
93 ///
94 /// Panics if `index` is greater than 3.
95 #[inline]
96 #[must_use]
97 pub fn test(&self, index: usize) -> bool {
98 assert!(index < 4, "index out of bounds");
99 self.0.test(index)
100 }
101
102 /// Sets the element at `index`.
103 ///
104 /// Panics if `index` is greater than 3.
105 #[inline]
106 pub fn set(&mut self, index: usize, value: bool) {
107 self.0.set(index, value)
108 }
109
110 #[inline]
111 #[must_use]
112 fn into_bool_array(self) -> [bool; 4] {
113 let bitmask = self.bitmask();
114 [
115 (bitmask & 1) != 0,
116 (bitmask & 2) != 0,
117 (bitmask & 4) != 0,
118 (bitmask & 8) != 0,
119 ]
120 }
121
122 #[inline]
123 #[must_use]
124 fn into_u32_array(self) -> [u32; 4] {
125 let bitmask = self.bitmask();
126 [
127 MASK[(bitmask & 1) as usize],
128 MASK[((bitmask >> 1) & 1) as usize],
129 MASK[((bitmask >> 2) & 1) as usize],
130 MASK[((bitmask >> 3) & 1) as usize],
131 ]
132 }
133 }
134
135 impl Default for BVec4A {
136 #[inline]
137 fn default() -> Self {
138 Self::FALSE
139 }
140 }
141
142 impl PartialEq for BVec4A {
143 #[inline]
144 fn eq(&self, rhs: &Self) -> bool {
145 self.bitmask().eq(&rhs.bitmask())
146 }
147 }
148
149 impl Eq for BVec4A {}
150
151 impl core::hash::Hash for BVec4A {
152 #[inline]
153 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
154 self.bitmask().hash(state);
155 }
156 }
157
158 impl BitAnd for BVec4A {
159 type Output = Self;
160 #[inline]
161 fn bitand(self, rhs: Self) -> Self {
162 Self(self.0 & rhs.0)
163 }
164 }
165
166 impl BitAnd<&Self> for BVec4A {
167 type Output = Self;
168 #[inline]
169 fn bitand(self, rhs: &Self) -> Self {
170 self.bitand(*rhs)
171 }
172 }
173
174 impl BitAnd<&BVec4A> for &BVec4A {
175 type Output = BVec4A;
176 #[inline]
177 fn bitand(self, rhs: &BVec4A) -> BVec4A {
178 (*self).bitand(*rhs)
179 }
180 }
181
182 impl BitAnd<BVec4A> for &BVec4A {
183 type Output = BVec4A;
184 #[inline]
185 fn bitand(self, rhs: BVec4A) -> BVec4A {
186 (*self).bitand(rhs)
187 }
188 }
189
190 impl BitAndAssign for BVec4A {
191 #[inline]
192 fn bitand_assign(&mut self, rhs: Self) {
193 *self = self.bitand(rhs);
194 }
195 }
196
197 impl BitAndAssign<&Self> for BVec4A {
198 #[inline]
199 fn bitand_assign(&mut self, rhs: &Self) {
200 self.bitand_assign(*rhs);
201 }
202 }
203
204 impl BitOr for BVec4A {
205 type Output = Self;
206 #[inline]
207 fn bitor(self, rhs: Self) -> Self {
208 Self(self.0 | rhs.0)
209 }
210 }
211
212 impl BitOr<&Self> for BVec4A {
213 type Output = Self;
214 #[inline]
215 fn bitor(self, rhs: &Self) -> Self {
216 self.bitor(*rhs)
217 }
218 }
219
220 impl BitOr<&BVec4A> for &BVec4A {
221 type Output = BVec4A;
222 #[inline]
223 fn bitor(self, rhs: &BVec4A) -> BVec4A {
224 (*self).bitor(*rhs)
225 }
226 }
227
228 impl BitOr<BVec4A> for &BVec4A {
229 type Output = BVec4A;
230 #[inline]
231 fn bitor(self, rhs: BVec4A) -> BVec4A {
232 (*self).bitor(rhs)
233 }
234 }
235
236 impl BitOrAssign for BVec4A {
237 #[inline]
238 fn bitor_assign(&mut self, rhs: Self) {
239 *self = self.bitor(rhs);
240 }
241 }
242
243 impl BitOrAssign<&Self> for BVec4A {
244 #[inline]
245 fn bitor_assign(&mut self, rhs: &Self) {
246 self.bitor_assign(*rhs);
247 }
248 }
249
250 impl BitXor for BVec4A {
251 type Output = Self;
252 #[inline]
253 fn bitxor(self, rhs: Self) -> Self {
254 Self(self.0 ^ rhs.0)
255 }
256 }
257
258 impl BitXor<&Self> for BVec4A {
259 type Output = Self;
260 #[inline]
261 fn bitxor(self, rhs: &Self) -> Self {
262 self.bitxor(*rhs)
263 }
264 }
265
266 impl BitXor<&BVec4A> for &BVec4A {
267 type Output = BVec4A;
268 #[inline]
269 fn bitxor(self, rhs: &BVec4A) -> BVec4A {
270 (*self).bitxor(*rhs)
271 }
272 }
273
274 impl BitXor<BVec4A> for &BVec4A {
275 type Output = BVec4A;
276 #[inline]
277 fn bitxor(self, rhs: BVec4A) -> BVec4A {
278 (*self).bitxor(rhs)
279 }
280 }
281
282 impl BitXorAssign for BVec4A {
283 #[inline]
284 fn bitxor_assign(&mut self, rhs: Self) {
285 *self = self.bitxor(rhs);
286 }
287 }
288
289 impl BitXorAssign<&Self> for BVec4A {
290 #[inline]
291 fn bitxor_assign(&mut self, rhs: &Self) {
292 self.bitxor_assign(*rhs);
293 }
294 }
295
296 impl Not for BVec4A {
297 type Output = Self;
298 #[inline]
299 fn not(self) -> Self {
300 Self(!self.0)
301 }
302 }
303
304 impl Not for &BVec4A {
305 type Output = BVec4A;
306 #[inline]
307 fn not(self) -> BVec4A {
308 (*self).not()
309 }
310 }
311
312 impl From<BVec4A> for mask32x4 {
313 #[inline]
314 fn from(t: BVec4A) -> Self {
315 t.0
316 }
317 }
318
319 impl fmt::Debug for BVec4A {
320 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
321 let arr = self.into_u32_array();
322 write!(
323 f,
324 "{}({:#x}, {:#x}, {:#x}, {:#x})",
325 stringify!(BVec4A),
326 arr[0],
327 arr[1],
328 arr[2],
329 arr[3]
330 )
331 }
332 }
333
334 impl fmt::Display for BVec4A {
335 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
336 let arr = self.into_bool_array();
337 write!(f, "[{}, {}, {}, {}]", arr[0], arr[1], arr[2], arr[3])
338 }
339 }
340
341 impl From<[bool; 4]> for BVec4A {
342 #[inline]
343 fn from(a: [bool; 4]) -> Self {
344 Self::from_array(a)
345 }
346 }
347
348 impl From<BVec4A> for [bool; 4] {
349 #[inline]
350 fn from(mask: BVec4A) -> Self {
351 mask.into_bool_array()
352 }
353 }
354
355 impl From<BVec4A> for [u32; 4] {
356 #[inline]
357 fn from(mask: BVec4A) -> Self {
358 mask.into_u32_array()
359 }
360 }