Skip to content

Commit 7cf0870

Browse files
authored
Rollup merge of #142340 - RalfJung:miri-apfloat-mul-add, r=oli-obk
miri: we can use apfloat's mul_add now With rust-lang/rustc_apfloat#11 fixed, there is no reason to still use host floats here. Fixes rust-lang/miri#2995 We already have a test for this: https://github.com/rust-lang/rust/blob/a7153db254acc387e271e75153bdbd3caa2bed89/src/tools/miri/tests/pass/float.rs#L998-L1003 r? ``@oli-obk``
2 parents b24473c + f5d24e9 commit 7cf0870

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,9 +3234,9 @@ dependencies = [
32343234

32353235
[[package]]
32363236
name = "rustc_apfloat"
3237-
version = "0.2.2+llvm-462a31f5a5ab"
3237+
version = "0.2.3+llvm-462a31f5a5ab"
32383238
source = "registry+https://github.com/rust-lang/crates.io-index"
3239-
checksum = "121e2195ff969977a4e2b5c9965ea867fce7e4cb5aee5b09dee698a7932d574f"
3239+
checksum = "486c2179b4796f65bfe2ee33679acf0927ac83ecf583ad6c91c3b4570911b9ad"
32403240
dependencies = [
32413241
"bitflags",
32423242
"smallvec",

src/tools/miri/src/intrinsics/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
272272
let a = this.read_scalar(a)?.to_f32()?;
273273
let b = this.read_scalar(b)?.to_f32()?;
274274
let c = this.read_scalar(c)?.to_f32()?;
275-
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
276-
let res = a.to_host().mul_add(b.to_host(), c.to_host()).to_soft();
275+
let res = a.mul_add(b, c).value;
277276
let res = this.adjust_nan(res, &[a, b, c]);
278277
this.write_scalar(res, dest)?;
279278
}
@@ -282,8 +281,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
282281
let a = this.read_scalar(a)?.to_f64()?;
283282
let b = this.read_scalar(b)?.to_f64()?;
284283
let c = this.read_scalar(c)?.to_f64()?;
285-
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
286-
let res = a.to_host().mul_add(b.to_host(), c.to_host()).to_soft();
284+
let res = a.mul_add(b, c).value;
287285
let res = this.adjust_nan(res, &[a, b, c]);
288286
this.write_scalar(res, dest)?;
289287
}
@@ -295,8 +293,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
295293
let c = this.read_scalar(c)?.to_f32()?;
296294
let fuse: bool = this.machine.rng.get_mut().random();
297295
let res = if fuse {
298-
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
299-
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
296+
a.mul_add(b, c).value
300297
} else {
301298
((a * b).value + c).value
302299
};
@@ -310,8 +307,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
310307
let c = this.read_scalar(c)?.to_f64()?;
311308
let fuse: bool = this.machine.rng.get_mut().random();
312309
let res = if fuse {
313-
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
314-
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
310+
a.mul_add(b, c).value
315311
} else {
316312
((a * b).value + c).value
317313
};

src/tools/miri/src/intrinsics/simd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
320320
let b = b.to_f32()?;
321321
let c = c.to_f32()?;
322322
let res = if fuse {
323-
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
323+
a.mul_add(b, c).value
324324
} else {
325325
((a * b).value + c).value
326326
};
@@ -332,7 +332,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
332332
let b = b.to_f64()?;
333333
let c = c.to_f64()?;
334334
let res = if fuse {
335-
a.to_host().mul_add(b.to_host(), c.to_host()).to_soft()
335+
a.mul_add(b, c).value
336336
} else {
337337
((a * b).value + c).value
338338
};

0 commit comments

Comments
 (0)