Skip to content

Commit f813811

Browse files
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.
1 parent 03c166d commit f813811

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ fn codegen_float_intrinsic_call<'tcx>(
295295
sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64),
296296
sym::truncf32 => ("truncf", 1, fx.tcx.types.f32),
297297
sym::truncf64 => ("trunc", 1, fx.tcx.types.f64),
298+
sym::rintf32 => ("rintf", 1, fx.tcx.types.f32),
299+
sym::rintf64 => ("rint", 1, fx.tcx.types.f64),
298300
sym::roundf32 => ("roundf", 1, fx.tcx.types.f32),
299301
sym::roundf64 => ("round", 1, fx.tcx.types.f64),
300302
sym::roundevenf32 => ("roundevenf", 1, fx.tcx.types.f32),

library/core/src/intrinsics.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1588,9 +1588,15 @@ extern "rust-intrinsic" {
15881588

15891589
/// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
15901590
/// if the argument is not an integer.
1591+
///
1592+
/// The stabilized version of this intrinsic is
1593+
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
15911594
pub fn rintf32(x: f32) -> f32;
15921595
/// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
15931596
/// if the argument is not an integer.
1597+
///
1598+
/// The stabilized version of this intrinsic is
1599+
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
15941600
pub fn rintf64(x: f64) -> f64;
15951601

15961602
/// Returns the nearest integer to an `f32`.
@@ -1616,16 +1622,13 @@ extern "rust-intrinsic" {
16161622
/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number
16171623
/// with an even least significant digit.
16181624
///
1619-
/// The stabilized version of this intrinsic is
1620-
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
1625+
/// This intrinsic does not have a stable counterpart.
16211626
#[cfg(not(bootstrap))]
16221627
pub fn roundevenf32(x: f32) -> f32;
1623-
16241628
/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number
16251629
/// with an even least significant digit.
16261630
///
1627-
/// The stabilized version of this intrinsic is
1628-
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
1631+
/// This intrinsic does not have a stable counterpart.
16291632
#[cfg(not(bootstrap))]
16301633
pub fn roundevenf64(x: f64) -> f64;
16311634

library/std/src/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl f32 {
119119
#[unstable(feature = "round_ties_even", issue = "96710")]
120120
#[inline]
121121
pub fn round_ties_even(self) -> f32 {
122-
unsafe { intrinsics::roundevenf32(self) }
122+
unsafe { intrinsics::rintf32(self) }
123123
}
124124

125125
/// Returns the integer part of `self`.

library/std/src/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl f64 {
119119
#[unstable(feature = "round_ties_even", issue = "96710")]
120120
#[inline]
121121
pub fn round_ties_even(self) -> f64 {
122-
unsafe { intrinsics::roundevenf64(self) }
122+
unsafe { intrinsics::rintf64(self) }
123123
}
124124

125125
/// Returns the integer part of `self`.

0 commit comments

Comments
 (0)