Debian Codegraph @

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