@@ -23,6 +23,7 @@ use rustc_target::{
23
23
24
24
use super :: backtrace:: EvalContextExt as _;
25
25
use crate :: * ;
26
+ use helpers:: { ToHost , ToSoft } ;
26
27
27
28
/// Type of dynamic symbols (for `dlsym` et al)
28
29
#[ derive( Debug , Copy , Clone ) ]
@@ -886,23 +887,26 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
886
887
| "tgammaf"
887
888
=> {
888
889
let [ f] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
890
+ let f = this. read_scalar ( f) ?. to_f32 ( ) ?;
889
891
// FIXME: Using host floats.
890
- let f = f32 :: from_bits ( this . read_scalar ( f ) ? . to_u32 ( ) ? ) ;
892
+ let f_host = f . to_host ( ) ;
891
893
let res = match link_name. as_str ( ) {
892
- "cbrtf" => f . cbrt ( ) ,
893
- "coshf" => f . cosh ( ) ,
894
- "sinhf" => f . sinh ( ) ,
895
- "tanf" => f . tan ( ) ,
896
- "tanhf" => f . tanh ( ) ,
897
- "acosf" => f . acos ( ) ,
898
- "asinf" => f . asin ( ) ,
899
- "atanf" => f . atan ( ) ,
900
- "log1pf" => f . ln_1p ( ) ,
901
- "expm1f" => f . exp_m1 ( ) ,
902
- "tgammaf" => f . gamma ( ) ,
894
+ "cbrtf" => f_host . cbrt ( ) ,
895
+ "coshf" => f_host . cosh ( ) ,
896
+ "sinhf" => f_host . sinh ( ) ,
897
+ "tanf" => f_host . tan ( ) ,
898
+ "tanhf" => f_host . tanh ( ) ,
899
+ "acosf" => f_host . acos ( ) ,
900
+ "asinf" => f_host . asin ( ) ,
901
+ "atanf" => f_host . atan ( ) ,
902
+ "log1pf" => f_host . ln_1p ( ) ,
903
+ "expm1f" => f_host . exp_m1 ( ) ,
904
+ "tgammaf" => f_host . gamma ( ) ,
903
905
_ => bug ! ( ) ,
904
906
} ;
905
- this. write_scalar ( Scalar :: from_u32 ( res. to_bits ( ) ) , dest) ?;
907
+ let res = res. to_soft ( ) ;
908
+ let res = this. adjust_nan ( res, & [ f] ) ;
909
+ this. write_scalar ( res, dest) ?;
906
910
}
907
911
#[ rustfmt:: skip]
908
912
| "_hypotf"
@@ -911,19 +915,20 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
911
915
| "fdimf"
912
916
=> {
913
917
let [ f1, f2] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
918
+ let f1 = this. read_scalar ( f1) ?. to_f32 ( ) ?;
919
+ let f2 = this. read_scalar ( f2) ?. to_f32 ( ) ?;
914
920
// underscore case for windows, here and below
915
921
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
916
922
// FIXME: Using host floats.
917
- let f1 = f32:: from_bits ( this. read_scalar ( f1) ?. to_u32 ( ) ?) ;
918
- let f2 = f32:: from_bits ( this. read_scalar ( f2) ?. to_u32 ( ) ?) ;
919
923
let res = match link_name. as_str ( ) {
920
- "_hypotf" | "hypotf" => f1. hypot ( f2) ,
921
- "atan2f" => f1. atan2 ( f2) ,
924
+ "_hypotf" | "hypotf" => f1. to_host ( ) . hypot ( f2. to_host ( ) ) . to_soft ( ) ,
925
+ "atan2f" => f1. to_host ( ) . atan2 ( f2. to_host ( ) ) . to_soft ( ) ,
922
926
#[ allow( deprecated) ]
923
- "fdimf" => f1. abs_sub ( f2) ,
927
+ "fdimf" => f1. to_host ( ) . abs_sub ( f2. to_host ( ) ) . to_soft ( ) ,
924
928
_ => bug ! ( ) ,
925
929
} ;
926
- this. write_scalar ( Scalar :: from_u32 ( res. to_bits ( ) ) , dest) ?;
930
+ let res = this. adjust_nan ( res, & [ f1, f2] ) ;
931
+ this. write_scalar ( res, dest) ?;
927
932
}
928
933
#[ rustfmt:: skip]
929
934
| "cbrt"
@@ -939,23 +944,26 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
939
944
| "tgamma"
940
945
=> {
941
946
let [ f] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
947
+ let f = this. read_scalar ( f) ?. to_f64 ( ) ?;
942
948
// FIXME: Using host floats.
943
- let f = f64 :: from_bits ( this . read_scalar ( f ) ? . to_u64 ( ) ? ) ;
949
+ let f_host = f . to_host ( ) ;
944
950
let res = match link_name. as_str ( ) {
945
- "cbrt" => f . cbrt ( ) ,
946
- "cosh" => f . cosh ( ) ,
947
- "sinh" => f . sinh ( ) ,
948
- "tan" => f . tan ( ) ,
949
- "tanh" => f . tanh ( ) ,
950
- "acos" => f . acos ( ) ,
951
- "asin" => f . asin ( ) ,
952
- "atan" => f . atan ( ) ,
953
- "log1p" => f . ln_1p ( ) ,
954
- "expm1" => f . exp_m1 ( ) ,
955
- "tgamma" => f . gamma ( ) ,
951
+ "cbrt" => f_host . cbrt ( ) ,
952
+ "cosh" => f_host . cosh ( ) ,
953
+ "sinh" => f_host . sinh ( ) ,
954
+ "tan" => f_host . tan ( ) ,
955
+ "tanh" => f_host . tanh ( ) ,
956
+ "acos" => f_host . acos ( ) ,
957
+ "asin" => f_host . asin ( ) ,
958
+ "atan" => f_host . atan ( ) ,
959
+ "log1p" => f_host . ln_1p ( ) ,
960
+ "expm1" => f_host . exp_m1 ( ) ,
961
+ "tgamma" => f_host . gamma ( ) ,
956
962
_ => bug ! ( ) ,
957
963
} ;
958
- this. write_scalar ( Scalar :: from_u64 ( res. to_bits ( ) ) , dest) ?;
964
+ let res = res. to_soft ( ) ;
965
+ let res = this. adjust_nan ( res, & [ f] ) ;
966
+ this. write_scalar ( res, dest) ?;
959
967
}
960
968
#[ rustfmt:: skip]
961
969
| "_hypot"
@@ -964,17 +972,20 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
964
972
| "fdim"
965
973
=> {
966
974
let [ f1, f2] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
975
+ let f1 = this. read_scalar ( f1) ?. to_f64 ( ) ?;
976
+ let f2 = this. read_scalar ( f2) ?. to_f64 ( ) ?;
977
+ // underscore case for windows, here and below
978
+ // (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
967
979
// FIXME: Using host floats.
968
- let f1 = f64:: from_bits ( this. read_scalar ( f1) ?. to_u64 ( ) ?) ;
969
- let f2 = f64:: from_bits ( this. read_scalar ( f2) ?. to_u64 ( ) ?) ;
970
980
let res = match link_name. as_str ( ) {
971
- "_hypot" | "hypot" => f1. hypot ( f2) ,
972
- "atan2" => f1. atan2 ( f2) ,
981
+ "_hypot" | "hypot" => f1. to_host ( ) . hypot ( f2. to_host ( ) ) . to_soft ( ) ,
982
+ "atan2" => f1. to_host ( ) . atan2 ( f2. to_host ( ) ) . to_soft ( ) ,
973
983
#[ allow( deprecated) ]
974
- "fdim" => f1. abs_sub ( f2) ,
984
+ "fdim" => f1. to_host ( ) . abs_sub ( f2. to_host ( ) ) . to_soft ( ) ,
975
985
_ => bug ! ( ) ,
976
986
} ;
977
- this. write_scalar ( Scalar :: from_u64 ( res. to_bits ( ) ) , dest) ?;
987
+ let res = this. adjust_nan ( res, & [ f1, f2] ) ;
988
+ this. write_scalar ( res, dest) ?;
978
989
}
979
990
#[ rustfmt:: skip]
980
991
| "_ldexp"
@@ -987,27 +998,30 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
987
998
let exp = this. read_scalar ( exp) ?. to_i32 ( ) ?;
988
999
989
1000
let res = x. scalbn ( exp) ;
990
- this. write_scalar ( Scalar :: from_f64 ( res) , dest) ?;
1001
+ let res = this. adjust_nan ( res, & [ x] ) ;
1002
+ this. write_scalar ( res, dest) ?;
991
1003
}
992
1004
"lgammaf_r" => {
993
1005
let [ x, signp] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
994
- // FIXME: Using host floats.
995
- let x = f32:: from_bits ( this. read_scalar ( x) ?. to_u32 ( ) ?) ;
1006
+ let x = this. read_scalar ( x) ?. to_f32 ( ) ?;
996
1007
let signp = this. deref_pointer ( signp) ?;
997
1008
998
- let ( res, sign) = x. ln_gamma ( ) ;
1009
+ // FIXME: Using host floats.
1010
+ let ( res, sign) = x. to_host ( ) . ln_gamma ( ) ;
999
1011
this. write_int ( sign, & signp) ?;
1000
- this. write_scalar ( Scalar :: from_u32 ( res. to_bits ( ) ) , dest) ?;
1012
+ let res = this. adjust_nan ( res. to_soft ( ) , & [ x] ) ;
1013
+ this. write_scalar ( res, dest) ?;
1001
1014
}
1002
1015
"lgamma_r" => {
1003
1016
let [ x, signp] = this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
1004
- // FIXME: Using host floats.
1005
- let x = f64:: from_bits ( this. read_scalar ( x) ?. to_u64 ( ) ?) ;
1017
+ let x = this. read_scalar ( x) ?. to_f64 ( ) ?;
1006
1018
let signp = this. deref_pointer ( signp) ?;
1007
1019
1008
- let ( res, sign) = x. ln_gamma ( ) ;
1020
+ // FIXME: Using host floats.
1021
+ let ( res, sign) = x. to_host ( ) . ln_gamma ( ) ;
1009
1022
this. write_int ( sign, & signp) ?;
1010
- this. write_scalar ( Scalar :: from_u64 ( res. to_bits ( ) ) , dest) ?;
1023
+ let res = this. adjust_nan ( res. to_soft ( ) , & [ x] ) ;
1024
+ this. write_scalar ( res, dest) ?;
1011
1025
}
1012
1026
1013
1027
// LLVM intrinsics
0 commit comments