| 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 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 |
const FALSE: BVec3A = BVec3A::new(false, false, false); |
| 20 |
|
| 21 |
impl BVec3A { |
| 22 |
/// Creates a new vector mask. |
| 23 |
#[inline(always)] |
| 24 |
pub const fn new(x: bool, y: bool, z: bool) -> Self { |
| 25 |
Self(u32x4( |
| 26 |
MASK[x as usize], |
| 27 |
MASK[y as usize], |
| 28 |
MASK[z as usize], |
| 29 |
0, |
| 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) & 0x7) 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() == 0x7 |
| 52 |
} |
| 53 |
|
| 54 |
#[inline] |
| 55 |
fn into_bool_array(self) -> [bool; 3] { |
| 56 |
let bitmask = self.bitmask(); |
| 57 |
[(bitmask & 1) != 0, (bitmask & 2) != 0, (bitmask & 4) != 0] |
| 58 |
} |
| 59 |
|
| 60 |
#[inline] |
| 61 |
fn into_u32_array(self) -> [u32; 3] { |
| 62 |
let bitmask = self.bitmask(); |
| 63 |
[ |
| 64 |
MASK[(bitmask & 1) as usize], |
| 65 |
MASK[((bitmask >> 1) & 1) as usize], |
| 66 |
MASK[((bitmask >> 2) & 1) as usize], |
| 67 |
] |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
impl Default for BVec3A { |
| 72 |
#[inline] |
| 73 |
fn default() -> Self { |
| 74 |
FALSE |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
impl PartialEq for BVec3A { |
| 79 |
#[inline] |
| 80 |
fn eq(&self, rhs: &Self) -> bool { |
| 81 |
self.bitmask().eq(&rhs.bitmask()) |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
impl Eq for BVec3A {} |
| 86 |
|
| 87 |
impl hash::Hash for BVec3A { |
| 88 |
#[inline] |
| 89 |
fn hash<H: hash::Hasher>(&self, state: &mut H) { |
| 90 |
self.bitmask().hash(state); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
impl BitAnd for BVec3A { |
| 95 |
type Output = Self; |
| 96 |
#[inline] |
| 97 |
fn bitand(self, rhs: Self) -> Self { |
| 98 |
Self(v128_and(self.0, rhs.0)) |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
impl BitAndAssign for BVec3A { |
| 103 |
#[inline] |
| 104 |
fn bitand_assign(&mut self, rhs: Self) { |
| 105 |
*self = self.bitand(rhs); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
impl BitOr for BVec3A { |
| 110 |
type Output = Self; |
| 111 |
#[inline] |
| 112 |
fn bitor(self, rhs: Self) -> Self { |
| 113 |
Self(v128_or(self.0, rhs.0)) |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
impl BitOrAssign for BVec3A { |
| 118 |
#[inline] |
| 119 |
fn bitor_assign(&mut self, rhs: Self) { |
| 120 |
*self = self.bitor(rhs); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
impl BitXor for BVec3A { |
| 125 |
type Output = Self; |
| 126 |
#[inline] |
| 127 |
fn bitxor(self, rhs: Self) -> Self { |
| 128 |
Self(v128_xor(self.0, rhs.0)) |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
impl BitXorAssign for BVec3A { |
| 133 |
#[inline] |
| 134 |
fn bitxor_assign(&mut self, rhs: Self) { |
| 135 |
*self = self.bitxor(rhs); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
impl Not for BVec3A { |
| 140 |
type Output = Self; |
| 141 |
#[inline] |
| 142 |
fn not(self) -> Self { |
| 143 |
Self(v128_not(self.0)) |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
impl From<BVec3A> for v128 { |
| 148 |
#[inline] |
| 149 |
fn from(t: BVec3A) -> Self { |
| 150 |
t.0 |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
#[cfg(not(target_arch = "spirv"))] |
| 155 |
impl fmt::Debug for BVec3A { |
| 156 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 157 |
let arr = self.into_u32_array(); |
| 158 |
write!( |
| 159 |
f, |
| 160 |
"{}({:#x}, {:#x}, {:#x})", |
| 161 |
stringify!(BVec3A), |
| 162 |
arr[0], |
| 163 |
arr[1], |
| 164 |
arr[2] |
| 165 |
) |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
#[cfg(not(target_arch = "spirv"))] |
| 170 |
impl fmt::Display for BVec3A { |
| 171 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 172 |
let arr = self.into_bool_array(); |
| 173 |
write!(f, "[{}, {}, {}]", arr[0], arr[1], arr[2]) |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
impl From<BVec3A> for [bool; 3] { |
| 178 |
#[inline] |
| 179 |
fn from(mask: BVec3A) -> Self { |
| 180 |
mask.into_bool_array() |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
impl From<BVec3A> for [u32; 3] { |
| 185 |
#[inline] |
| 186 |
fn from(mask: BVec3A) -> Self { |
| 187 |
mask.into_u32_array() |
| 188 |
} |
| 189 |
} |