Skip to content

Commit 2ffa1dd

Browse files
committed
Implement simd_round_ties_even for miri, cg_clif and cg_gcc
1 parent 2038405 commit 2ffa1dd

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
495495
| sym::simd_flog
496496
| sym::simd_flog10
497497
| sym::simd_flog2
498-
| sym::simd_round => {
498+
| sym::simd_round
499+
| sym::simd_round_ties_even => {
499500
intrinsic_args!(fx, args => (a); intrinsic);
500501

501502
if !a.layout().ty.is_simd() {
@@ -526,6 +527,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
526527
(sym::simd_flog2, types::F64) => "log2",
527528
(sym::simd_round, types::F32) => "roundf",
528529
(sym::simd_round, types::F64) => "round",
530+
(sym::simd_round_ties_even, types::F32) => "rintf",
531+
(sym::simd_round_ties_even, types::F64) => "rint",
529532
_ => unreachable!("{:?}", intrinsic),
530533
};
531534
fx.lib_call(

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
779779
sym::simd_fsin => "sin",
780780
sym::simd_fsqrt => "sqrt",
781781
sym::simd_round => "round",
782+
sym::simd_round_ties_even => "rint",
782783
sym::simd_trunc => "trunc",
783784
_ => return_error!(InvalidMonomorphization::UnrecognizedIntrinsic { span, name }),
784785
};
@@ -826,6 +827,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
826827
| sym::simd_fsin
827828
| sym::simd_fsqrt
828829
| sym::simd_round
830+
| sym::simd_round_ties_even
829831
| sym::simd_trunc
830832
) {
831833
return simd_simple_float_intrinsic(name, in_elem, in_ty, in_len, bx, span, args);

src/tools/miri/src/intrinsics/simd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3737
| "ceil"
3838
| "floor"
3939
| "round"
40+
| "round_ties_even"
4041
| "trunc"
4142
| "fsqrt"
4243
| "fsin"
@@ -72,6 +73,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7273
"ceil" => Op::Round(rustc_apfloat::Round::TowardPositive),
7374
"floor" => Op::Round(rustc_apfloat::Round::TowardNegative),
7475
"round" => Op::Round(rustc_apfloat::Round::NearestTiesToAway),
76+
"round_ties_even" => Op::Round(rustc_apfloat::Round::NearestTiesToEven),
7577
"trunc" => Op::Round(rustc_apfloat::Round::TowardZero),
7678
"ctlz" => Op::Numeric(sym::ctlz),
7779
"ctpop" => Op::Numeric(sym::ctpop),

src/tools/miri/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)