@@ -1051,6 +1051,19 @@ extern "rust-intrinsic" {
1051
1051
/// Returns the absolute value of an `f64`.
1052
1052
pub fn fabsf64 ( x : f64 ) -> f64 ;
1053
1053
1054
+ /// Returns the minimum of two `f32` values.
1055
+ #[ cfg( not( bootstrap) ) ]
1056
+ pub fn minnumf32 ( x : f32 , y : f32 ) -> f32 ;
1057
+ /// Returns the minimum of two `f64` values.
1058
+ #[ cfg( not( bootstrap) ) ]
1059
+ pub fn minnumf64 ( x : f64 , y : f64 ) -> f64 ;
1060
+ /// Returns the maximum of two `f32` values.
1061
+ #[ cfg( not( bootstrap) ) ]
1062
+ pub fn maxnumf32 ( x : f32 , y : f32 ) -> f32 ;
1063
+ /// Returns the maximum of two `f64` values.
1064
+ #[ cfg( not( bootstrap) ) ]
1065
+ pub fn maxnumf64 ( x : f64 , y : f64 ) -> f64 ;
1066
+
1054
1067
/// Copies the sign from `y` to `x` for `f32` values.
1055
1068
pub fn copysignf32 ( x : f32 , y : f32 ) -> f32 ;
1056
1069
/// Copies the sign from `y` to `x` for `f64` values.
@@ -1561,3 +1574,47 @@ pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
1561
1574
pub unsafe fn write_bytes < T > ( dst : * mut T , val : u8 , count : usize ) {
1562
1575
real_intrinsics:: write_bytes ( dst, val, count)
1563
1576
}
1577
+
1578
+ // Simple bootstrap implementations of minnum/maxnum for stage0 compilation.
1579
+
1580
+ /// Returns the minimum of two `f32` values.
1581
+ #[ cfg( bootstrap) ]
1582
+ pub fn minnumf32 ( x : f32 , y : f32 ) -> f32 {
1583
+ // IEEE754 says: minNum(x, y) is the canonicalized number x if x < y, y if y < x, the
1584
+ // canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
1585
+ // is either x or y, canonicalized (this means results might differ among implementations).
1586
+ // When either x or y is a signaling NaN, then the result is according to 6.2.
1587
+ //
1588
+ // Since we do not support sNaN in Rust yet, we do not need to handle them.
1589
+ // FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
1590
+ // multiplying by 1.0. Should switch to the `canonicalize` when it works.
1591
+ ( if x < y || y != y { x } else { y } ) * 1.0
1592
+ }
1593
+
1594
+ /// Returns the minimum of two `f64` values.
1595
+ #[ cfg( bootstrap) ]
1596
+ pub fn minnumf64 ( x : f64 , y : f64 ) -> f64 {
1597
+ // Identical to the `f32` case.
1598
+ ( if x < y || y != y { x } else { y } ) * 1.0
1599
+ }
1600
+
1601
+ /// Returns the maximum of two `f32` values.
1602
+ #[ cfg( bootstrap) ]
1603
+ pub fn maxnumf32 ( x : f32 , y : f32 ) -> f32 {
1604
+ // IEEE754 says: maxNum(x, y) is the canonicalized number y if x < y, x if y < x, the
1605
+ // canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
1606
+ // is either x or y, canonicalized (this means results might differ among implementations).
1607
+ // When either x or y is a signaling NaN, then the result is according to 6.2.
1608
+ //
1609
+ // Since we do not support sNaN in Rust yet, we do not need to handle them.
1610
+ // FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
1611
+ // multiplying by 1.0. Should switch to the `canonicalize` when it works.
1612
+ ( if x < y || x != x { y } else { x } ) * 1.0
1613
+ }
1614
+
1615
+ /// Returns the maximum of two `f64` values.
1616
+ #[ cfg( bootstrap) ]
1617
+ pub fn maxnumf64 ( x : f64 , y : f64 ) -> f64 {
1618
+ // Identical to the `f32` case.
1619
+ ( if x < y || x != x { y } else { x } ) * 1.0
1620
+ }
0 commit comments