Skip to content

Commit b3f6df4

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

File tree

5 files changed

+77
-116
lines changed

5 files changed

+77
-116
lines changed

core/src/intrinsics/mod.rs

+73-112
Original file line numberDiff line numberDiff line change
@@ -2731,110 +2731,112 @@ pub unsafe fn truncf128(_x: f128) -> f128 {
27312731
unreachable!()
27322732
}
27332733

2734-
/// Returns the nearest integer to an `f16`. Changing the rounding mode is not possible in Rust,
2735-
/// so this rounds half-way cases to the number with an even least significant digit.
2736-
///
2737-
/// May raise an inexact floating-point exception if the argument is not an integer.
2738-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2739-
/// cannot actually be utilized from Rust code.
2740-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf16` and `roundevenf16`.
2734+
/// Returns the nearest integer to an `f16`. Rounds half-way cases to the number with an even
2735+
/// least significant digit.
27412736
///
27422737
/// The stabilized version of this intrinsic is
27432738
/// [`f16::round_ties_even`](../../std/primitive.f16.html#method.round_ties_even)
27442739
#[rustc_intrinsic]
27452740
#[rustc_intrinsic_must_be_overridden]
27462741
#[rustc_nounwind]
2747-
pub unsafe fn rintf16(_x: f16) -> f16 {
2742+
#[cfg(not(bootstrap))]
2743+
pub unsafe fn round_ties_even_f16(_x: f16) -> f16 {
27482744
unreachable!()
27492745
}
2750-
/// Returns the nearest integer to an `f32`. Changing the rounding mode is not possible in Rust,
2751-
/// so this rounds half-way cases to the number with an even least significant digit.
2752-
///
2753-
/// May raise an inexact floating-point exception if the argument is not an integer.
2754-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2755-
/// cannot actually be utilized from Rust code.
2756-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf32` and `roundevenf32`.
2746+
2747+
/// To be removed on next bootstrap bump.
2748+
#[cfg(bootstrap)]
2749+
pub unsafe fn round_ties_even_f16(x: f16) -> f16 {
2750+
#[rustc_intrinsic]
2751+
#[rustc_intrinsic_must_be_overridden]
2752+
#[rustc_nounwind]
2753+
unsafe fn rintf16(_x: f16) -> f16 {
2754+
unreachable!()
2755+
}
2756+
2757+
// SAFETY: this intrinsic isn't actually unsafe
2758+
unsafe { rintf16(x) }
2759+
}
2760+
2761+
/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number with an even
2762+
/// least significant digit.
27572763
///
27582764
/// The stabilized version of this intrinsic is
27592765
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
27602766
#[rustc_intrinsic]
27612767
#[rustc_intrinsic_must_be_overridden]
27622768
#[rustc_nounwind]
2763-
pub unsafe fn rintf32(_x: f32) -> f32 {
2769+
#[cfg(not(bootstrap))]
2770+
pub unsafe fn round_ties_even_f32(_x: f32) -> f32 {
27642771
unreachable!()
27652772
}
2766-
/// Returns the nearest integer to an `f64`. Changing the rounding mode is not possible in Rust,
2767-
/// so this rounds half-way cases to the number with an even least significant digit.
2768-
///
2769-
/// May raise an inexact floating-point exception if the argument is not an integer.
2770-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2771-
/// cannot actually be utilized from Rust code.
2772-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf64` and `roundevenf64`.
2773+
2774+
/// To be removed on next bootstrap bump.
2775+
#[cfg(bootstrap)]
2776+
pub unsafe fn round_ties_even_f32(x: f32) -> f32 {
2777+
#[rustc_intrinsic]
2778+
#[rustc_intrinsic_must_be_overridden]
2779+
#[rustc_nounwind]
2780+
unsafe fn rintf32(_x: f32) -> f32 {
2781+
unreachable!()
2782+
}
2783+
2784+
// SAFETY: this intrinsic isn't actually unsafe
2785+
unsafe { rintf32(x) }
2786+
}
2787+
2788+
/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number with an even
2789+
/// least significant digit.
27732790
///
27742791
/// The stabilized version of this intrinsic is
27752792
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
27762793
#[rustc_intrinsic]
27772794
#[rustc_intrinsic_must_be_overridden]
27782795
#[rustc_nounwind]
2779-
pub unsafe fn rintf64(_x: f64) -> f64 {
2796+
#[cfg(not(bootstrap))]
2797+
pub unsafe fn round_ties_even_f64(_x: f64) -> f64 {
27802798
unreachable!()
27812799
}
2782-
/// Returns the nearest integer to an `f128`. Changing the rounding mode is not possible in Rust,
2783-
/// so this rounds half-way cases to the number with an even least significant digit.
2784-
///
2785-
/// May raise an inexact floating-point exception if the argument is not an integer.
2786-
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2787-
/// cannot actually be utilized from Rust code.
2788-
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf128` and `roundevenf128`.
2800+
2801+
/// To be removed on next bootstrap bump.
2802+
#[cfg(bootstrap)]
2803+
pub unsafe fn round_ties_even_f64(x: f64) -> f64 {
2804+
#[rustc_intrinsic]
2805+
#[rustc_intrinsic_must_be_overridden]
2806+
#[rustc_nounwind]
2807+
unsafe fn rintf64(_x: f64) -> f64 {
2808+
unreachable!()
2809+
}
2810+
2811+
// SAFETY: this intrinsic isn't actually unsafe
2812+
unsafe { rintf64(x) }
2813+
}
2814+
2815+
/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number with an even
2816+
/// least significant digit.
27892817
///
27902818
/// The stabilized version of this intrinsic is
27912819
/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
27922820
#[rustc_intrinsic]
27932821
#[rustc_intrinsic_must_be_overridden]
27942822
#[rustc_nounwind]
2795-
pub unsafe fn rintf128(_x: f128) -> f128 {
2823+
#[cfg(not(bootstrap))]
2824+
pub unsafe fn round_ties_even_f128(_x: f128) -> f128 {
27962825
unreachable!()
27972826
}
27982827

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

28402842
/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
@@ -2878,47 +2880,6 @@ pub unsafe fn roundf128(_x: f128) -> f128 {
28782880
unreachable!()
28792881
}
28802882

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

std/src/f128.rs

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

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

std/src/f16.rs

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

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

std/src/f32.rs

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

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

std/src/f64.rs

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

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

0 commit comments

Comments
 (0)