@@ -10,7 +10,7 @@ use rustc_abi::Size;
10
10
use rustc_apfloat:: ieee:: { IeeeFloat , Semantics } ;
11
11
use rustc_apfloat:: { self , Float , Round } ;
12
12
use rustc_middle:: mir;
13
- use rustc_middle:: ty:: { self , FloatTy , ScalarInt } ;
13
+ use rustc_middle:: ty:: { self , FloatTy } ;
14
14
use rustc_span:: { Symbol , sym} ;
15
15
16
16
use self :: atomic:: EvalContextExt as _;
@@ -230,7 +230,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
230
230
let res = apply_random_float_error_ulp (
231
231
this,
232
232
res,
233
- 2 , // log2(4)
233
+ 4 ,
234
234
) ;
235
235
236
236
// Clamp the result to the guaranteed range of this function according to the C standard,
@@ -274,7 +274,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
274
274
let res = apply_random_float_error_ulp (
275
275
this,
276
276
res,
277
- 2 , // log2(4)
277
+ 4 ,
278
278
) ;
279
279
280
280
// Clamp the result to the guaranteed range of this function according to the C standard,
@@ -336,9 +336,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
336
336
337
337
// Apply a relative error of 4ULP to introduce some non-determinism
338
338
// simulating imprecise implementations and optimizations.
339
- apply_random_float_error_ulp (
340
- this, res, 2 , // log2(4)
341
- )
339
+ apply_random_float_error_ulp ( this, res, 4 )
342
340
} ) ;
343
341
let res = this. adjust_nan ( res, & [ f1, f2] ) ;
344
342
this. write_scalar ( res, dest) ?;
@@ -354,9 +352,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354
352
355
353
// Apply a relative error of 4ULP to introduce some non-determinism
356
354
// simulating imprecise implementations and optimizations.
357
- apply_random_float_error_ulp (
358
- this, res, 2 , // log2(4)
359
- )
355
+ apply_random_float_error_ulp ( this, res, 4 )
360
356
} ) ;
361
357
let res = this. adjust_nan ( res, & [ f1, f2] ) ;
362
358
this. write_scalar ( res, dest) ?;
@@ -373,9 +369,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
373
369
374
370
// Apply a relative error of 4ULP to introduce some non-determinism
375
371
// simulating imprecise implementations and optimizations.
376
- apply_random_float_error_ulp (
377
- this, res, 2 , // log2(4)
378
- )
372
+ apply_random_float_error_ulp ( this, res, 4 )
379
373
} ) ;
380
374
let res = this. adjust_nan ( res, & [ f] ) ;
381
375
this. write_scalar ( res, dest) ?;
@@ -391,9 +385,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
391
385
392
386
// Apply a relative error of 4ULP to introduce some non-determinism
393
387
// simulating imprecise implementations and optimizations.
394
- apply_random_float_error_ulp (
395
- this, res, 2 , // log2(4)
396
- )
388
+ apply_random_float_error_ulp ( this, res, 4 )
397
389
} ) ;
398
390
let res = this. adjust_nan ( res, & [ f] ) ;
399
391
this. write_scalar ( res, dest) ?;
@@ -448,7 +440,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
448
440
}
449
441
// Apply a relative error of 4ULP to simulate non-deterministic precision loss
450
442
// due to optimizations.
451
- let res = apply_random_float_error_to_imm ( this, res, 2 /* log2(4) */ ) ?;
443
+ let res = crate :: math :: apply_random_float_error_to_imm ( this, res, 4 ) ?;
452
444
this. write_immediate ( * res, dest) ?;
453
445
}
454
446
@@ -486,31 +478,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
486
478
}
487
479
}
488
480
489
- /// Applies a random ULP floating point error to `val` and returns the new value.
490
- /// So if you want an X ULP error, `ulp_exponent` should be log2(X).
491
- ///
492
- /// Will fail if `val` is not a floating point number.
493
- fn apply_random_float_error_to_imm < ' tcx > (
494
- ecx : & mut MiriInterpCx < ' tcx > ,
495
- val : ImmTy < ' tcx > ,
496
- ulp_exponent : u32 ,
497
- ) -> InterpResult < ' tcx , ImmTy < ' tcx > > {
498
- let scalar = val. to_scalar_int ( ) ?;
499
- let res: ScalarInt = match val. layout . ty . kind ( ) {
500
- ty:: Float ( FloatTy :: F16 ) =>
501
- apply_random_float_error_ulp ( ecx, scalar. to_f16 ( ) , ulp_exponent) . into ( ) ,
502
- ty:: Float ( FloatTy :: F32 ) =>
503
- apply_random_float_error_ulp ( ecx, scalar. to_f32 ( ) , ulp_exponent) . into ( ) ,
504
- ty:: Float ( FloatTy :: F64 ) =>
505
- apply_random_float_error_ulp ( ecx, scalar. to_f64 ( ) , ulp_exponent) . into ( ) ,
506
- ty:: Float ( FloatTy :: F128 ) =>
507
- apply_random_float_error_ulp ( ecx, scalar. to_f128 ( ) , ulp_exponent) . into ( ) ,
508
- _ => bug ! ( "intrinsic called with non-float input type" ) ,
509
- } ;
510
-
511
- interp_ok ( ImmTy :: from_scalar_int ( res, val. layout ) )
512
- }
513
-
514
481
/// For the intrinsics:
515
482
/// - sinf32, sinf64
516
483
/// - cosf32, cosf64
0 commit comments