1+ use rustc_apfloat:: Float ;
12use rustc:: mir;
23use rustc:: mir:: interpret:: { InterpResult , PointerArithmetic } ;
34use rustc:: ty:: layout:: { self , LayoutOf , Size } ;
@@ -186,7 +187,8 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
186187
187188 "sinf32" | "fabsf32" | "cosf32" | "sqrtf32" | "expf32" | "exp2f32" | "logf32" |
188189 "log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" => {
189- let f = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
190+ // FIXME: Using host floats.
191+ let f = f32:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ?) ;
190192 let f = match intrinsic_name. get ( ) {
191193 "sinf32" => f. sin ( ) ,
192194 "fabsf32" => f. abs ( ) ,
@@ -202,12 +204,13 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
202204 "truncf32" => f. trunc ( ) ,
203205 _ => bug ! ( ) ,
204206 } ;
205- this. write_scalar ( Scalar :: from_f32 ( f ) , dest) ?;
207+ this. write_scalar ( Scalar :: from_u32 ( f . to_bits ( ) ) , dest) ?;
206208 }
207209
208210 "sinf64" | "fabsf64" | "cosf64" | "sqrtf64" | "expf64" | "exp2f64" | "logf64" |
209211 "log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" => {
210- let f = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
212+ // FIXME: Using host floats.
213+ let f = f64:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u64 ( ) ?) ;
211214 let f = match intrinsic_name. get ( ) {
212215 "sinf64" => f. sin ( ) ,
213216 "fabsf64" => f. abs ( ) ,
@@ -223,7 +226,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
223226 "truncf64" => f. trunc ( ) ,
224227 _ => bug ! ( ) ,
225228 } ;
226- this. write_scalar ( Scalar :: from_f64 ( f ) , dest) ?;
229+ this. write_scalar ( Scalar :: from_u64 ( f . to_bits ( ) ) , dest) ?;
227230 }
228231
229232 "fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
@@ -240,6 +243,28 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
240243 this. binop_ignore_overflow ( op, a, b, dest) ?;
241244 }
242245
246+ "minnumf32" | "maxnumf32" => {
247+ let a = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
248+ let b = this. read_scalar ( args[ 1 ] ) ?. to_f32 ( ) ?;
249+ let res = if intrinsic_name. get ( ) . starts_with ( "min" ) {
250+ a. min ( b)
251+ } else {
252+ a. max ( b)
253+ } ;
254+ this. write_scalar ( Scalar :: from_f32 ( res) , dest) ?;
255+ }
256+
257+ "minnumf64" | "maxnumf64" => {
258+ let a = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
259+ let b = this. read_scalar ( args[ 1 ] ) ?. to_f64 ( ) ?;
260+ let res = if intrinsic_name. get ( ) . starts_with ( "min" ) {
261+ a. min ( b)
262+ } else {
263+ a. max ( b)
264+ } ;
265+ this. write_scalar ( Scalar :: from_f64 ( res) , dest) ?;
266+ }
267+
243268 "exact_div" => {
244269 // Performs an exact division, resulting in undefined behavior where
245270 // `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
@@ -320,19 +345,21 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
320345 }
321346
322347 "powf32" => {
323- let f = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
324- let f2 = this. read_scalar ( args[ 1 ] ) ?. to_f32 ( ) ?;
348+ // FIXME: Using host floats.
349+ let f = f32:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ?) ;
350+ let f2 = f32:: from_bits ( this. read_scalar ( args[ 1 ] ) ?. to_u32 ( ) ?) ;
325351 this. write_scalar (
326- Scalar :: from_f32 ( f. powf ( f2) ) ,
352+ Scalar :: from_u32 ( f. powf ( f2) . to_bits ( ) ) ,
327353 dest,
328354 ) ?;
329355 }
330356
331357 "powf64" => {
332- let f = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
333- let f2 = this. read_scalar ( args[ 1 ] ) ?. to_f64 ( ) ?;
358+ // FIXME: Using host floats.
359+ let f = f64:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u64 ( ) ?) ;
360+ let f2 = f64:: from_bits ( this. read_scalar ( args[ 1 ] ) ?. to_u64 ( ) ?) ;
334361 this. write_scalar (
335- Scalar :: from_f64 ( f. powf ( f2) ) ,
362+ Scalar :: from_u64 ( f. powf ( f2) . to_bits ( ) ) ,
336363 dest,
337364 ) ?;
338365 }
@@ -341,8 +368,9 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
341368 let a = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
342369 let b = this. read_scalar ( args[ 1 ] ) ?. to_f32 ( ) ?;
343370 let c = this. read_scalar ( args[ 2 ] ) ?. to_f32 ( ) ?;
371+ let res = a. mul_add ( b, c) . value ;
344372 this. write_scalar (
345- Scalar :: from_f32 ( a * b + c ) ,
373+ Scalar :: from_f32 ( res ) ,
346374 dest,
347375 ) ?;
348376 }
@@ -351,26 +379,29 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
351379 let a = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
352380 let b = this. read_scalar ( args[ 1 ] ) ?. to_f64 ( ) ?;
353381 let c = this. read_scalar ( args[ 2 ] ) ?. to_f64 ( ) ?;
382+ let res = a. mul_add ( b, c) . value ;
354383 this. write_scalar (
355- Scalar :: from_f64 ( a * b + c ) ,
384+ Scalar :: from_f64 ( res ) ,
356385 dest,
357386 ) ?;
358387 }
359388
360389 "powif32" => {
361- let f = this. read_scalar ( args[ 0 ] ) ?. to_f32 ( ) ?;
390+ // FIXME: Using host floats.
391+ let f = f32:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u32 ( ) ?) ;
362392 let i = this. read_scalar ( args[ 1 ] ) ?. to_i32 ( ) ?;
363393 this. write_scalar (
364- Scalar :: from_f32 ( f. powi ( i) ) ,
394+ Scalar :: from_u32 ( f. powi ( i) . to_bits ( ) ) ,
365395 dest,
366396 ) ?;
367397 }
368398
369399 "powif64" => {
370- let f = this. read_scalar ( args[ 0 ] ) ?. to_f64 ( ) ?;
400+ // FIXME: Using host floats.
401+ let f = f64:: from_bits ( this. read_scalar ( args[ 0 ] ) ?. to_u64 ( ) ?) ;
371402 let i = this. read_scalar ( args[ 1 ] ) ?. to_i32 ( ) ?;
372403 this. write_scalar (
373- Scalar :: from_f64 ( f. powi ( i) ) ,
404+ Scalar :: from_u64 ( f. powi ( i) . to_bits ( ) ) ,
374405 dest,
375406 ) ?;
376407 }
0 commit comments