Debian Codegraph @

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