11//! Various number casting functions
22
3+ use crate :: codegen_f16_f128;
34use crate :: prelude:: * ;
45
56pub ( crate ) fn clif_intcast (
@@ -36,6 +37,14 @@ pub(crate) fn clif_int_or_float_cast(
3637) -> Value {
3738 let from_ty = fx. bcx . func . dfg . value_type ( from) ;
3839
40+ // FIXME(bytecodealliance/wasmtime#8312): Remove in favour of native
41+ // Cranelift operations once Cranelift backends have lowerings for them.
42+ if matches ! ( from_ty, types:: F16 | types:: F128 )
43+ || matches ! ( to_ty, types:: F16 | types:: F128 ) && from_ty != to_ty
44+ {
45+ return codegen_f16_f128:: codegen_cast ( fx, from, from_signed, to_ty, to_signed) ;
46+ }
47+
3948 if from_ty. is_int ( ) && to_ty. is_int ( ) {
4049 // int-like -> int-like
4150 clif_intcast (
@@ -58,8 +67,10 @@ pub(crate) fn clif_int_or_float_cast(
5867 "__float{sign}ti{flt}f" ,
5968 sign = if from_signed { "" } else { "un" } ,
6069 flt = match to_ty {
70+ types:: F16 => "h" ,
6171 types:: F32 => "s" ,
6272 types:: F64 => "d" ,
73+ types:: F128 => "t" ,
6374 _ => unreachable!( "{:?}" , to_ty) ,
6475 } ,
6576 ) ;
@@ -90,8 +101,10 @@ pub(crate) fn clif_int_or_float_cast(
90101 "__fix{sign}{flt}fti" ,
91102 sign = if to_signed { "" } else { "uns" } ,
92103 flt = match from_ty {
104+ types:: F16 => "h" ,
93105 types:: F32 => "s" ,
94106 types:: F64 => "d" ,
107+ types:: F128 => "t" ,
95108 _ => unreachable!( "{:?}" , to_ty) ,
96109 } ,
97110 ) ;
@@ -145,8 +158,12 @@ pub(crate) fn clif_int_or_float_cast(
145158 } else if from_ty. is_float ( ) && to_ty. is_float ( ) {
146159 // float -> float
147160 match ( from_ty, to_ty) {
148- ( types:: F32 , types:: F64 ) => fx. bcx . ins ( ) . fpromote ( types:: F64 , from) ,
149- ( types:: F64 , types:: F32 ) => fx. bcx . ins ( ) . fdemote ( types:: F32 , from) ,
161+ ( types:: F16 , types:: F32 | types:: F64 | types:: F128 )
162+ | ( types:: F32 , types:: F64 | types:: F128 )
163+ | ( types:: F64 , types:: F128 ) => fx. bcx . ins ( ) . fpromote ( to_ty, from) ,
164+ ( types:: F128 , types:: F64 | types:: F32 | types:: F16 )
165+ | ( types:: F64 , types:: F32 | types:: F16 )
166+ | ( types:: F32 , types:: F16 ) => fx. bcx . ins ( ) . fdemote ( to_ty, from) ,
150167 _ => from,
151168 }
152169 } else {
0 commit comments