Debian Codegraph @

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