Debian Codegraph @

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