De-duplicate and move adjust_nan
to InterpCx
This commit is contained in:
parent
8f8bee4f60
commit
b73e613e00
@ -334,19 +334,6 @@ fn cast_from_float<F>(&self, f: F, dest_ty: Ty<'tcx>) -> Scalar<M::Provenance>
|
||||
{
|
||||
use rustc_type_ir::TyKind::*;
|
||||
|
||||
fn adjust_nan<
|
||||
'tcx,
|
||||
M: Machine<'tcx>,
|
||||
F1: rustc_apfloat::Float + FloatConvert<F2>,
|
||||
F2: rustc_apfloat::Float,
|
||||
>(
|
||||
ecx: &InterpCx<'tcx, M>,
|
||||
f1: F1,
|
||||
f2: F2,
|
||||
) -> F2 {
|
||||
if f2.is_nan() { M::generate_nan(ecx, &[f1]) } else { f2 }
|
||||
}
|
||||
|
||||
match *dest_ty.kind() {
|
||||
// float -> uint
|
||||
Uint(t) => {
|
||||
@ -367,11 +354,17 @@ fn adjust_nan<
|
||||
}
|
||||
// float -> float
|
||||
Float(fty) => match fty {
|
||||
FloatTy::F16 => Scalar::from_f16(adjust_nan(self, f, f.convert(&mut false).value)),
|
||||
FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value)),
|
||||
FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value)),
|
||||
FloatTy::F16 => {
|
||||
Scalar::from_f16(self.adjust_nan(f.convert(&mut false).value, &[f]))
|
||||
}
|
||||
FloatTy::F32 => {
|
||||
Scalar::from_f32(self.adjust_nan(f.convert(&mut false).value, &[f]))
|
||||
}
|
||||
FloatTy::F64 => {
|
||||
Scalar::from_f64(self.adjust_nan(f.convert(&mut false).value, &[f]))
|
||||
}
|
||||
FloatTy::F128 => {
|
||||
Scalar::from_f128(adjust_nan(self, f, f.convert(&mut false).value))
|
||||
Scalar::from_f128(self.adjust_nan(f.convert(&mut false).value, &[f]))
|
||||
}
|
||||
},
|
||||
// That's it.
|
||||
|
@ -599,6 +599,14 @@ pub fn dump_place(&self, place: &PlaceTy<'tcx, M::Provenance>) -> PlacePrinter<'
|
||||
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
|
||||
Frame::generate_stacktrace_from_stack(self.stack())
|
||||
}
|
||||
|
||||
pub fn adjust_nan<F1, F2>(&self, f: F2, inputs: &[F1]) -> F2
|
||||
where
|
||||
F1: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F2>,
|
||||
F2: rustc_apfloat::Float,
|
||||
{
|
||||
if f.is_nan() { M::generate_nan(self, inputs) } else { f }
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
|
@ -64,8 +64,7 @@ fn binary_float_op<F: Float + FloatConvert<F> + Into<Scalar<M::Provenance>>>(
|
||||
use rustc_middle::mir::BinOp::*;
|
||||
|
||||
// Performs appropriate non-deterministic adjustments of NaN results.
|
||||
let adjust_nan =
|
||||
|f: F| -> F { if f.is_nan() { M::generate_nan(self, &[l, r]) } else { f } };
|
||||
let adjust_nan = |f: F| -> F { self.adjust_nan(f, &[l, r]) };
|
||||
|
||||
match bin_op {
|
||||
Eq => ImmTy::from_bool(l == r, *self.tcx),
|
||||
|
@ -115,8 +115,4 @@ fn make_signaling<F: Float>(f: F) -> Option<F> {
|
||||
nan
|
||||
}
|
||||
}
|
||||
|
||||
fn adjust_nan<F1: Float + FloatConvert<F2>, F2: Float>(&self, f: F2, inputs: &[F1]) -> F2 {
|
||||
if f.is_nan() { self.generate_nan(inputs) } else { f }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user