Skip to content

Commit a6b6316

Browse files
committed
Add intrinsic fallback for {minimum,maximum}{16,32,64,128}
1 parent e7247df commit a6b6316

File tree

5 files changed

+92
-16
lines changed

5 files changed

+92
-16
lines changed

library/core/src/intrinsics/mod.rs

Lines changed: 92 additions & 8 deletions
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
///
@@ -4002,7 +4013,18 @@ pub const fn minimumf16(x: f16, y: f16) -> f16;
40024013
#[rustc_nounwind]
40034014
#[rustc_intrinsic]
40044015
#[cfg(not(bootstrap))]
4005-
pub const fn minimumf32(x: f32, y: f32) -> f32;
4016+
pub const fn minimumf32(x: f32, y: f32) -> f32 {
4017+
if x < y {
4018+
x
4019+
} else if y < x {
4020+
y
4021+
} else if x == y {
4022+
if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
4023+
} else {
4024+
// At least one input is NaN. Use `+` to perform NaN propagation and quieting.
4025+
x + y
4026+
}
4027+
}
40064028

40074029
/// Returns the minimum (IEEE 754-2019 minimum) of two `f64` values.
40084030
///
@@ -4013,7 +4035,18 @@ pub const fn minimumf32(x: f32, y: f32) -> f32;
40134035
#[rustc_nounwind]
40144036
#[rustc_intrinsic]
40154037
#[cfg(not(bootstrap))]
4016-
pub const fn minimumf64(x: f64, y: f64) -> f64;
4038+
pub const fn minimumf64(x: f64, y: f64) -> f64 {
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+
}
40174050

40184051
/// Returns the minimum (IEEE 754-2019 minimum) of two `f128` values.
40194052
///
@@ -4024,7 +4057,18 @@ pub const fn minimumf64(x: f64, y: f64) -> f64;
40244057
#[rustc_nounwind]
40254058
#[rustc_intrinsic]
40264059
#[cfg(not(bootstrap))]
4027-
pub const fn minimumf128(x: f128, y: f128) -> f128;
4060+
pub const fn minimumf128(x: f128, y: f128) -> f128 {
4061+
if x < y {
4062+
x
4063+
} else if y < x {
4064+
y
4065+
} else if x == y {
4066+
if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
4067+
} else {
4068+
// At least one input is NaN. Use `+` to perform NaN propagation and quieting.
4069+
x + y
4070+
}
4071+
}
40284072

40294073
/// Returns the maximum (IEEE 754-2008 maxNum) of two `f16` values.
40304074
///
@@ -4089,7 +4133,17 @@ pub const fn maxnumf128(x: f128, y: f128) -> f128;
40894133
#[rustc_nounwind]
40904134
#[rustc_intrinsic]
40914135
#[cfg(not(bootstrap))]
4092-
pub const fn maximumf16(x: f16, y: f16) -> f16;
4136+
pub const fn maximumf16(x: f16, y: f16) -> f16 {
4137+
if x > y {
4138+
x
4139+
} else if y > x {
4140+
y
4141+
} else if x == y {
4142+
if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
4143+
} else {
4144+
x + y
4145+
}
4146+
}
40934147

40944148
/// Returns the maximum (IEEE 754-2019 maximum) of two `f32` values.
40954149
///
@@ -4100,7 +4154,17 @@ pub const fn maximumf16(x: f16, y: f16) -> f16;
41004154
#[rustc_nounwind]
41014155
#[rustc_intrinsic]
41024156
#[cfg(not(bootstrap))]
4103-
pub const fn maximumf32(x: f32, y: f32) -> f32;
4157+
pub const fn maximumf32(x: f32, y: f32) -> f32 {
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+
}
41044168

41054169
/// Returns the maximum (IEEE 754-2019 maximum) of two `f64` values.
41064170
///
@@ -4111,7 +4175,17 @@ pub const fn maximumf32(x: f32, y: f32) -> f32;
41114175
#[rustc_nounwind]
41124176
#[rustc_intrinsic]
41134177
#[cfg(not(bootstrap))]
4114-
pub const fn maximumf64(x: f64, y: f64) -> f64;
4178+
pub const fn maximumf64(x: f64, y: f64) -> f64 {
4179+
if x > y {
4180+
x
4181+
} else if y > x {
4182+
y
4183+
} else if x == y {
4184+
if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
4185+
} else {
4186+
x + y
4187+
}
4188+
}
41154189

41164190
/// Returns the maximum (IEEE 754-2019 maximum) of two `f128` values.
41174191
///
@@ -4122,7 +4196,17 @@ pub const fn maximumf64(x: f64, y: f64) -> f64;
41224196
#[rustc_nounwind]
41234197
#[rustc_intrinsic]
41244198
#[cfg(not(bootstrap))]
4125-
pub const fn maximumf128(x: f128, y: f128) -> f128;
4199+
pub const fn maximumf128(x: f128, y: f128) -> f128 {
4200+
if x > y {
4201+
x
4202+
} else if y > x {
4203+
y
4204+
} else if x == y {
4205+
if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
4206+
} else {
4207+
x + y
4208+
}
4209+
}
41264210

41274211
/// Returns the absolute value of an `f16`.
41284212
///

library/core/src/num/f128.rs

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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))]

library/core/src/num/f32.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ impl f32 {
942942
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
943943
#[must_use = "this returns the result of the comparison, without modifying either input"]
944944
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
945-
#[rustc_const_unstable(feature = "float_minimum_maximum", issue = "91079")]
946945
#[inline]
947946
pub const fn maximum(self, other: f32) -> f32 {
948947
#[cfg(not(bootstrap))]
@@ -985,7 +984,6 @@ impl f32 {
985984
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
986985
#[must_use = "this returns the result of the comparison, without modifying either input"]
987986
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
988-
#[rustc_const_unstable(feature = "float_minimum_maximum", issue = "91079")]
989987
#[inline]
990988
pub const fn minimum(self, other: f32) -> f32 {
991989
#[cfg(not(bootstrap))]

library/core/src/num/f64.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,6 @@ impl f64 {
960960
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
961961
#[must_use = "this returns the result of the comparison, without modifying either input"]
962962
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
963-
#[rustc_const_unstable(feature = "float_minimum_maximum", issue = "91079")]
964963
#[inline]
965964
pub const fn maximum(self, other: f64) -> f64 {
966965
#[cfg(not(bootstrap))]
@@ -1003,7 +1002,6 @@ impl f64 {
10031002
/// operand is conserved; see the [specification of NaN bit patterns](f32#nan-bit-patterns) for more info.
10041003
#[must_use = "this returns the result of the comparison, without modifying either input"]
10051004
#[unstable(feature = "float_minimum_maximum", issue = "91079")]
1006-
#[rustc_const_unstable(feature = "float_minimum_maximum", issue = "91079")]
10071005
#[inline]
10081006
pub const fn minimum(self, other: f64) -> f64 {
10091007
#[cfg(not(bootstrap))]

0 commit comments

Comments
 (0)