Skip to content

Commit 13fcf47

Browse files
committed
Implement simd_select_bitmask
1 parent 782b5fe commit 13fcf47

File tree

2 files changed

+28
-65
lines changed

2 files changed

+28
-65
lines changed

patches/0001-portable-simd-Disable-unsupported-tests.patch

-64
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,6 @@ Subject: [PATCH] Disable unsupported tests
1111
crates/core_simd/tests/masks.rs | 3 ---
1212
5 files changed, 20 insertions(+), 3 deletions(-)
1313

14-
diff --git a/crates/core_simd/src/masks/full_masks.rs b/crates/core_simd/src/masks/full_masks.rs
15-
index adf0fcb..e7e657e 100644
16-
--- a/crates/core_simd/src/masks/full_masks.rs
17-
+++ b/crates/core_simd/src/masks/full_masks.rs
18-
@@ -180,6 +180,7 @@ where
19-
super::Mask<T, LANES>: ToBitMaskArray,
20-
[(); <super::Mask<T, LANES> as ToBitMaskArray>::BYTES]: Sized,
21-
{
22-
+ /*
23-
assert_eq!(<super::Mask<T, LANES> as ToBitMaskArray>::BYTES, N);
24-
25-
// Safety: N is the correct bitmask size
26-
@@ -202,6 +203,8 @@ where
27-
Self::splat(false).to_int(),
28-
))
29-
}
30-
+ */
31-
+ panic!();
32-
}
33-
34-
#[inline]
35-
@@ -225,6 +228,7 @@ where
36-
where
37-
super::Mask<T, LANES>: ToBitMask<BitMask = U>,
38-
{
39-
+ /*
40-
// LLVM assumes bit order should match endianness
41-
let bitmask = if cfg!(target_endian = "big") {
42-
bitmask.reverse_bits(LANES)
43-
@@ -240,6 +244,8 @@ where
44-
Self::splat(false).to_int(),
45-
))
46-
}
47-
+ */
48-
+ panic!();
49-
}
50-
51-
#[inline]
5214
diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs
5315
index e8e8f68..7173c24 100644
5416
--- a/crates/core_simd/src/vector.rs
@@ -69,31 +31,5 @@ index e8e8f68..7173c24 100644
6931
}
7032

7133
impl<T, const LANES: usize> Copy for Simd<T, LANES>
72-
diff --git a/crates/core_simd/tests/masks.rs b/crates/core_simd/tests/masks.rs
73-
index 673d0db..3ebfcd1 100644
74-
--- a/crates/core_simd/tests/masks.rs
75-
+++ b/crates/core_simd/tests/masks.rs
76-
@@ -78,7 +78,6 @@ macro_rules! test_mask_api {
77-
let mask = core_simd::Mask::<$type, 16>::from_array(values);
78-
let bitmask = mask.to_bitmask();
79-
assert_eq!(bitmask, 0b1000001101001001);
80-
- assert_eq!(core_simd::Mask::<$type, 16>::from_bitmask(bitmask), mask);
81-
}
82-
83-
#[test]
84-
@@ -91,13 +90,11 @@ macro_rules! test_mask_api {
85-
let mask = core_simd::Mask::<$type, 4>::from_array(values);
86-
let bitmask = mask.to_bitmask();
87-
assert_eq!(bitmask, 0b1000);
88-
- assert_eq!(core_simd::Mask::<$type, 4>::from_bitmask(bitmask), mask);
89-
90-
let values = [true, false];
91-
let mask = core_simd::Mask::<$type, 2>::from_array(values);
92-
let bitmask = mask.to_bitmask();
93-
assert_eq!(bitmask, 0b01);
94-
- assert_eq!(core_simd::Mask::<$type, 2>::from_bitmask(bitmask), mask);
95-
}
96-
97-
#[test]
9834
--
9935
2.25.1

src/intrinsics/simd.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,34 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
652652
}
653653
}
654654

655+
sym::simd_select_bitmask => {
656+
intrinsic_args!(fx, args => (m, a, b); intrinsic);
657+
658+
if !a.layout().ty.is_simd() {
659+
report_simd_type_validation_error(fx, intrinsic, span, a.layout().ty);
660+
return;
661+
}
662+
assert_eq!(a.layout(), b.layout());
663+
664+
let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx);
665+
let lane_layout = fx.layout_of(lane_ty);
666+
667+
let m = m.load_scalar(fx);
668+
669+
for lane in 0..lane_count {
670+
let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(lane) as i64);
671+
let m_lane = fx.bcx.ins().band_imm(m_lane, 1);
672+
let a_lane = a.value_lane(fx, lane).load_scalar(fx);
673+
let b_lane = b.value_lane(fx, lane).load_scalar(fx);
674+
675+
let m_lane = fx.bcx.ins().icmp_imm(IntCC::Equal, m_lane, 0);
676+
let res_lane =
677+
CValue::by_val(fx.bcx.ins().select(m_lane, b_lane, a_lane), lane_layout);
678+
679+
ret.place_lane(fx, lane).write_cvalue(fx, res_lane);
680+
}
681+
}
682+
655683
sym::simd_bitmask => {
656684
intrinsic_args!(fx, args => (a); intrinsic);
657685

@@ -748,7 +776,6 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
748776
// simd_arith_offset
749777
// simd_scatter
750778
// simd_gather
751-
// simd_select_bitmask
752779
_ => {
753780
fx.tcx.sess.span_fatal(span, &format!("Unknown SIMD intrinsic {}", intrinsic));
754781
}

0 commit comments

Comments
 (0)