Debian Codegraph @

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