@@ -6,7 +6,6 @@ mod simd;
66use std:: ops:: Neg ;
77
88use rand:: Rng ;
9- use rand:: rngs:: StdRng ;
109use rustc_abi:: Size ;
1110use rustc_apfloat:: ieee:: { IeeeFloat , Semantics } ;
1211use rustc_apfloat:: { self , Float , Round } ;
@@ -18,6 +17,7 @@ use self::atomic::EvalContextExt as _;
1817use self :: helpers:: { ToHost , ToSoft , check_intrinsic_arg_count} ;
1918use self :: simd:: EvalContextExt as _;
2019use crate :: math:: { IeeeExt , apply_random_float_error_ulp} ;
20+ use crate :: operator:: EvalContextExt as _;
2121use crate :: * ;
2222
2323impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
@@ -490,15 +490,6 @@ fn apply_random_float_error_to_imm<'tcx>(
490490 interp_ok ( ImmTy :: from_scalar_int ( res, val. layout ) )
491491}
492492
493- /// Returns either a SNaN or a QNaN, with a randomly generated payload.
494- fn random_nan < S : Semantics > ( rng : & mut StdRng ) -> IeeeFloat < S > {
495- if rng. random ( ) {
496- IeeeFloat :: < S > :: snan ( Some ( rng. random ( ) ) )
497- } else {
498- IeeeFloat :: < S > :: qnan ( Some ( rng. random ( ) ) )
499- }
500- }
501-
502493/// For the intrinsics:
503494/// - sinf32, sinf64
504495/// - cosf32, cosf64
@@ -547,15 +538,17 @@ fn fixed_float_value<S: Semantics>(
547538 // 1^y = 1 for any y, even a NaN, *but* not a SNaN
548539 ( "powf32" | "powf64" , [ base, exp] ) if * base == one => {
549540 let rng = ecx. machine . rng . get_mut ( ) ;
541+ let return_nan = ecx. machine . float_nondet && rng. random ( ) && exp. is_signaling ( ) ;
550542 // Handle both the musl and glibc cases non-deterministically.
551- if !exp . is_signaling ( ) || rng . random ( ) { one } else { random_nan ( rng ) }
543+ if return_nan { ecx . generate_nan ( args ) } else { one }
552544 }
553545
554546 // x^(±0) = 1 for any x, even a NaN, *but* not a SNaN
555547 ( "powf32" | "powf64" , [ base, exp] ) if exp. is_zero ( ) => {
556548 let rng = ecx. machine . rng . get_mut ( ) ;
549+ let return_nan = ecx. machine . float_nondet && rng. random ( ) && base. is_signaling ( ) ;
557550 // Handle both the musl and glibc cases non-deterministically.
558- if !base . is_signaling ( ) || rng . random ( ) { one } else { random_nan ( rng ) }
551+ if return_nan { ecx . generate_nan ( args ) } else { one }
559552 }
560553
561554 // There are a lot of cases for fixed outputs according to the C Standard, but these are mainly INF or zero
@@ -576,9 +569,10 @@ fn fixed_powi_float_value<S: Semantics>(
576569 0 => {
577570 let one = IeeeFloat :: < S > :: one ( ) ;
578571 let rng = ecx. machine . rng . get_mut ( ) ;
572+ let return_nan = ecx. machine . float_nondet && rng. random ( ) && base. is_signaling ( ) ;
579573 Some (
580574 // Handle both the musl and glibc powf cases non-deterministically.
581- if !base . is_signaling ( ) || rng . random ( ) { one } else { random_nan ( rng ) } ,
575+ if return_nan { ecx . generate_nan ( & [ base ] ) } else { one } ,
582576 )
583577 }
584578
0 commit comments