11use std:: assert_matches:: assert_matches;
22
3- use rustc_apfloat:: ieee:: { Double , Single } ;
3+ use rustc_apfloat:: ieee:: { Double , Half , Quad , Single } ;
44use rustc_apfloat:: { Float , FloatConvert } ;
55use rustc_middle:: mir:: interpret:: { InterpResult , PointerArithmetic , Scalar } ;
66use rustc_middle:: mir:: CastKind ;
@@ -187,10 +187,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
187187bug ! ( "FloatToFloat/FloatToInt cast: source type {} is not a float type" , src. layout. ty)
188188} ;
189189let val =match fty{
190- FloatTy :: F16 =>unimplemented ! ( "f16_f128" ) ,
190+ FloatTy :: F16 =>self . cast_from_float ( src . to_scalar ( ) . to_f16 ( ) ? , cast_to . ty ) ,
191191FloatTy :: F32 =>self . cast_from_float ( src. to_scalar ( ) . to_f32 ( ) ?, cast_to. ty ) ,
192192FloatTy :: F64 =>self . cast_from_float ( src. to_scalar ( ) . to_f64 ( ) ?, cast_to. ty ) ,
193- FloatTy :: F128 =>unimplemented ! ( "f16_f128" ) ,
193+ FloatTy :: F128 =>self . cast_from_float ( src . to_scalar ( ) . to_f128 ( ) ? , cast_to . ty ) ,
194194} ;
195195Ok ( ImmTy :: from_scalar ( val, cast_to) )
196196}
@@ -296,18 +296,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
296296Float ( fty) if signed =>{
297297let v = vas i128 ;
298298match fty{
299- FloatTy :: F16 =>unimplemented ! ( "f16_f128" ) ,
299+ FloatTy :: F16 =>Scalar :: from_f16 ( Half :: from_i128 ( v ) . value ) ,
300300FloatTy :: F32 =>Scalar :: from_f32 ( Single :: from_i128 ( v) . value ) ,
301301FloatTy :: F64 =>Scalar :: from_f64 ( Double :: from_i128 ( v) . value ) ,
302- FloatTy :: F128 =>unimplemented ! ( "f16_f128" ) ,
302+ FloatTy :: F128 =>Scalar :: from_f128 ( Quad :: from_i128 ( v ) . value ) ,
303303}
304304}
305305// unsigned int -> float
306306Float ( fty) =>match fty{
307- FloatTy :: F16 =>unimplemented ! ( "f16_f128" ) ,
307+ FloatTy :: F16 =>Scalar :: from_f16 ( Half :: from_u128 ( v ) . value ) ,
308308FloatTy :: F32 =>Scalar :: from_f32 ( Single :: from_u128 ( v) . value ) ,
309309FloatTy :: F64 =>Scalar :: from_f64 ( Double :: from_u128 ( v) . value ) ,
310- FloatTy :: F128 =>unimplemented ! ( "f16_f128" ) ,
310+ FloatTy :: F128 =>Scalar :: from_f128 ( Quad :: from_u128 ( v ) . value ) ,
311311} ,
312312
313313// u8 -> char
@@ -321,7 +321,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
321321/// Low-level cast helper function. Converts an apfloat `f` into int or float types.
322322fn cast_from_float < F > ( & self , f : F , dest_ty : Ty < ' tcx > ) ->Scalar < M :: Provenance >
323323where
324- F : Float +Into < Scalar < M :: Provenance > > +FloatConvert < Single > +FloatConvert < Double > ,
324+ F : Float
325+ +Into < Scalar < M :: Provenance > >
326+ +FloatConvert < Half >
327+ +FloatConvert < Single >
328+ +FloatConvert < Double >
329+ +FloatConvert < Quad > ,
325330{
326331use rustc_type_ir:: TyKind :: * ;
327332
@@ -358,10 +363,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
358363}
359364// float -> float
360365Float ( fty) =>match fty{
361- FloatTy :: F16 =>unimplemented ! ( "f16_f128" ) ,
366+ FloatTy :: F16 =>Scalar :: from_f16 ( adjust_nan ( self , f , f . convert ( & mut false ) . value ) ) ,
362367FloatTy :: F32 =>Scalar :: from_f32 ( adjust_nan ( self , f, f. convert ( & mut false ) . value ) ) ,
363368FloatTy :: F64 =>Scalar :: from_f64 ( adjust_nan ( self , f, f. convert ( & mut false ) . value ) ) ,
364- FloatTy :: F128 =>unimplemented ! ( "f16_f128" ) ,
369+ FloatTy :: F128 =>{
370+ Scalar :: from_f128 ( adjust_nan ( self , f, f. convert ( & mut false ) . value ) )
371+ }
365372} ,
366373// That's it.
367374 _ =>span_bug ! ( self . cur_span( ) , "invalid float to {} cast" , dest_ty) ,