Debian Codegraph @

debian/missing-sources/glam-0.23.0/src/bool/sse2/bvec3a.rs

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