Skip to content

Commit b3f8760

Browse files
authored
Rollup merge of #125266 - workingjubilee:stream-plastic-love, r=RalfJung,nikic
compiler: add simd_ctpop intrinsic Fairly straightforward addition. cc `@rust-lang/opsem` new (extremely boring) intrinsic
2 parents 39b3e33 + 21e99a8 commit b3f8760

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/intrinsics/simd.rs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4242
| "flog2"
4343
| "flog10"
4444
| "ctlz"
45+
| "ctpop"
4546
| "cttz"
4647
| "bswap"
4748
| "bitreverse"
@@ -68,6 +69,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6869
"round" => Op::Round(rustc_apfloat::Round::NearestTiesToAway),
6970
"trunc" => Op::Round(rustc_apfloat::Round::TowardZero),
7071
"ctlz" => Op::Numeric(sym::ctlz),
72+
"ctpop" => Op::Numeric(sym::ctpop),
7173
"cttz" => Op::Numeric(sym::cttz),
7274
"bswap" => Op::Numeric(sym::bswap),
7375
"bitreverse" => Op::Numeric(sym::bitreverse),

tests/pass/intrinsics/portable-simd.rs

+15
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,21 @@ fn simd_intrinsics() {
505505
assert!(simd_reduce_all(i32x4::splat(-1)));
506506
assert!(!simd_reduce_all(i32x2::from_array([0, -1])));
507507

508+
assert_eq!(
509+
simd_ctlz(i32x4::from_array([0, i32::MAX, i32::MIN, -1_i32])),
510+
i32x4::from_array([32, 1, 0, 0])
511+
);
512+
513+
assert_eq!(
514+
simd_ctpop(i32x4::from_array([0, i32::MAX, i32::MIN, -1_i32])),
515+
i32x4::from_array([0, 31, 1, 32])
516+
);
517+
518+
assert_eq!(
519+
simd_cttz(i32x4::from_array([0, i32::MAX, i32::MIN, -1_i32])),
520+
i32x4::from_array([32, 0, 31, 0])
521+
);
522+
508523
assert_eq!(
509524
simd_select(i8x4::from_array([0, -1, -1, 0]), a, b),
510525
i32x4::from_array([1, 10, 10, 4])

0 commit comments

Comments
 (0)