Debian Codegraph @

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