@@ -10,7 +10,7 @@ use rustc_abi::Size;
1010use rustc_apfloat:: ieee:: { IeeeFloat , Semantics } ;
1111use rustc_apfloat:: { self , Float , Round } ;
1212use rustc_middle:: mir;
13- use rustc_middle:: ty:: { self , FloatTy , ScalarInt } ;
13+ use rustc_middle:: ty:: { self , FloatTy } ;
1414use rustc_span:: { Symbol , sym} ;
1515
1616use self :: atomic:: EvalContextExt as _;
@@ -230,7 +230,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
230230 let res = apply_random_float_error_ulp (
231231 this,
232232 res,
233- 2 , // log2(4)
233+ 4 ,
234234 ) ;
235235
236236 // 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> {
274274 let res = apply_random_float_error_ulp (
275275 this,
276276 res,
277- 2 , // log2(4)
277+ 4 ,
278278 ) ;
279279
280280 // 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> {
336336
337337 // Apply a relative error of 4ULP to introduce some non-determinism
338338 // 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 )
342340 } ) ;
343341 let res = this. adjust_nan ( res, & [ f1, f2] ) ;
344342 this. write_scalar ( res, dest) ?;
@@ -354,9 +352,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354352
355353 // Apply a relative error of 4ULP to introduce some non-determinism
356354 // 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 )
360356 } ) ;
361357 let res = this. adjust_nan ( res, & [ f1, f2] ) ;
362358 this. write_scalar ( res, dest) ?;
@@ -373,9 +369,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
373369
374370 // Apply a relative error of 4ULP to introduce some non-determinism
375371 // 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 )
379373 } ) ;
380374 let res = this. adjust_nan ( res, & [ f] ) ;
381375 this. write_scalar ( res, dest) ?;
@@ -391,9 +385,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
391385
392386 // Apply a relative error of 4ULP to introduce some non-determinism
393387 // 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 )
397389 } ) ;
398390 let res = this. adjust_nan ( res, & [ f] ) ;
399391 this. write_scalar ( res, dest) ?;
@@ -448,7 +440,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
448440 }
449441 // Apply a relative error of 4ULP to simulate non-deterministic precision loss
450442 // 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 ) ?;
452444 this. write_immediate ( * res, dest) ?;
453445 }
454446
@@ -486,31 +478,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
486478 }
487479}
488480
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-
514481/// For the intrinsics:
515482/// - sinf32, sinf64
516483/// - cosf32, cosf64
0 commit comments