Debian Codegraph @

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