Skip to content

Commit f63c9d7

Browse files
committed
Add intrinsic fallback for {minimum,maximum}{16,128}
1 parent cad0a57 commit f63c9d7

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

library/core/src/intrinsics/mod.rs

+46-4
Original file line numberDiff line numberDiff line change
@@ -3991,7 +3991,18 @@ pub const fn minnumf128(x: f128, y: f128) -> f128;
39913991
#[rustc_nounwind]
39923992
#[rustc_intrinsic]
39933993
#[cfg(not(bootstrap))]
3994-
pub const fn minimumf16(x: f16, y: f16) -> f16;
3994+
pub const fn minimumf16(x: f16, y: f16) -> f16 {
3995+
if x < y {
3996+
x
3997+
} else if y < x {
3998+
y
3999+
} else if x == y {
4000+
if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
4001+
} else {
4002+
// At least one input is NaN. Use `+` to perform NaN propagation and quieting.
4003+
x + y
4004+
}
4005+
}
39954006

39964007
/// Returns the minimum (IEEE 754-2019 minimum) of two `f32` values.
39974008
///
@@ -4024,7 +4035,18 @@ pub const fn minimumf64(x: f64, y: f64) -> f64;
40244035
#[rustc_nounwind]
40254036
#[rustc_intrinsic]
40264037
#[cfg(not(bootstrap))]
4027-
pub const fn minimumf128(x: f128, y: f128) -> f128;
4038+
pub const fn minimumf128(x: f128, y: f128) -> f128 {
4039+
if x < y {
4040+
x
4041+
} else if y < x {
4042+
y
4043+
} else if x == y {
4044+
if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
4045+
} else {
4046+
// At least one input is NaN. Use `+` to perform NaN propagation and quieting.
4047+
x + y
4048+
}
4049+
}
40284050

40294051
/// Returns the maximum (IEEE 754-2008 maxNum) of two `f16` values.
40304052
///
@@ -4089,7 +4111,17 @@ pub const fn maxnumf128(x: f128, y: f128) -> f128;
40894111
#[rustc_nounwind]
40904112
#[rustc_intrinsic]
40914113
#[cfg(not(bootstrap))]
4092-
pub const fn maximumf16(x: f16, y: f16) -> f16;
4114+
pub const fn maximumf16(x: f16, y: f16) -> f16 {
4115+
if x > y {
4116+
x
4117+
} else if y > x {
4118+
y
4119+
} else if x == y {
4120+
if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
4121+
} else {
4122+
x + y
4123+
}
4124+
}
40934125

40944126
/// Returns the maximum (IEEE 754-2019 maximum) of two `f32` values.
40954127
///
@@ -4122,7 +4154,17 @@ pub const fn maximumf64(x: f64, y: f64) -> f64;
41224154
#[rustc_nounwind]
41234155
#[rustc_intrinsic]
41244156
#[cfg(not(bootstrap))]
4125-
pub const fn maximumf128(x: f128, y: f128) -> f128;
4157+
pub const fn maximumf128(x: f128, y: f128) -> f128 {
4158+
if x > y {
4159+
x
4160+
} else if y > x {
4161+
y
4162+
} else if x == y {
4163+
if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
4164+
} else {
4165+
x + y
4166+
}
4167+
}
41264168

41274169
/// Returns the absolute value of an `f16`.
41284170
///

library/core/src/num/f128.rs

-2
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,6 @@ impl f128 {
755755
#[inline]
756756
#[unstable(feature = "f128", issue = "116909")]
757757
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
758-
#[rustc_const_unstable(feature = "f128", issue = "116909")]
759758
#[must_use = "this returns the result of the comparison, without modifying either input"]
760759
pub const fn maximum(self, other: f128) -> f128 {
761760
#[cfg(not(bootstrap))]
@@ -804,7 +803,6 @@ impl f128 {
804803
#[inline]
805804
#[unstable(feature = "f128", issue = "116909")]
806805
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
807-
#[rustc_const_unstable(feature = "f128", issue = "116909")]
808806
#[must_use = "this returns the result of the comparison, without modifying either input"]
809807
pub const fn minimum(self, other: f128) -> f128 {
810808
#[cfg(not(bootstrap))]

library/core/src/num/f16.rs

-2
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ impl f16 {
744744
#[inline]
745745
#[unstable(feature = "f16", issue = "116909")]
746746
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
747-
#[rustc_const_unstable(feature = "f16", issue = "116909")]
748747
#[must_use = "this returns the result of the comparison, without modifying either input"]
749748
pub const fn maximum(self, other: f16) -> f16 {
750749
#[cfg(not(bootstrap))]
@@ -792,7 +791,6 @@ impl f16 {
792791
#[inline]
793792
#[unstable(feature = "f16", issue = "116909")]
794793
// #[unstable(feature = "float_minimum_maximum", issue = "91079")]
795-
#[rustc_const_unstable(feature = "f16", issue = "116909")]
796794
#[must_use = "this returns the result of the comparison, without modifying either input"]
797795
pub const fn minimum(self, other: f16) -> f16 {
798796
#[cfg(not(bootstrap))]

0 commit comments

Comments
 (0)