1
1
//! Various number casting functions
2
2
3
+ use crate :: codegen_f16_f128;
3
4
use crate :: prelude:: * ;
4
5
5
6
pub ( crate ) fn clif_intcast (
@@ -36,6 +37,14 @@ pub(crate) fn clif_int_or_float_cast(
36
37
) -> Value {
37
38
let from_ty = fx. bcx . func . dfg . value_type ( from) ;
38
39
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
+
39
48
if from_ty. is_int ( ) && to_ty. is_int ( ) {
40
49
// int-like -> int-like
41
50
clif_intcast (
@@ -58,8 +67,10 @@ pub(crate) fn clif_int_or_float_cast(
58
67
"__float{sign}ti{flt}f" ,
59
68
sign = if from_signed { "" } else { "un" } ,
60
69
flt = match to_ty {
70
+ types:: F16 => "h" ,
61
71
types:: F32 => "s" ,
62
72
types:: F64 => "d" ,
73
+ types:: F128 => "t" ,
63
74
_ => unreachable!( "{:?}" , to_ty) ,
64
75
} ,
65
76
) ;
@@ -90,8 +101,10 @@ pub(crate) fn clif_int_or_float_cast(
90
101
"__fix{sign}{flt}fti" ,
91
102
sign = if to_signed { "" } else { "uns" } ,
92
103
flt = match from_ty {
104
+ types:: F16 => "h" ,
93
105
types:: F32 => "s" ,
94
106
types:: F64 => "d" ,
107
+ types:: F128 => "t" ,
95
108
_ => unreachable!( "{:?}" , to_ty) ,
96
109
} ,
97
110
) ;
@@ -145,8 +158,12 @@ pub(crate) fn clif_int_or_float_cast(
145
158
} else if from_ty. is_float ( ) && to_ty. is_float ( ) {
146
159
// float -> float
147
160
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) ,
150
167
_ => from,
151
168
}
152
169
} else {
0 commit comments