Debian Codegraph @

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