Skip to content

Commit 78a8d61

Browse files
committed
Implement missing traits on opaque masks, fix tests
1 parent 5bc5d7f commit 78a8d61

File tree

9 files changed

+233
-86
lines changed

9 files changed

+233
-86
lines changed

crates/core_simd/src/masks/mod.rs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,136 @@ macro_rules! define_opaque_mask {
158158
self.0.partial_cmp(&other.0)
159159
}
160160
}
161+
162+
impl core::fmt::Debug for $name {
163+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
164+
f.debug_list()
165+
.entries((0..$lanes).map(|i| self.test(i)))
166+
.finish()
167+
}
168+
}
169+
170+
impl core::ops::BitAnd for $name {
171+
type Output = Self;
172+
#[inline]
173+
fn bitand(self, rhs: Self) -> Self {
174+
Self(self.0 & rhs.0)
175+
}
176+
}
177+
178+
impl core::ops::BitAnd<bool> for $name {
179+
type Output = Self;
180+
#[inline]
181+
fn bitand(self, rhs: bool) -> Self {
182+
self & Self::splat(rhs)
183+
}
184+
}
185+
186+
impl core::ops::BitAnd<$name> for bool {
187+
type Output = $name;
188+
#[inline]
189+
fn bitand(self, rhs: $name) -> $name {
190+
$name::splat(self) & rhs
191+
}
192+
}
193+
194+
impl core::ops::BitOr for $name {
195+
type Output = Self;
196+
#[inline]
197+
fn bitor(self, rhs: Self) -> Self {
198+
Self(self.0 | rhs.0)
199+
}
200+
}
201+
202+
impl core::ops::BitOr<bool> for $name {
203+
type Output = Self;
204+
#[inline]
205+
fn bitor(self, rhs: bool) -> Self {
206+
self | Self::splat(rhs)
207+
}
208+
}
209+
210+
impl core::ops::BitOr<$name> for bool {
211+
type Output = $name;
212+
#[inline]
213+
fn bitor(self, rhs: $name) -> $name {
214+
$name::splat(self) | rhs
215+
}
216+
}
217+
218+
impl core::ops::BitXor for $name {
219+
type Output = Self;
220+
#[inline]
221+
fn bitxor(self, rhs: Self) -> Self::Output {
222+
Self(self.0 ^ rhs.0)
223+
}
224+
}
225+
226+
impl core::ops::BitXor<bool> for $name {
227+
type Output = Self;
228+
#[inline]
229+
fn bitxor(self, rhs: bool) -> Self::Output {
230+
self ^ Self::splat(rhs)
231+
}
232+
}
233+
234+
impl core::ops::BitXor<$name> for bool {
235+
type Output = $name;
236+
#[inline]
237+
fn bitxor(self, rhs: $name) -> Self::Output {
238+
$name::splat(self) ^ rhs
239+
}
240+
}
241+
242+
impl core::ops::Not for $name {
243+
type Output = $name;
244+
#[inline]
245+
fn not(self) -> Self::Output {
246+
Self(!self.0)
247+
}
248+
}
249+
250+
impl core::ops::BitAndAssign for $name {
251+
#[inline]
252+
fn bitand_assign(&mut self, rhs: Self) {
253+
self.0 &= rhs.0;
254+
}
255+
}
256+
257+
impl core::ops::BitAndAssign<bool> for $name {
258+
#[inline]
259+
fn bitand_assign(&mut self, rhs: bool) {
260+
*self &= Self::splat(rhs);
261+
}
262+
}
263+
264+
impl core::ops::BitOrAssign for $name {
265+
#[inline]
266+
fn bitor_assign(&mut self, rhs: Self) {
267+
self.0 |= rhs.0;
268+
}
269+
}
270+
271+
impl core::ops::BitOrAssign<bool> for $name {
272+
#[inline]
273+
fn bitor_assign(&mut self, rhs: bool) {
274+
*self |= Self::splat(rhs);
275+
}
276+
}
277+
278+
impl core::ops::BitXorAssign for $name {
279+
#[inline]
280+
fn bitxor_assign(&mut self, rhs: Self) {
281+
self.0 ^= rhs.0;
282+
}
283+
}
284+
285+
impl core::ops::BitXorAssign<bool> for $name {
286+
#[inline]
287+
fn bitxor_assign(&mut self, rhs: bool) {
288+
*self ^= Self::splat(rhs);
289+
}
290+
}
161291
};
162292
{ new [$width:ty; $lanes:tt] $($var:ident)* } => {
163293
/// Construct a vector by setting each lane to the given values.

crates/core_simd/tests/helpers/biteq.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ impl_biteq! {
7070
integer impl BitEq for
7171
u8, u16, u32, u64, u128, usize,
7272
i8, i16, i32, i64, i128, isize,
73-
core_simd::mask8, core_simd::mask16, core_simd::mask32, core_simd::mask64, core_simd::mask128, core_simd::masksize,
73+
core_simd::masks::wide::m8,
74+
core_simd::masks::wide::m16,
75+
core_simd::masks::wide::m32,
76+
core_simd::masks::wide::m64,
77+
core_simd::masks::wide::m128,
78+
core_simd::masks::wide::msize,
7479
}
7580

7681
impl_biteq! {
@@ -93,12 +98,12 @@ impl_biteq! {
9398
core_simd::isizex2, core_simd::isizex4, core_simd::isizex8,
9499
core_simd::f32x2, core_simd::f32x4, core_simd::f32x8, core_simd::f32x16,
95100
core_simd::f64x2, core_simd::f64x4, core_simd::f64x8,
96-
core_simd::mask8x8, core_simd::mask8x16, core_simd::mask8x32, core_simd::mask8x64,
97-
core_simd::mask16x4, core_simd::mask16x8, core_simd::mask16x16, core_simd::mask16x32,
98-
core_simd::mask32x2, core_simd::mask32x4, core_simd::mask32x8, core_simd::mask32x16,
99-
core_simd::mask64x2, core_simd::mask64x4, core_simd::mask64x8,
100-
core_simd::mask128x2, core_simd::mask128x4,
101-
core_simd::masksizex2, core_simd::masksizex4, core_simd::masksizex8,
101+
core_simd::masks::wide::m8x8, core_simd::masks::wide::m8x16, core_simd::masks::wide::m8x32, core_simd::masks::wide::m8x64,
102+
core_simd::masks::wide::m16x4, core_simd::masks::wide::m16x8, core_simd::masks::wide::m16x16, core_simd::masks::wide::m16x32,
103+
core_simd::masks::wide::m32x2, core_simd::masks::wide::m32x4, core_simd::masks::wide::m32x8, core_simd::masks::wide::m32x16,
104+
core_simd::masks::wide::m64x2, core_simd::masks::wide::m64x4, core_simd::masks::wide::m64x8,
105+
core_simd::masks::wide::m128x2, core_simd::masks::wide::m128x4,
106+
core_simd::masks::wide::msizex2, core_simd::masks::wide::msizex4, core_simd::masks::wide::msizex8,
102107
}
103108

104109
pub(crate) struct BitEqWrapper<'a, T>(pub(crate) &'a T);
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
use super::helpers;
2-
3-
mask_tests! { mask128x2, mask128 }
4-
mask_tests! { mask128x4, mask128 }
1+
mask_tests! { mask128x2, 2 }
2+
mask_tests! { mask128x4, 4 }
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use super::helpers;
2-
3-
mask_tests! { mask16x4, mask16 }
4-
mask_tests! { mask16x8, mask16 }
5-
mask_tests! { mask16x16, mask16 }
6-
mask_tests! { mask16x32, mask16 }
1+
mask_tests! { mask16x4, 4 }
2+
mask_tests! { mask16x8, 8 }
3+
mask_tests! { mask16x16, 16 }
4+
mask_tests! { mask16x32, 32 }
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use super::helpers;
2-
3-
mask_tests! { mask32x2, mask32 }
4-
mask_tests! { mask32x4, mask32 }
5-
mask_tests! { mask32x8, mask32 }
6-
mask_tests! { mask32x16, mask32 }
1+
mask_tests! { mask32x2, 2 }
2+
mask_tests! { mask32x4, 4 }
3+
mask_tests! { mask32x8, 8 }
4+
mask_tests! { mask32x16, 16 }
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use super::helpers;
2-
3-
mask_tests! { mask64x2, mask64 }
4-
mask_tests! { mask64x4, mask64 }
5-
mask_tests! { mask64x8, mask64 }
1+
mask_tests! { mask64x2, 2 }
2+
mask_tests! { mask64x4, 4 }
3+
mask_tests! { mask64x8, 8 }
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use super::helpers;
2-
3-
mask_tests! { mask8x8, mask8 }
4-
mask_tests! { mask8x16, mask8 }
5-
mask_tests! { mask8x32, mask8 }
6-
mask_tests! { mask8x64, mask8 }
1+
mask_tests! { mask8x8, 8 }
2+
mask_tests! { mask8x16, 16 }
3+
mask_tests! { mask8x32, 32 }
4+
mask_tests! { mask8x64, 64 }

0 commit comments

Comments
 (0)