Debian Codegraph @

debian/missing-sources/glam-0.22.0/src/bool/wasm32/bvec4a.rs

raw
1 // Generated from vec_mask.rs.tera template. Edit the template, not the generated file.
2
3 #[cfg(not(target_arch = "spirv"))]
4 use core::fmt;
5 use core::ops::*;
6
7 use core::arch::wasm32::*;
8
9 /// A 4-dimensional SIMD vector mask.
10 ///
11 /// This type is 16 byte aligned and is backed by a SIMD vector. If SIMD is not available
12 /// `BVec4A` will be a type alias for `BVec4`.
13 #[derive(Clone, Copy)]
14 #[repr(transparent)]
15 pub struct BVec4A(pub(crate) v128);
16
17 const MASK: [u32; 2] = [0, 0xff_ff_ff_ff];
18
19 impl BVec4A {
20 /// All false.
21 pub const FALSE: Self = Self::splat(false);
22
23 /// All true.
24 pub const TRUE: Self = Self::splat(true);
25
26 /// Creates a new vector mask.
27 #[inline(always)]
28 pub const fn new(x: bool, y: bool, z: bool, w: bool) -> Self {
29 Self(u32x4(
30 MASK[x as usize],
31 MASK[y as usize],
32 MASK[z as usize],
33 MASK[w as usize],
34 ))
35 }
36
37 /// Creates a vector with all elements set to `v`.
38 #[inline]
39 pub const fn splat(v: bool) -> Self {
40 Self::new(v, v, v, v)
41 }
42
43 /// Returns a bitmask with the lowest 4 bits set from the elements of `self`.
44 ///
45 /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes
46 /// into the first lowest bit, element `y` into the second, etc.
47 #[inline]
48 pub fn bitmask(self) -> u32 {
49 u32x4_bitmask(self.0) as u32
50 }
51
52 /// Returns true if any of the elements are true, false otherwise.
53 #[inline]
54 pub fn any(self) -> bool {
55 self.bitmask() != 0
56 }
57
58 /// Returns true if all the elements are true, false otherwise.
59 #[inline]
60 pub fn all(self) -> bool {
61 self.bitmask() == 0xf
62 }
63
64 #[inline]
65 fn into_bool_array(self) -> [bool; 4] {
66 let bitmask = self.bitmask();
67 [
68 (bitmask & 1) != 0,
69 (bitmask & 2) != 0,
70 (bitmask & 4) != 0,
71 (bitmask & 8) != 0,
72 ]
73 }
74
75 #[inline]
76 fn into_u32_array(self) -> [u32; 4] {
77 let bitmask = self.bitmask();
78 [
79 MASK[(bitmask & 1) as usize],
80 MASK[((bitmask >> 1) & 1) as usize],
81 MASK[((bitmask >> 2) & 1) as usize],
82 MASK[((bitmask >> 3) & 1) as usize],
83 ]
84 }
85 }
86
87 impl Default for BVec4A {
88 #[inline]
89 fn default() -> Self {
90 Self::FALSE
91 }
92 }
93
94 impl PartialEq for BVec4A {
95 #[inline]
96 fn eq(&self, rhs: &Self) -> bool {
97 self.bitmask().eq(&rhs.bitmask())
98 }
99 }
100
101 impl Eq for BVec4A {}
102
103 impl core::hash::Hash for BVec4A {
104 #[inline]
105 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
106 self.bitmask().hash(state);
107 }
108 }
109
110 impl BitAnd for BVec4A {
111 type Output = Self;
112 #[inline]
113 fn bitand(self, rhs: Self) -> Self {
114 Self(v128_and(self.0, rhs.0))
115 }
116 }
117
118 impl BitAndAssign for BVec4A {
119 #[inline]
120 fn bitand_assign(&mut self, rhs: Self) {
121 *self = self.bitand(rhs);
122 }
123 }
124
125 impl BitOr for BVec4A {
126 type Output = Self;
127 #[inline]
128 fn bitor(self, rhs: Self) -> Self {
129 Self(v128_or(self.0, rhs.0))
130 }
131 }
132
133 impl BitOrAssign for BVec4A {
134 #[inline]
135 fn bitor_assign(&mut self, rhs: Self) {
136 *self = self.bitor(rhs);
137 }
138 }
139
140 impl BitXor for BVec4A {
141 type Output = Self;
142 #[inline]
143 fn bitxor(self, rhs: Self) -> Self {
144 Self(v128_xor(self.0, rhs.0))
145 }
146 }
147
148 impl BitXorAssign for BVec4A {
149 #[inline]
150 fn bitxor_assign(&mut self, rhs: Self) {
151 *self = self.bitxor(rhs);
152 }
153 }
154
155 impl Not for BVec4A {
156 type Output = Self;
157 #[inline]
158 fn not(self) -> Self {
159 Self(v128_not(self.0))
160 }
161 }
162
163 impl From<BVec4A> for v128 {
164 #[inline]
165 fn from(t: BVec4A) -> Self {
166 t.0
167 }
168 }
169
170 #[cfg(not(target_arch = "spirv"))]
171 impl fmt::Debug for BVec4A {
172 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
173 let arr = self.into_u32_array();
174 write!(
175 f,
176 "{}({:#x}, {:#x}, {:#x}, {:#x})",
177 stringify!(BVec4A),
178 arr[0],
179 arr[1],
180 arr[2],
181 arr[3]
182 )
183 }
184 }
185
186 #[cfg(not(target_arch = "spirv"))]
187 impl fmt::Display for BVec4A {
188 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
189 let arr = self.into_bool_array();
190 write!(f, "[{}, {}, {}, {}]", arr[0], arr[1], arr[2], arr[3])
191 }
192 }
193
194 impl From<BVec4A> for [bool; 4] {
195 #[inline]
196 fn from(mask: BVec4A) -> Self {
197 mask.into_bool_array()
198 }
199 }
200
201 impl From<BVec4A> for [u32; 4] {
202 #[inline]
203 fn from(mask: BVec4A) -> Self {
204 mask.into_u32_array()
205 }
206 }