11use rand:: Rng ;
2- use rustc_apfloat:: { self , Float , Round } ;
2+ use rustc_apfloat:: { self , Float , FloatConvert , Round } ;
33use rustc_middle:: mir;
44use rustc_middle:: ty:: { self , FloatTy } ;
55
66use self :: helpers:: { ToHost , ToSoft } ;
77use super :: check_intrinsic_arg_count;
88use crate :: * ;
99
10+ fn sqrt < ' tcx , F : Float + FloatConvert < F > + Into < Scalar > > (
11+ this : & mut MiriInterpCx < ' tcx > ,
12+ args : & [ OpTy < ' tcx > ] ,
13+ dest : & MPlaceTy < ' tcx > ,
14+ ) -> InterpResult < ' tcx > {
15+ let [ f] = check_intrinsic_arg_count ( args) ?;
16+ let f = this. read_scalar ( f) ?;
17+ let f: F = f. to_float ( ) ?;
18+ // Sqrt is specified to be fully precise.
19+ let res = math:: sqrt ( f) ;
20+ let res = this. adjust_nan ( res, & [ f] ) ;
21+ this. write_scalar ( res, dest)
22+ }
23+
1024impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
1125pub trait EvalContextExt < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
1226 fn emulate_math_intrinsic (
@@ -20,38 +34,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
2034
2135 match intrinsic_name {
2236 // Operations we can do with soft-floats.
23- "sqrtf16" => {
24- let [ f] = check_intrinsic_arg_count ( args) ?;
25- let f = this. read_scalar ( f) ?. to_f16 ( ) ?;
26- // Sqrt is specified to be fully precise.
27- let res = math:: sqrt ( f) ;
28- let res = this. adjust_nan ( res, & [ f] ) ;
29- this. write_scalar ( res, dest) ?;
30- }
31- "sqrtf32" => {
32- let [ f] = check_intrinsic_arg_count ( args) ?;
33- let f = this. read_scalar ( f) ?. to_f32 ( ) ?;
34- // Sqrt is specified to be fully precise.
35- let res = math:: sqrt ( f) ;
36- let res = this. adjust_nan ( res, & [ f] ) ;
37- this. write_scalar ( res, dest) ?;
38- }
39- "sqrtf64" => {
40- let [ f] = check_intrinsic_arg_count ( args) ?;
41- let f = this. read_scalar ( f) ?. to_f64 ( ) ?;
42- // Sqrt is specified to be fully precise.
43- let res = math:: sqrt ( f) ;
44- let res = this. adjust_nan ( res, & [ f] ) ;
45- this. write_scalar ( res, dest) ?;
46- }
47- "sqrtf128" => {
48- let [ f] = check_intrinsic_arg_count ( args) ?;
49- let f = this. read_scalar ( f) ?. to_f128 ( ) ?;
50- // Sqrt is specified to be fully precise.
51- let res = math:: sqrt ( f) ;
52- let res = this. adjust_nan ( res, & [ f] ) ;
53- this. write_scalar ( res, dest) ?;
54- }
37+ "sqrtf16" => sqrt :: < rustc_apfloat:: ieee:: Half > ( this, args, dest) ?,
38+ "sqrtf32" => sqrt :: < rustc_apfloat:: ieee:: Single > ( this, args, dest) ?,
39+ "sqrtf64" => sqrt :: < rustc_apfloat:: ieee:: Double > ( this, args, dest) ?,
40+ "sqrtf128" => sqrt :: < rustc_apfloat:: ieee:: Quad > ( this, args, dest) ?,
5541
5642 "fmaf32" => {
5743 let [ a, b, c] = check_intrinsic_arg_count ( args) ?;
0 commit comments