Add cast from f16 to non-native integer
This commit is contained in:
parent
4a6f0bebfb
commit
c5cb56957a
1 changed files with 11 additions and 3 deletions
14
src/int.rs
14
src/int.rs
|
|
@ -942,7 +942,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
fn float_to_int_cast(
|
||||
&self,
|
||||
signed: bool,
|
||||
value: RValue<'gcc>,
|
||||
mut value: RValue<'gcc>,
|
||||
dest_typ: Type<'gcc>,
|
||||
) -> RValue<'gcc> {
|
||||
let value_type = value.get_type();
|
||||
|
|
@ -951,9 +951,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
}
|
||||
|
||||
debug_assert!(dest_typ.dyncast_array().is_some());
|
||||
let (dest_type, param_type) = match self.type_kind(value_type) {
|
||||
TypeKind::Half => (Some(self.float_type), self.float_type),
|
||||
_ => (None, value_type),
|
||||
};
|
||||
let name_suffix = match self.type_kind(value_type) {
|
||||
// cSpell:disable
|
||||
TypeKind::Float => "sfti",
|
||||
// Since we will cast Half to a float, we use sfti for both.
|
||||
TypeKind::Half | TypeKind::Float => "sfti",
|
||||
TypeKind::Double => "dfti",
|
||||
TypeKind::FP128 => "tfti",
|
||||
// cSpell:enable
|
||||
|
|
@ -961,7 +966,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
};
|
||||
let sign = if signed { "" } else { "uns" };
|
||||
let func_name = format!("__fix{}{}", sign, name_suffix);
|
||||
let param = self.context.new_parameter(None, value_type, "n");
|
||||
let param = self.context.new_parameter(None, param_type, "n");
|
||||
let func = self.context.new_function(
|
||||
None,
|
||||
FunctionType::Extern,
|
||||
|
|
@ -970,6 +975,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||
func_name,
|
||||
false,
|
||||
);
|
||||
if let Some(dest_type) = dest_type {
|
||||
value = self.context.new_cast(None, value, dest_type);
|
||||
}
|
||||
self.context.new_call(None, func, &[value])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue