Debian Codegraph @

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