1
+ use rustc_apfloat:: Float ;
1
2
use rustc:: mir;
2
3
use rustc:: mir:: interpret:: { InterpResult , PointerArithmetic } ;
3
4
use rustc:: ty:: layout:: { self , LayoutOf , Size } ;
@@ -186,7 +187,8 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
186
187
187
188
"sinf32" | "fabsf32" | "cosf32" | "sqrtf32" | "expf32" | "exp2f32" | "logf32" |
188
189
"log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" => {
189
- let f = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
190
+ // FIXME: Using host floats.
191
+ let f = f32:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ?) ;
190
192
let f = match intrinsic_name. get ( ) {
191
193
"sinf32" => f. sin ( ) ,
192
194
"fabsf32" => f. abs ( ) ,
@@ -202,12 +204,13 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
202
204
"truncf32" => f. trunc ( ) ,
203
205
_ => bug ! ( ) ,
204
206
} ;
205
- this. write_scalar ( Scalar :: from_f32 ( f ) , dest) ?;
207
+ this. write_scalar ( Scalar :: from_u32 ( f . to_bits ( ) ) , dest) ?;
206
208
}
207
209
208
210
"sinf64" | "fabsf64" | "cosf64" | "sqrtf64" | "expf64" | "exp2f64" | "logf64" |
209
211
"log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" => {
210
- let f = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
212
+ // FIXME: Using host floats.
213
+ let f = f64:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u64 ( ) ?) ;
211
214
let f = match intrinsic_name. get ( ) {
212
215
"sinf64" => f. sin ( ) ,
213
216
"fabsf64" => f. abs ( ) ,
@@ -223,7 +226,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
223
226
"truncf64" => f. trunc ( ) ,
224
227
_ => bug ! ( ) ,
225
228
} ;
226
- this. write_scalar ( Scalar :: from_f64 ( f ) , dest) ?;
229
+ this. write_scalar ( Scalar :: from_u64 ( f . to_bits ( ) ) , dest) ?;
227
230
}
228
231
229
232
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
@@ -240,6 +243,28 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
240
243
this. binop_ignore_overflow ( op, a, b, dest) ?;
241
244
}
242
245
246
+ "minnumf32" | "maxnumf32" => {
247
+ let a = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
248
+ let b = this. read_scalar ( args[ 1 ] ) ?. to_f32 ( ) ?;
249
+ let res = if intrinsic_name. get ( ) . starts_with ( "min" ) {
250
+ a. min ( b)
251
+ } else {
252
+ a. max ( b)
253
+ } ;
254
+ this. write_scalar ( Scalar :: from_f32 ( res) , dest) ?;
255
+ }
256
+
257
+ "minnumf64" | "maxnumf64" => {
258
+ let a = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
259
+ let b = this. read_scalar ( args[ 1 ] ) ?. to_f64 ( ) ?;
260
+ let res = if intrinsic_name. get ( ) . starts_with ( "min" ) {
261
+ a. min ( b)
262
+ } else {
263
+ a. max ( b)
264
+ } ;
265
+ this. write_scalar ( Scalar :: from_f64 ( res) , dest) ?;
266
+ }
267
+
243
268
"exact_div" => {
244
269
// Performs an exact division, resulting in undefined behavior where
245
270
// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
@@ -320,19 +345,21 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
320
345
}
321
346
322
347
"powf32" => {
323
- let f = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
324
- let f2 = this. read_scalar ( args[ 1 ] ) ?. to_f32 ( ) ?;
348
+ // FIXME: Using host floats.
349
+ let f = f32:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ?) ;
350
+ let f2 = f32:: from_bits ( this. read_scalar ( args[ 1 ] ) ?. to_u32 ( ) ?) ;
325
351
this. write_scalar (
326
- Scalar :: from_f32 ( f. powf ( f2) ) ,
352
+ Scalar :: from_u32 ( f. powf ( f2) . to_bits ( ) ) ,
327
353
dest,
328
354
) ?;
329
355
}
330
356
331
357
"powf64" => {
332
- let f = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
333
- let f2 = this. read_scalar ( args[ 1 ] ) ?. to_f64 ( ) ?;
358
+ // FIXME: Using host floats.
359
+ let f = f64:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u64 ( ) ?) ;
360
+ let f2 = f64:: from_bits ( this. read_scalar ( args[ 1 ] ) ?. to_u64 ( ) ?) ;
334
361
this. write_scalar (
335
- Scalar :: from_f64 ( f. powf ( f2) ) ,
362
+ Scalar :: from_u64 ( f. powf ( f2) . to_bits ( ) ) ,
336
363
dest,
337
364
) ?;
338
365
}
@@ -341,8 +368,9 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
341
368
let a = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
342
369
let b = this. read_scalar ( args[ 1 ] ) ?. to_f32 ( ) ?;
343
370
let c = this. read_scalar ( args[ 2 ] ) ?. to_f32 ( ) ?;
371
+ let res = a. mul_add ( b, c) . value ;
344
372
this. write_scalar (
345
- Scalar :: from_f32 ( a * b + c ) ,
373
+ Scalar :: from_f32 ( res ) ,
346
374
dest,
347
375
) ?;
348
376
}
@@ -351,26 +379,29 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
351
379
let a = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
352
380
let b = this. read_scalar ( args[ 1 ] ) ?. to_f64 ( ) ?;
353
381
let c = this. read_scalar ( args[ 2 ] ) ?. to_f64 ( ) ?;
382
+ let res = a. mul_add ( b, c) . value ;
354
383
this. write_scalar (
355
- Scalar :: from_f64 ( a * b + c ) ,
384
+ Scalar :: from_f64 ( res ) ,
356
385
dest,
357
386
) ?;
358
387
}
359
388
360
389
"powif32" => {
361
- let f = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
390
+ // FIXME: Using host floats.
391
+ let f = f32:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ?) ;
362
392
let i = this. read_scalar ( args[ 1 ] ) ?. to_i32 ( ) ?;
363
393
this. write_scalar (
364
- Scalar :: from_f32 ( f. powi ( i) ) ,
394
+ Scalar :: from_u32 ( f. powi ( i) . to_bits ( ) ) ,
365
395
dest,
366
396
) ?;
367
397
}
368
398
369
399
"powif64" => {
370
- let f = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
400
+ // FIXME: Using host floats.
401
+ let f = f64:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u64 ( ) ?) ;
371
402
let i = this. read_scalar ( args[ 1 ] ) ?. to_i32 ( ) ?;
372
403
this. write_scalar (
373
- Scalar :: from_f64 ( f. powi ( i) ) ,
404
+ Scalar :: from_u64 ( f. powi ( i) . to_bits ( ) ) ,
374
405
dest,
375
406
) ?;
376
407
}
0 commit comments