Debian Codegraph @

debian/missing-sources/glam/src/bool/neon/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::arch::aarch64::*;
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) uint32x4_t);
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 let movemask = unsafe {
71 let mma = vandq_u32(self.0, vld1q_u32([1, 2, 4, 8].as_ptr())); // [0 1 2 3]
72 let mmb = vextq_u32(mma, mma, 2); // [2 3 0 1]
73 let mmc = vorrq_u32(mma, mmb); // [0+2 1+3 0+2 1+3]
74 let mmd = vextq_u32(mmc, mmc, 3); // [1+3 0+2 1+3 0+2]
75 let mme = vorrq_u32(mmc, mmd); // [0+1+2+3 ...]
76 vgetq_lane_u32(mme, 0)
77 };
78
79 movemask & 0x7
80 }
81
82 /// Returns true if any of the elements are true, false otherwise.
83 #[inline]
84 #[must_use]
85 pub fn any(self) -> bool {
86 self.bitmask() != 0
87 }
88
89 /// Returns true if all the elements are true, false otherwise.
90 #[inline]
91 #[must_use]
92 pub fn all(self) -> bool {
93 self.bitmask() == 0x7
94 }
95
96 /// Tests the value at `index`.
97 ///
98 /// Panics if `index` is greater than 2.
99 #[inline]
100 #[must_use]
101 pub fn test(&self, index: usize) -> bool {
102 match index {
103 0 => (self.bitmask() & (1 << 0)) != 0,
104 1 => (self.bitmask() & (1 << 1)) != 0,
105 2 => (self.bitmask() & (1 << 2)) != 0,
106 _ => panic!("index out of bounds"),
107 }
108 }
109
110 /// Sets the element at `index`.
111 ///
112 /// Panics if `index` is greater than 2.
113 #[inline]
114 pub fn set(&mut self, index: usize, value: bool) {
115 self.0 = match index {
116 0 => unsafe { vsetq_lane_u32(MASK[value as usize], self.0, 0) },
117 1 => unsafe { vsetq_lane_u32(MASK[value as usize], self.0, 1) },
118 2 => unsafe { vsetq_lane_u32(MASK[value as usize], self.0, 2) },
119 _ => panic!("index out of bounds"),
120 }
121 }
122
123 #[inline]
124 #[must_use]
125 fn into_bool_array(self) -> [bool; 3] {
126 let bitmask = self.bitmask();
127 [(bitmask & 1) != 0, (bitmask & 2) != 0, (bitmask & 4) != 0]
128 }
129
130 #[inline]
131 #[must_use]
132 fn into_u32_array(self) -> [u32; 3] {
133 let bitmask = self.bitmask();
134 [
135 MASK[(bitmask & 1) as usize],
136 MASK[((bitmask >> 1) & 1) as usize],
137 MASK[((bitmask >> 2) & 1) as usize],
138 ]
139 }
140 }
141
142 impl Default for BVec3A {
143 #[inline]
144 fn default() -> Self {
145 Self::FALSE
146 }
147 }
148
149 impl PartialEq for BVec3A {
150 #[inline]
151 fn eq(&self, rhs: &Self) -> bool {
152 self.bitmask().eq(&rhs.bitmask())
153 }
154 }
155
156 impl Eq for BVec3A {}
157
158 impl core::hash::Hash for BVec3A {
159 #[inline]
160 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
161 self.bitmask().hash(state);
162 }
163 }
164
165 impl BitAnd for BVec3A {
166 type Output = Self;
167 #[inline]
168 fn bitand(self, rhs: Self) -> Self {
169 Self(unsafe { vandq_u32(self.0, rhs.0) })
170 }
171 }
172
173 impl BitAnd<&Self> for BVec3A {
174 type Output = Self;
175 #[inline]
176 fn bitand(self, rhs: &Self) -> Self {
177 self.bitand(*rhs)
178 }
179 }
180
181 impl BitAnd<&BVec3A> for &BVec3A {
182 type Output = BVec3A;
183 #[inline]
184 fn bitand(self, rhs: &BVec3A) -> BVec3A {
185 (*self).bitand(*rhs)
186 }
187 }
188
189 impl BitAnd<BVec3A> for &BVec3A {
190 type Output = BVec3A;
191 #[inline]
192 fn bitand(self, rhs: BVec3A) -> BVec3A {
193 (*self).bitand(rhs)
194 }
195 }
196
197 impl BitAndAssign for BVec3A {
198 #[inline]
199 fn bitand_assign(&mut self, rhs: Self) {
200 *self = self.bitand(rhs);
201 }
202 }
203
204 impl BitAndAssign<&Self> for BVec3A {
205 #[inline]
206 fn bitand_assign(&mut self, rhs: &Self) {
207 self.bitand_assign(*rhs);
208 }
209 }
210
211 impl BitOr for BVec3A {
212 type Output = Self;
213 #[inline]
214 fn bitor(self, rhs: Self) -> Self {
215 Self(unsafe { vorrq_u32(self.0, rhs.0) })
216 }
217 }
218
219 impl BitOr<&Self> for BVec3A {
220 type Output = Self;
221 #[inline]
222 fn bitor(self, rhs: &Self) -> Self {
223 self.bitor(*rhs)
224 }
225 }
226
227 impl BitOr<&BVec3A> for &BVec3A {
228 type Output = BVec3A;
229 #[inline]
230 fn bitor(self, rhs: &BVec3A) -> BVec3A {
231 (*self).bitor(*rhs)
232 }
233 }
234
235 impl BitOr<BVec3A> for &BVec3A {
236 type Output = BVec3A;
237 #[inline]
238 fn bitor(self, rhs: BVec3A) -> BVec3A {
239 (*self).bitor(rhs)
240 }
241 }
242
243 impl BitOrAssign for BVec3A {
244 #[inline]
245 fn bitor_assign(&mut self, rhs: Self) {
246 *self = self.bitor(rhs);
247 }
248 }
249
250 impl BitOrAssign<&Self> for BVec3A {
251 #[inline]
252 fn bitor_assign(&mut self, rhs: &Self) {
253 self.bitor_assign(*rhs);
254 }
255 }
256
257 impl BitXor for BVec3A {
258 type Output = Self;
259 #[inline]
260 fn bitxor(self, rhs: Self) -> Self {
261 Self(unsafe { veorq_u32(self.0, rhs.0) })
262 }
263 }
264
265 impl BitXor<&Self> for BVec3A {
266 type Output = Self;
267 #[inline]
268 fn bitxor(self, rhs: &Self) -> Self {
269 self.bitxor(*rhs)
270 }
271 }
272
273 impl BitXor<&BVec3A> for &BVec3A {
274 type Output = BVec3A;
275 #[inline]
276 fn bitxor(self, rhs: &BVec3A) -> BVec3A {
277 (*self).bitxor(*rhs)
278 }
279 }
280
281 impl BitXor<BVec3A> for &BVec3A {
282 type Output = BVec3A;
283 #[inline]
284 fn bitxor(self, rhs: BVec3A) -> BVec3A {
285 (*self).bitxor(rhs)
286 }
287 }
288
289 impl BitXorAssign for BVec3A {
290 #[inline]
291 fn bitxor_assign(&mut self, rhs: Self) {
292 *self = self.bitxor(rhs);
293 }
294 }
295
296 impl BitXorAssign<&Self> for BVec3A {
297 #[inline]
298 fn bitxor_assign(&mut self, rhs: &Self) {
299 self.bitxor_assign(*rhs);
300 }
301 }
302
303 impl Not for BVec3A {
304 type Output = Self;
305 #[inline]
306 fn not(self) -> Self {
307 Self(unsafe { vmvnq_u32(self.0) })
308 }
309 }
310
311 impl Not for &BVec3A {
312 type Output = BVec3A;
313 #[inline]
314 fn not(self) -> BVec3A {
315 (*self).not()
316 }
317 }
318
319 impl From<BVec3A> for uint32x4_t {
320 #[inline]
321 fn from(t: BVec3A) -> Self {
322 t.0
323 }
324 }
325
326 impl fmt::Debug for BVec3A {
327 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
328 let arr = self.into_u32_array();
329 write!(
330 f,
331 "{}({:#x}, {:#x}, {:#x})",
332 stringify!(BVec3A),
333 arr[0],
334 arr[1],
335 arr[2]
336 )
337 }
338 }
339
340 impl fmt::Display for BVec3A {
341 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
342 let arr = self.into_bool_array();
343 write!(f, "[{}, {}, {}]", arr[0], arr[1], arr[2])
344 }
345 }
346
347 impl From<[bool; 3]> for BVec3A {
348 #[inline]
349 fn from(a: [bool; 3]) -> Self {
350 Self::from_array(a)
351 }
352 }
353
354 impl From<BVec3A> for [bool; 3] {
355 #[inline]
356 fn from(mask: BVec3A) -> Self {
357 mask.into_bool_array()
358 }
359 }
360
361 impl From<BVec3A> for [u32; 3] {
362 #[inline]
363 fn from(mask: BVec3A) -> Self {
364 mask.into_u32_array()
365 }
366 }