Debian Codegraph @

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