Debian Codegraph @

debian/missing-sources/glam-0.27.0/src/bool/coresimd/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::simd::*;
8
9 #[repr(C)]
10 union UnionCast {
11 a: [u32; 4],
12 v: BVec4A,
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) mask32x4);
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 unsafe {
36 UnionCast {
37 a: [
38 MASK[x as usize],
39 MASK[y as usize],
40 MASK[z as usize],
41 MASK[w as usize],
42 ],
43 }
44 .v
45 }
46 }
47
48 /// Creates a vector mask with all elements set to `v`.
49 #[inline]
50 #[must_use]
51 pub const fn splat(v: bool) -> Self {
52 Self::new(v, v, v, v)
53 }
54
55 /// Creates a new vector mask from a bool array.
56 #[inline]
57 #[must_use]
58 pub const fn from_array(a: [bool; 4]) -> Self {
59 Self::new(a[0], a[1], a[2], a[3])
60 }
61
62 /// Returns a bitmask with the lowest 4 bits set from the elements of `self`.
63 ///
64 /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes
65 /// into the first lowest bit, element `y` into the second, etc.
66 #[inline]
67 #[must_use]
68 pub fn bitmask(self) -> u32 {
69 self.0.to_bitmask() as u32
70 }
71
72 /// Returns true if any of the elements are true, false otherwise.
73 #[inline]
74 #[must_use]
75 pub fn any(self) -> bool {
76 self.bitmask() != 0
77 }
78
79 /// Returns true if all the elements are true, false otherwise.
80 #[inline]
81 #[must_use]
82 pub fn all(self) -> bool {
83 self.bitmask() == 0xf
84 }
85
86 /// Tests the value at `index`.
87 ///
88 /// Panics if `index` is greater than 3.
89 #[inline]
90 #[must_use]
91 pub fn test(&self, index: usize) -> bool {
92 self.0.test(index)
93 }
94
95 /// Sets the element at `index`.
96 ///
97 /// Panics if `index` is greater than 3.
98 #[inline]
99 pub fn set(&mut self, index: usize, value: bool) {
100 self.0.set(index, value)
101 }
102
103 #[inline]
104 #[must_use]
105 fn into_bool_array(self) -> [bool; 4] {
106 let bitmask = self.bitmask();
107 [
108 (bitmask & 1) != 0,
109 (bitmask & 2) != 0,
110 (bitmask & 4) != 0,
111 (bitmask & 8) != 0,
112 ]
113 }
114
115 #[inline]
116 #[must_use]
117 fn into_u32_array(self) -> [u32; 4] {
118 let bitmask = self.bitmask();
119 [
120 MASK[(bitmask & 1) as usize],
121 MASK[((bitmask >> 1) & 1) as usize],
122 MASK[((bitmask >> 2) & 1) as usize],
123 MASK[((bitmask >> 3) & 1) as usize],
124 ]
125 }
126 }
127
128 impl Default for BVec4A {
129 #[inline]
130 fn default() -> Self {
131 Self::FALSE
132 }
133 }
134
135 impl PartialEq for BVec4A {
136 #[inline]
137 fn eq(&self, rhs: &Self) -> bool {
138 self.bitmask().eq(&rhs.bitmask())
139 }
140 }
141
142 impl Eq for BVec4A {}
143
144 impl core::hash::Hash for BVec4A {
145 #[inline]
146 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
147 self.bitmask().hash(state);
148 }
149 }
150
151 impl BitAnd for BVec4A {
152 type Output = Self;
153 #[inline]
154 fn bitand(self, rhs: Self) -> Self {
155 Self(self.0 & rhs.0)
156 }
157 }
158
159 impl BitAndAssign for BVec4A {
160 #[inline]
161 fn bitand_assign(&mut self, rhs: Self) {
162 *self = self.bitand(rhs);
163 }
164 }
165
166 impl BitOr for BVec4A {
167 type Output = Self;
168 #[inline]
169 fn bitor(self, rhs: Self) -> Self {
170 Self(self.0 | rhs.0)
171 }
172 }
173
174 impl BitOrAssign for BVec4A {
175 #[inline]
176 fn bitor_assign(&mut self, rhs: Self) {
177 *self = self.bitor(rhs);
178 }
179 }
180
181 impl BitXor for BVec4A {
182 type Output = Self;
183 #[inline]
184 fn bitxor(self, rhs: Self) -> Self {
185 Self(self.0 ^ rhs.0)
186 }
187 }
188
189 impl BitXorAssign for BVec4A {
190 #[inline]
191 fn bitxor_assign(&mut self, rhs: Self) {
192 *self = self.bitxor(rhs);
193 }
194 }
195
196 impl Not for BVec4A {
197 type Output = Self;
198 #[inline]
199 fn not(self) -> Self {
200 Self(!self.0)
201 }
202 }
203
204 impl From<BVec4A> for mask32x4 {
205 #[inline]
206 fn from(t: BVec4A) -> Self {
207 t.0
208 }
209 }
210
211 #[cfg(not(target_arch = "spirv"))]
212 impl fmt::Debug for BVec4A {
213 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214 let arr = self.into_u32_array();
215 write!(
216 f,
217 "{}({:#x}, {:#x}, {:#x}, {:#x})",
218 stringify!(BVec4A),
219 arr[0],
220 arr[1],
221 arr[2],
222 arr[3]
223 )
224 }
225 }
226
227 #[cfg(not(target_arch = "spirv"))]
228 impl fmt::Display for BVec4A {
229 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
230 let arr = self.into_bool_array();
231 write!(f, "[{}, {}, {}, {}]", arr[0], arr[1], arr[2], arr[3])
232 }
233 }
234
235 impl From<[bool; 4]> for BVec4A {
236 #[inline]
237 fn from(a: [bool; 4]) -> Self {
238 Self::from_array(a)
239 }
240 }
241
242 impl From<BVec4A> for [bool; 4] {
243 #[inline]
244 fn from(mask: BVec4A) -> Self {
245 mask.into_bool_array()
246 }
247 }
248
249 impl From<BVec4A> for [u32; 4] {
250 #[inline]
251 fn from(mask: BVec4A) -> Self {
252 mask.into_u32_array()
253 }
254 }