Skip to content

Commit a695145

Browse files
Rollup merge of #142078 - sayantn:more-intrinsics, r=workingjubilee
Add SIMD funnel shift and round-to-even intrinsics This PR adds 3 new SIMD intrinsics - `simd_funnel_shl` - funnel shift left - `simd_funnel_shr` - funnel shift right - `simd_round_ties_even` (vector version of `round_ties_even_fN`) TODO (future PR): implement `simd_fsh{l,r}` in miri, cg_gcc and cg_clif (it is surprisingly hard to implement without branches, the common tricks that rotate uses doesn't work because we have 2 elements now. e.g, the `-n&31` trick used by cg_gcc to implement rotate doesn't work with this because then `fshl(a, b, 0)` will be `a | b`) [#t-compiler > More SIMD intrinsics](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/More.20SIMD.20intrinsics/with/522130286) `@rustbot` label T-compiler T-libs A-intrinsics F-core_intrinsics r? `@workingjubilee`
2 parents a32d884 + 2234a5d commit a695145

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/intrinsics/simd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3636
| "ceil"
3737
| "floor"
3838
| "round"
39+
| "round_ties_even"
3940
| "trunc"
4041
| "fsqrt"
4142
| "fsin"
@@ -71,6 +72,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7172
"ceil" => Op::Round(rustc_apfloat::Round::TowardPositive),
7273
"floor" => Op::Round(rustc_apfloat::Round::TowardNegative),
7374
"round" => Op::Round(rustc_apfloat::Round::NearestTiesToAway),
75+
"round_ties_even" => Op::Round(rustc_apfloat::Round::NearestTiesToEven),
7476
"trunc" => Op::Round(rustc_apfloat::Round::TowardZero),
7577
"ctlz" => Op::Numeric(sym::ctlz),
7678
"ctpop" => Op::Numeric(sym::ctpop),

tests/pass/intrinsics/portable-simd.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ fn simd_round() {
569569
f32x4::from_array([0.9, 1.001, 2.0, -4.5]).round(),
570570
f32x4::from_array([1.0, 1.0, 2.0, -5.0])
571571
);
572+
assert_eq!(
573+
unsafe { intrinsics::simd_round_ties_even(f32x4::from_array([0.9, 1.001, 2.0, -4.5])) },
574+
f32x4::from_array([1.0, 1.0, 2.0, -4.0])
575+
);
572576
assert_eq!(
573577
f32x4::from_array([0.9, 1.001, 2.0, -4.5]).trunc(),
574578
f32x4::from_array([0.0, 1.0, 2.0, -4.0])
@@ -586,6 +590,10 @@ fn simd_round() {
586590
f64x4::from_array([0.9, 1.001, 2.0, -4.5]).round(),
587591
f64x4::from_array([1.0, 1.0, 2.0, -5.0])
588592
);
593+
assert_eq!(
594+
unsafe { intrinsics::simd_round_ties_even(f64x4::from_array([0.9, 1.001, 2.0, -4.5])) },
595+
f64x4::from_array([1.0, 1.0, 2.0, -4.0])
596+
);
589597
assert_eq!(
590598
f64x4::from_array([0.9, 1.001, 2.0, -4.5]).trunc(),
591599
f64x4::from_array([0.0, 1.0, 2.0, -4.0])

0 commit comments

Comments
 (0)