Skip to content

Commit 6eab94a

Browse files
committed
fix from to/from f32/f64 changes
1 parent 48897d0 commit 6eab94a

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/fn_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
758758
this.machine.last_error = err;
759759
}
760760
"GetLastError" => {
761-
this.write_scalar(Scalar::from_uint(this.machine.last_error, Size::from_bits(32)), dest)?;
761+
this.write_scalar(Scalar::from_u32(this.machine.last_error), dest)?;
762762
}
763763

764764
"AddVectoredExceptionHandler" => {
@@ -854,7 +854,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
854854
};
855855
// If there was no error, write back how much was written.
856856
if let Some(n) = written {
857-
this.write_scalar(Scalar::from_uint(n, Size::from_bits(32)), written_place.into())?;
857+
this.write_scalar(Scalar::from_u32(n), written_place.into())?;
858858
}
859859
// Return whether this was a success.
860860
this.write_scalar(

src/intrinsic.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
186186

187187
"sinf32" | "fabsf32" | "cosf32" | "sqrtf32" | "expf32" | "exp2f32" | "logf32" |
188188
"log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" => {
189-
let f = this.read_scalar(args[0])?.to_f32()?;
189+
// FIXME: Using host floats.
190+
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
190191
let f = match intrinsic_name.get() {
191192
"sinf32" => f.sin(),
192193
"fabsf32" => f.abs(),
@@ -202,12 +203,13 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
202203
"truncf32" => f.trunc(),
203204
_ => bug!(),
204205
};
205-
this.write_scalar(Scalar::from_f32(f), dest)?;
206+
this.write_scalar(Scalar::from_u32(f.to_bits()), dest)?;
206207
}
207208

208209
"sinf64" | "fabsf64" | "cosf64" | "sqrtf64" | "expf64" | "exp2f64" | "logf64" |
209210
"log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" => {
210-
let f = this.read_scalar(args[0])?.to_f64()?;
211+
// FIXME: Using host floats.
212+
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
211213
let f = match intrinsic_name.get() {
212214
"sinf64" => f.sin(),
213215
"fabsf64" => f.abs(),
@@ -223,7 +225,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
223225
"truncf64" => f.trunc(),
224226
_ => bug!(),
225227
};
226-
this.write_scalar(Scalar::from_f64(f), dest)?;
228+
this.write_scalar(Scalar::from_u64(f.to_bits()), dest)?;
227229
}
228230

229231
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
@@ -320,19 +322,21 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
320322
}
321323

322324
"powf32" => {
323-
let f = this.read_scalar(args[0])?.to_f32()?;
324-
let f2 = this.read_scalar(args[1])?.to_f32()?;
325+
// FIXME: Using host floats.
326+
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
327+
let f2 = f32::from_bits(this.read_scalar(args[1])?.to_u32()?);
325328
this.write_scalar(
326-
Scalar::from_f32(f.powf(f2)),
329+
Scalar::from_u32(f.powf(f2).to_bits()),
327330
dest,
328331
)?;
329332
}
330333

331334
"powf64" => {
332-
let f = this.read_scalar(args[0])?.to_f64()?;
333-
let f2 = this.read_scalar(args[1])?.to_f64()?;
335+
// FIXME: Using host floats.
336+
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
337+
let f2 = f64::from_bits(this.read_scalar(args[1])?.to_u64()?);
334338
this.write_scalar(
335-
Scalar::from_f64(f.powf(f2)),
339+
Scalar::from_u64(f.powf(f2).to_bits()),
336340
dest,
337341
)?;
338342
}
@@ -341,8 +345,9 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
341345
let a = this.read_scalar(args[0])?.to_f32()?;
342346
let b = this.read_scalar(args[1])?.to_f32()?;
343347
let c = this.read_scalar(args[2])?.to_f32()?;
348+
let res = (a*b).value + c;
344349
this.write_scalar(
345-
Scalar::from_f32(a * b + c),
350+
Scalar::from_f32(res.value),
346351
dest,
347352
)?;
348353
}
@@ -351,26 +356,29 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
351356
let a = this.read_scalar(args[0])?.to_f64()?;
352357
let b = this.read_scalar(args[1])?.to_f64()?;
353358
let c = this.read_scalar(args[2])?.to_f64()?;
359+
let res = (a*b).value + c;
354360
this.write_scalar(
355-
Scalar::from_f64(a * b + c),
361+
Scalar::from_f64(res.value),
356362
dest,
357363
)?;
358364
}
359365

360366
"powif32" => {
361-
let f = this.read_scalar(args[0])?.to_f32()?;
367+
// FIXME: Using host floats.
368+
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
362369
let i = this.read_scalar(args[1])?.to_i32()?;
363370
this.write_scalar(
364-
Scalar::from_f32(f.powi(i)),
371+
Scalar::from_u32(f.powi(i).to_bits()),
365372
dest,
366373
)?;
367374
}
368375

369376
"powif64" => {
370-
let f = this.read_scalar(args[0])?.to_f64()?;
377+
// FIXME: Using host floats.
378+
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
371379
let i = this.read_scalar(args[1])?.to_i32()?;
372380
this.write_scalar(
373-
Scalar::from_f64(f.powi(i)),
381+
Scalar::from_u64(f.powi(i).to_bits()),
374382
dest,
375383
)?;
376384
}

0 commit comments

Comments
 (0)