Skip to content

Commit 6e2065b

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

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/int.rs

Lines changed: 10 additions & 2 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,9 +951,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
951951
}
952952

953953
debug_assert!(dest_typ.dyncast_array().is_some());
954+
let dest_type = match self.type_kind(value_type) {
955+
TypeKind::Half => Some(self.float_type),
956+
_ => None,
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
@@ -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)