Debian Codegraph @

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