Debian Codegraph @

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