@@ -1019,39 +1019,23 @@ fn codegen_regular_intrinsic_call<'tcx>(
10191019 ret. write_cvalue( fx, old) ;
10201020 } ;
10211021
1022- // In Rust floating point min and max don't propagate NaN. In Cranelift they do however.
1023- // For this reason it is necessary to use `a.is_nan() ? b : (a >= b ? b : a)` for `minnumf*`
1024- // and `a.is_nan() ? b : (a <= b ? b : a)` for `maxnumf*`. NaN checks are done by comparing
1025- // a float against itself. Only in case of NaN is it not equal to itself.
10261022 minnumf32, ( v a, v b) {
1027- let a_is_nan = fx. bcx. ins( ) . fcmp( FloatCC :: NotEqual , a, a) ;
1028- let a_ge_b = fx. bcx. ins( ) . fcmp( FloatCC :: GreaterThanOrEqual , a, b) ;
1029- let temp = fx. bcx. ins( ) . select( a_ge_b, b, a) ;
1030- let val = fx. bcx. ins( ) . select( a_is_nan, b, temp) ;
1023+ let val = crate :: num:: codegen_float_min( fx, a, b) ;
10311024 let val = CValue :: by_val( val, fx. layout_of( fx. tcx. types. f32 ) ) ;
10321025 ret. write_cvalue( fx, val) ;
10331026 } ;
10341027 minnumf64, ( v a, v b) {
1035- let a_is_nan = fx. bcx. ins( ) . fcmp( FloatCC :: NotEqual , a, a) ;
1036- let a_ge_b = fx. bcx. ins( ) . fcmp( FloatCC :: GreaterThanOrEqual , a, b) ;
1037- let temp = fx. bcx. ins( ) . select( a_ge_b, b, a) ;
1038- let val = fx. bcx. ins( ) . select( a_is_nan, b, temp) ;
1028+ let val = crate :: num:: codegen_float_min( fx, a, b) ;
10391029 let val = CValue :: by_val( val, fx. layout_of( fx. tcx. types. f64 ) ) ;
10401030 ret. write_cvalue( fx, val) ;
10411031 } ;
10421032 maxnumf32, ( v a, v b) {
1043- let a_is_nan = fx. bcx. ins( ) . fcmp( FloatCC :: NotEqual , a, a) ;
1044- let a_le_b = fx. bcx. ins( ) . fcmp( FloatCC :: LessThanOrEqual , a, b) ;
1045- let temp = fx. bcx. ins( ) . select( a_le_b, b, a) ;
1046- let val = fx. bcx. ins( ) . select( a_is_nan, b, temp) ;
1033+ let val = crate :: num:: codegen_float_max( fx, a, b) ;
10471034 let val = CValue :: by_val( val, fx. layout_of( fx. tcx. types. f32 ) ) ;
10481035 ret. write_cvalue( fx, val) ;
10491036 } ;
10501037 maxnumf64, ( v a, v b) {
1051- let a_is_nan = fx. bcx. ins( ) . fcmp( FloatCC :: NotEqual , a, a) ;
1052- let a_le_b = fx. bcx. ins( ) . fcmp( FloatCC :: LessThanOrEqual , a, b) ;
1053- let temp = fx. bcx. ins( ) . select( a_le_b, b, a) ;
1054- let val = fx. bcx. ins( ) . select( a_is_nan, b, temp) ;
1038+ let val = crate :: num:: codegen_float_max( fx, a, b) ;
10551039 let val = CValue :: by_val( val, fx. layout_of( fx. tcx. types. f64 ) ) ;
10561040 ret. write_cvalue( fx, val) ;
10571041 } ;
0 commit comments