Debian Codegraph @

debian/missing-sources/glam-0.23.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 union UnionCast {
10 a: [u32; 4],
11 v: BVec4A,
12 }
13
14 /// A 4-dimensional SIMD vector mask.
15 ///
16 /// This type is 16 byte aligned and is backed by a SIMD vector. If SIMD is not available
17 /// `BVec4A` will be a type alias for `BVec4`.
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 #[inline]
75 fn into_bool_array(self) -> [bool; 4] {
76 let bitmask = self.bitmask();
77 [
78 (bitmask & 1) != 0,
79 (bitmask & 2) != 0,
80 (bitmask & 4) != 0,
81 (bitmask & 8) != 0,
82 ]
83 }
84
85 #[inline]
86 fn into_u32_array(self) -> [u32; 4] {
87 let bitmask = self.bitmask();
88 [
89 MASK[(bitmask & 1) as usize],
90 MASK[((bitmask >> 1) & 1) as usize],
91 MASK[((bitmask >> 2) & 1) as usize],
92 MASK[((bitmask >> 3) & 1) as usize],
93 ]
94 }
95 }
96
97 impl Default for BVec4A {
98 #[inline]
99 fn default() -> Self {
100 Self::FALSE
101 }
102 }
103
104 impl PartialEq for BVec4A {
105 #[inline]
106 fn eq(&self, rhs: &Self) -> bool {
107 self.bitmask().eq(&rhs.bitmask())
108 }
109 }
110
111 impl Eq for BVec4A {}
112
113 impl core::hash::Hash for BVec4A {
114 #[inline]
115 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
116 self.bitmask().hash(state);
117 }
118 }
119
120 impl BitAnd for BVec4A {
121 type Output = Self;
122 #[inline]
123 fn bitand(self, rhs: Self) -> Self {
124 Self(self.0 & rhs.0)
125 }
126 }
127
128 impl BitAndAssign for BVec4A {
129 #[inline]
130 fn bitand_assign(&mut self, rhs: Self) {
131 *self = self.bitand(rhs);
132 }
133 }
134
135 impl BitOr for BVec4A {
136 type Output = Self;
137 #[inline]
138 fn bitor(self, rhs: Self) -> Self {
139 Self(self.0 | rhs.0)
140 }
141 }
142
143 impl BitOrAssign for BVec4A {
144 #[inline]
145 fn bitor_assign(&mut self, rhs: Self) {
146 *self = self.bitor(rhs);
147 }
148 }
149
150 impl BitXor for BVec4A {
151 type Output = Self;
152 #[inline]
153 fn bitxor(self, rhs: Self) -> Self {
154 Self(self.0 ^ rhs.0)
155 }
156 }
157
158 impl BitXorAssign for BVec4A {
159 #[inline]
160 fn bitxor_assign(&mut self, rhs: Self) {
161 *self = self.bitxor(rhs);
162 }
163 }
164
165 impl Not for BVec4A {
166 type Output = Self;
167 #[inline]
168 fn not(self) -> Self {
169 Self(!self.0)
170 }
171 }
172
173 impl From<BVec4A> for mask32x4 {
174 #[inline]
175 fn from(t: BVec4A) -> Self {
176 t.0
177 }
178 }
179
180 #[cfg(not(target_arch = "spirv"))]
181 impl fmt::Debug for BVec4A {
182 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
183 let arr = self.into_u32_array();
184 write!(
185 f,
186 "{}({:#x}, {:#x}, {:#x}, {:#x})",
187 stringify!(BVec4A),
188 arr[0],
189 arr[1],
190 arr[2],
191 arr[3]
192 )
193 }
194 }
195
196 #[cfg(not(target_arch = "spirv"))]
197 impl fmt::Display for BVec4A {
198 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
199 let arr = self.into_bool_array();
200 write!(f, "[{}, {}, {}, {}]", arr[0], arr[1], arr[2], arr[3])
201 }
202 }
203
204 impl From<BVec4A> for [bool; 4] {
205 #[inline]
206 fn from(mask: BVec4A) -> Self {
207 mask.into_bool_array()
208 }
209 }
210
211 impl From<BVec4A> for [u32; 4] {
212 #[inline]
213 fn from(mask: BVec4A) -> Self {
214 mask.into_u32_array()
215 }
216 }