Skip to content

Commit 679d0c5

Browse files
committed
Treat f16 as a u16 in ABI
1 parent b4f3025 commit 679d0c5

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/abi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl GccType for Reg {
8686
match self.kind {
8787
RegKind::Integer => cx.type_ix(self.size.bits()),
8888
RegKind::Float => match self.size.bits() {
89+
16 => cx.type_f16_for_abi(),
8990
32 => cx.type_f32(),
9091
64 => cx.type_f64(),
9192
_ => bug!("unsupported float: {:?}", self),

src/type_.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
9797
}
9898
}
9999

100+
pub fn type_f16_for_abi(&self) -> Type<'gcc> {
101+
#[cfg(feature = "master")]
102+
if self.supports_f16_type {
103+
return self.type_f16();
104+
}
105+
self.type_u16()
106+
}
107+
100108
pub fn type_i1(&self) -> Type<'gcc> {
101109
self.bool_type
102110
}

src/type_of.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
285285
match scalar.primitive() {
286286
Int(i, true) => cx.type_from_integer(i),
287287
Int(i, false) => cx.type_from_unsigned_integer(i),
288+
Float(abi::Float::F16) => cx.type_f16_for_abi(),
288289
Float(f) => cx.type_from_float(f),
289290
Pointer(address_space) => {
290291
// If we know the alignment, pick something better than i8.

tests/compile/f16-abi.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Compiler:
2+
3+
#![crate_type = "lib"]
4+
#![feature(f16)]
5+
6+
#[unsafe(no_mangle)]
7+
pub extern "C" fn f16_identity(a: f16) -> f16 {
8+
a
9+
}

0 commit comments

Comments
 (0)