1
1
use rand:: Rng ;
2
- use rustc_apfloat:: { self , Float , Round } ;
2
+ use rustc_apfloat:: { self , Float , FloatConvert , Round } ;
3
3
use rustc_middle:: mir;
4
4
use rustc_middle:: ty:: { self , FloatTy } ;
5
5
6
6
use self :: helpers:: { ToHost , ToSoft } ;
7
7
use super :: check_intrinsic_arg_count;
8
8
use crate :: * ;
9
9
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
+
10
24
impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
11
25
pub trait EvalContextExt < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
12
26
fn emulate_math_intrinsic (
@@ -20,38 +34,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
20
34
21
35
match intrinsic_name {
22
36
// 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) ?,
55
41
56
42
"fmaf32" => {
57
43
let [ a, b, c] = check_intrinsic_arg_count ( args) ?;
0 commit comments