From f8138110bca50f8eb9196e098d20df5f496b7051 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Mon, 7 Nov 2022 13:10:36 -0500 Subject: [PATCH] Use rint instead of roundeven Use rint intrinsic instead of roundeven to impement `round_ties_even`. They do the same thing when rounding mode is default, which Rust assumes. And `rint` has better platform support. Keeps `roundeven` around in `core::intrinsics`, it's doing no harm there. --- .../rustc_codegen_cranelift/src/intrinsics/mod.rs | 2 ++ library/core/src/intrinsics.rs | 13 ++++++++----- library/std/src/f32.rs | 2 +- library/std/src/f64.rs | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs index 4851c3fdcb7..ff9447a7484 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs @@ -295,6 +295,8 @@ fn codegen_float_intrinsic_call<'tcx>( sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64), sym::truncf32 => ("truncf", 1, fx.tcx.types.f32), sym::truncf64 => ("trunc", 1, fx.tcx.types.f64), + sym::rintf32 => ("rintf", 1, fx.tcx.types.f32), + sym::rintf64 => ("rint", 1, fx.tcx.types.f64), sym::roundf32 => ("roundf", 1, fx.tcx.types.f32), sym::roundf64 => ("round", 1, fx.tcx.types.f64), sym::roundevenf32 => ("roundevenf", 1, fx.tcx.types.f32), diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index e331dfff6fd..dd84e546a84 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1588,9 +1588,15 @@ extern "rust-intrinsic" { /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception /// if the argument is not an integer. + /// + /// The stabilized version of this intrinsic is + /// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even) pub fn rintf32(x: f32) -> f32; /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception /// if the argument is not an integer. + /// + /// The stabilized version of this intrinsic is + /// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even) pub fn rintf64(x: f64) -> f64; /// Returns the nearest integer to an `f32`. @@ -1616,16 +1622,13 @@ extern "rust-intrinsic" { /// Returns the nearest integer to an `f32`. Rounds half-way cases to the number /// with an even least significant digit. /// - /// The stabilized version of this intrinsic is - /// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even) + /// This intrinsic does not have a stable counterpart. #[cfg(not(bootstrap))] pub fn roundevenf32(x: f32) -> f32; - /// Returns the nearest integer to an `f64`. Rounds half-way cases to the number /// with an even least significant digit. /// - /// The stabilized version of this intrinsic is - /// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even) + /// This intrinsic does not have a stable counterpart. #[cfg(not(bootstrap))] pub fn roundevenf64(x: f64) -> f64; diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index d92eb45e96c..221ad469de9 100644 --- a/library/std/src/f32.rs +++ b/library/std/src/f32.rs @@ -119,7 +119,7 @@ impl f32 { #[unstable(feature = "round_ties_even", issue = "96710")] #[inline] pub fn round_ties_even(self) -> f32 { - unsafe { intrinsics::roundevenf32(self) } + unsafe { intrinsics::rintf32(self) } } /// Returns the integer part of `self`. diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs index 2e98495fad3..4663e00f9ed 100644 --- a/library/std/src/f64.rs +++ b/library/std/src/f64.rs @@ -119,7 +119,7 @@ impl f64 { #[unstable(feature = "round_ties_even", issue = "96710")] #[inline] pub fn round_ties_even(self) -> f64 { - unsafe { intrinsics::roundevenf64(self) } + unsafe { intrinsics::rintf64(self) } } /// Returns the integer part of `self`.