Skip to content

Commit e459c9f

Browse files
RalfJunggitbot
authored and
gitbot
committed
intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic
1 parent a35e7df commit e459c9f

File tree

5 files changed

+77
-116
lines changed

5 files changed

+77
-116
lines changed

Diff for: core/src/intrinsics/mod.rs

+73-112
Original file line numberDiff line numberDiff line change
@@ -2739,110 +2739,112 @@ pub unsafe fn truncf128(_x: f128) -> f128 {
27392739
unreachable!()
27402740
}
27412741

2742-
/// Returns the nearest integer to an `f16`. Changing the rounding mode is not possible in Rust,
2743-
/// so this rounds half-way cases to the number with an even least significant digit.
2744-
///
2745-
/// May raise an inexact floating-point exception if the argument is not an integer.
2746-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2747-
/// cannot actually be utilized from Rust code.
2748-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf16` and `roundevenf16`.
2742+
/// Returns the nearest integer to an `f16`. Rounds half-way cases to the number with an even
2743+
/// least significant digit.
27492744
///
27502745
/// The stabilized version of this intrinsic is
27512746
/// [`f16::round_ties_even`](../../std/primitive.f16.html#method.round_ties_even)
27522747
#[rustc_intrinsic]
27532748
#[rustc_intrinsic_must_be_overridden]
27542749
#[rustc_nounwind]
2755-
pub unsafe fn rintf16(_x: f16) -> f16 {
2750+
#[cfg(not(bootstrap))]
2751+
pub unsafe fn round_ties_even_f16(_x: f16) -> f16 {
27562752
unreachable!()
27572753
}
2758-
/// Returns the nearest integer to an `f32`. Changing the rounding mode is not possible in Rust,
2759-
/// so this rounds half-way cases to the number with an even least significant digit.
2760-
///
2761-
/// May raise an inexact floating-point exception if the argument is not an integer.
2762-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2763-
/// cannot actually be utilized from Rust code.
2764-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf32` and `roundevenf32`.
2754+
2755+
/// To be removed on next bootstrap bump.
2756+
#[cfg(bootstrap)]
2757+
pub unsafe fn round_ties_even_f16(x: f16) -> f16 {
2758+
#[rustc_intrinsic]
2759+
#[rustc_intrinsic_must_be_overridden]
2760+
#[rustc_nounwind]
2761+
unsafe fn rintf16(_x: f16) -> f16 {
2762+
unreachable!()
2763+
}
2764+
2765+
// SAFETY: this intrinsic isn't actually unsafe
2766+
unsafe { rintf16(x) }
2767+
}
2768+
2769+
/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number with an even
2770+
/// least significant digit.
27652771
///
27662772
/// The stabilized version of this intrinsic is
27672773
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
27682774
#[rustc_intrinsic]
27692775
#[rustc_intrinsic_must_be_overridden]
27702776
#[rustc_nounwind]
2771-
pub unsafe fn rintf32(_x: f32) -> f32 {
2777+
#[cfg(not(bootstrap))]
2778+
pub unsafe fn round_ties_even_f32(_x: f32) -> f32 {
27722779
unreachable!()
27732780
}
2774-
/// Returns the nearest integer to an `f64`. Changing the rounding mode is not possible in Rust,
2775-
/// so this rounds half-way cases to the number with an even least significant digit.
2776-
///
2777-
/// May raise an inexact floating-point exception if the argument is not an integer.
2778-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2779-
/// cannot actually be utilized from Rust code.
2780-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf64` and `roundevenf64`.
2781+
2782+
/// To be removed on next bootstrap bump.
2783+
#[cfg(bootstrap)]
2784+
pub unsafe fn round_ties_even_f32(x: f32) -> f32 {
2785+
#[rustc_intrinsic]
2786+
#[rustc_intrinsic_must_be_overridden]
2787+
#[rustc_nounwind]
2788+
unsafe fn rintf32(_x: f32) -> f32 {
2789+
unreachable!()
2790+
}
2791+
2792+
// SAFETY: this intrinsic isn't actually unsafe
2793+
unsafe { rintf32(x) }
2794+
}
2795+
2796+
/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number with an even
2797+
/// least significant digit.
27812798
///
27822799
/// The stabilized version of this intrinsic is
27832800
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
27842801
#[rustc_intrinsic]
27852802
#[rustc_intrinsic_must_be_overridden]
27862803
#[rustc_nounwind]
2787-
pub unsafe fn rintf64(_x: f64) -> f64 {
2804+
#[cfg(not(bootstrap))]
2805+
pub unsafe fn round_ties_even_f64(_x: f64) -> f64 {
27882806
unreachable!()
27892807
}
2790-
/// Returns the nearest integer to an `f128`. Changing the rounding mode is not possible in Rust,
2791-
/// so this rounds half-way cases to the number with an even least significant digit.
2792-
///
2793-
/// May raise an inexact floating-point exception if the argument is not an integer.
2794-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2795-
/// cannot actually be utilized from Rust code.
2796-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf128` and `roundevenf128`.
2808+
2809+
/// To be removed on next bootstrap bump.
2810+
#[cfg(bootstrap)]
2811+
pub unsafe fn round_ties_even_f64(x: f64) -> f64 {
2812+
#[rustc_intrinsic]
2813+
#[rustc_intrinsic_must_be_overridden]
2814+
#[rustc_nounwind]
2815+
unsafe fn rintf64(_x: f64) -> f64 {
2816+
unreachable!()
2817+
}
2818+
2819+
// SAFETY: this intrinsic isn't actually unsafe
2820+
unsafe { rintf64(x) }
2821+
}
2822+
2823+
/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number with an even
2824+
/// least significant digit.
27972825
///
27982826
/// The stabilized version of this intrinsic is
27992827
/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
28002828
#[rustc_intrinsic]
28012829
#[rustc_intrinsic_must_be_overridden]
28022830
#[rustc_nounwind]
2803-
pub unsafe fn rintf128(_x: f128) -> f128 {
2831+
#[cfg(not(bootstrap))]
2832+
pub unsafe fn round_ties_even_f128(_x: f128) -> f128 {
28042833
unreachable!()
28052834
}
28062835

2807-
/// Returns the nearest integer to an `f16`. Changing the rounding mode is not possible in Rust,
2808-
/// so this rounds half-way cases to the number with an even least significant digit.
2809-
///
2810-
/// This intrinsic does not have a stable counterpart.
2811-
#[rustc_intrinsic]
2812-
#[rustc_intrinsic_must_be_overridden]
2813-
#[rustc_nounwind]
2814-
pub unsafe fn nearbyintf16(_x: f16) -> f16 {
2815-
unreachable!()
2816-
}
2817-
/// Returns the nearest integer to an `f32`. Changing the rounding mode is not possible in Rust,
2818-
/// so this rounds half-way cases to the number with an even least significant digit.
2819-
///
2820-
/// This intrinsic does not have a stable counterpart.
2821-
#[rustc_intrinsic]
2822-
#[rustc_intrinsic_must_be_overridden]
2823-
#[rustc_nounwind]
2824-
pub unsafe fn nearbyintf32(_x: f32) -> f32 {
2825-
unreachable!()
2826-
}
2827-
/// Returns the nearest integer to an `f64`. Changing the rounding mode is not possible in Rust,
2828-
/// so this rounds half-way cases to the number with an even least significant digit.
2829-
///
2830-
/// This intrinsic does not have a stable counterpart.
2831-
#[rustc_intrinsic]
2832-
#[rustc_intrinsic_must_be_overridden]
2833-
#[rustc_nounwind]
2834-
pub unsafe fn nearbyintf64(_x: f64) -> f64 {
2835-
unreachable!()
2836-
}
2837-
/// Returns the nearest integer to an `f128`. Changing the rounding mode is not possible in Rust,
2838-
/// so this rounds half-way cases to the number with an even least significant digit.
2839-
///
2840-
/// This intrinsic does not have a stable counterpart.
2841-
#[rustc_intrinsic]
2842-
#[rustc_intrinsic_must_be_overridden]
2843-
#[rustc_nounwind]
2844-
pub unsafe fn nearbyintf128(_x: f128) -> f128 {
2845-
unreachable!()
2836+
/// To be removed on next bootstrap bump.
2837+
#[cfg(bootstrap)]
2838+
pub unsafe fn round_ties_even_f128(x: f128) -> f128 {
2839+
#[rustc_intrinsic]
2840+
#[rustc_intrinsic_must_be_overridden]
2841+
#[rustc_nounwind]
2842+
unsafe fn rintf128(_x: f128) -> f128 {
2843+
unreachable!()
2844+
}
2845+
2846+
// SAFETY: this intrinsic isn't actually unsafe
2847+
unsafe { rintf128(x) }
28462848
}
28472849

28482850
/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
@@ -2886,47 +2888,6 @@ pub unsafe fn roundf128(_x: f128) -> f128 {
28862888
unreachable!()
28872889
}
28882890

2889-
/// Returns the nearest integer to an `f16`. Rounds half-way cases to the number
2890-
/// with an even least significant digit.
2891-
///
2892-
/// This intrinsic does not have a stable counterpart.
2893-
#[rustc_intrinsic]
2894-
#[rustc_intrinsic_must_be_overridden]
2895-
#[rustc_nounwind]
2896-
pub unsafe fn roundevenf16(_x: f16) -> f16 {
2897-
unreachable!()
2898-
}
2899-
/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number
2900-
/// with an even least significant digit.
2901-
///
2902-
/// This intrinsic does not have a stable counterpart.
2903-
#[rustc_intrinsic]
2904-
#[rustc_intrinsic_must_be_overridden]
2905-
#[rustc_nounwind]
2906-
pub unsafe fn roundevenf32(_x: f32) -> f32 {
2907-
unreachable!()
2908-
}
2909-
/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number
2910-
/// with an even least significant digit.
2911-
///
2912-
/// This intrinsic does not have a stable counterpart.
2913-
#[rustc_intrinsic]
2914-
#[rustc_intrinsic_must_be_overridden]
2915-
#[rustc_nounwind]
2916-
pub unsafe fn roundevenf64(_x: f64) -> f64 {
2917-
unreachable!()
2918-
}
2919-
/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number
2920-
/// with an even least significant digit.
2921-
///
2922-
/// This intrinsic does not have a stable counterpart.
2923-
#[rustc_intrinsic]
2924-
#[rustc_intrinsic_must_be_overridden]
2925-
#[rustc_nounwind]
2926-
pub unsafe fn roundevenf128(_x: f128) -> f128 {
2927-
unreachable!()
2928-
}
2929-
29302891
/// Float addition that allows optimizations based on algebraic rules.
29312892
/// May assume inputs are finite.
29322893
///

Diff for: std/src/f128.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl f128 {
129129
#[unstable(feature = "f128", issue = "116909")]
130130
#[must_use = "method returns a new number and does not mutate the original value"]
131131
pub fn round_ties_even(self) -> f128 {
132-
unsafe { intrinsics::rintf128(self) }
132+
unsafe { intrinsics::round_ties_even_f128(self) }
133133
}
134134

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

Diff for: std/src/f16.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl f16 {
129129
#[unstable(feature = "f16", issue = "116909")]
130130
#[must_use = "method returns a new number and does not mutate the original value"]
131131
pub fn round_ties_even(self) -> f16 {
132-
unsafe { intrinsics::rintf16(self) }
132+
unsafe { intrinsics::round_ties_even_f16(self) }
133133
}
134134

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

Diff for: std/src/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl f32 {
125125
#[stable(feature = "round_ties_even", since = "1.77.0")]
126126
#[inline]
127127
pub fn round_ties_even(self) -> f32 {
128-
unsafe { intrinsics::rintf32(self) }
128+
unsafe { intrinsics::round_ties_even_f32(self) }
129129
}
130130

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

Diff for: std/src/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl f64 {
125125
#[stable(feature = "round_ties_even", since = "1.77.0")]
126126
#[inline]
127127
pub fn round_ties_even(self) -> f64 {
128-
unsafe { intrinsics::rintf64(self) }
128+
unsafe { intrinsics::round_ties_even_f64(self) }
129129
}
130130

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

0 commit comments

Comments
 (0)