Skip to content

Commit c5cb569

Browse files
committed
Add cast from f16 to non-native integer
1 parent 4a6f0be commit c5cb569

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/int.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
942942
fn float_to_int_cast(
943943
&self,
944944
signed: bool,
945-
value: RValue<'gcc>,
945+
mut value: RValue<'gcc>,
946946
dest_typ: Type<'gcc>,
947947
) -> RValue<'gcc> {
948948
let value_type = value.get_type();
@@ -951,17 +951,22 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
951951
}
952952

953953
debug_assert!(dest_typ.dyncast_array().is_some());
954+
let (dest_type, param_type) = match self.type_kind(value_type) {
955+
TypeKind::Half => (Some(self.float_type), self.float_type),
956+
_ => (None, value_type),
957+
};
954958
let name_suffix = match self.type_kind(value_type) {
955959
// cSpell:disable
956-
TypeKind::Float => "sfti",
960+
// Since we will cast Half to a float, we use sfti for both.
961+
TypeKind::Half | TypeKind::Float => "sfti",
957962
TypeKind::Double => "dfti",
958963
TypeKind::FP128 => "tfti",
959964
// cSpell:enable
960965
kind => panic!("cannot cast a {:?} to non-native integer", kind),
961966
};
962967
let sign = if signed { "" } else { "uns" };
963968
let func_name = format!("__fix{}{}", sign, name_suffix);
964-
let param = self.context.new_parameter(None, value_type, "n");
969+
let param = self.context.new_parameter(None, param_type, "n");
965970
let func = self.context.new_function(
966971
None,
967972
FunctionType::Extern,
@@ -970,6 +975,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
970975
func_name,
971976
false,
972977
);
978+
if let Some(dest_type) = dest_type {
979+
value = self.context.new_cast(None, value, dest_type);
980+
}
973981
self.context.new_call(None, func, &[value])
974982
}
975983

0 commit comments

Comments
 (0)