@@ -6,7 +6,6 @@ mod simd;
6
6
use std:: ops:: Neg ;
7
7
8
8
use rand:: Rng ;
9
- use rand:: rngs:: StdRng ;
10
9
use rustc_abi:: Size ;
11
10
use rustc_apfloat:: ieee:: { IeeeFloat , Semantics } ;
12
11
use rustc_apfloat:: { self , Float , Round } ;
@@ -18,6 +17,7 @@ use self::atomic::EvalContextExt as _;
18
17
use self :: helpers:: { ToHost , ToSoft , check_intrinsic_arg_count} ;
19
18
use self :: simd:: EvalContextExt as _;
20
19
use crate :: math:: { IeeeExt , apply_random_float_error_ulp} ;
20
+ use crate :: operator:: EvalContextExt as _;
21
21
use crate :: * ;
22
22
23
23
impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
@@ -490,15 +490,6 @@ fn apply_random_float_error_to_imm<'tcx>(
490
490
interp_ok ( ImmTy :: from_scalar_int ( res, val. layout ) )
491
491
}
492
492
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
-
502
493
/// For the intrinsics:
503
494
/// - sinf32, sinf64
504
495
/// - cosf32, cosf64
@@ -547,15 +538,17 @@ fn fixed_float_value<S: Semantics>(
547
538
// 1^y = 1 for any y, even a NaN, *but* not a SNaN
548
539
( "powf32" | "powf64" , [ base, exp] ) if * base == one => {
549
540
let rng = ecx. machine . rng . get_mut ( ) ;
541
+ let return_nan = ecx. machine . float_nondet && rng. random ( ) && exp. is_signaling ( ) ;
550
542
// 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 }
552
544
}
553
545
554
546
// x^(±0) = 1 for any x, even a NaN, *but* not a SNaN
555
547
( "powf32" | "powf64" , [ base, exp] ) if exp. is_zero ( ) => {
556
548
let rng = ecx. machine . rng . get_mut ( ) ;
549
+ let return_nan = ecx. machine . float_nondet && rng. random ( ) && base. is_signaling ( ) ;
557
550
// 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 }
559
552
}
560
553
561
554
// 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>(
576
569
0 => {
577
570
let one = IeeeFloat :: < S > :: one ( ) ;
578
571
let rng = ecx. machine . rng . get_mut ( ) ;
572
+ let return_nan = ecx. machine . float_nondet && rng. random ( ) && base. is_signaling ( ) ;
579
573
Some (
580
574
// 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 } ,
582
576
)
583
577
}
584
578
0 commit comments