Skip to content

Commit 474fbca

Browse files
committed
Enable f16 in assembly on aarch64 platforms that support it
Signed-off-by: rongfu.leng <[email protected]>
1 parent 003a902 commit 474fbca

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
6262
ty::Int(IntTy::I64) | ty::Uint(UintTy::U64) => Some(InlineAsmType::I64),
6363
ty::Int(IntTy::I128) | ty::Uint(UintTy::U128) => Some(InlineAsmType::I128),
6464
ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize) => Some(asm_ty_isize),
65+
ty::Float(FloatTy::F16) => Some(InlineAsmType::F16),
6566
ty::Float(FloatTy::F32) => Some(InlineAsmType::F32),
6667
ty::Float(FloatTy::F64) => Some(InlineAsmType::F64),
6768
ty::FnPtr(_) => Some(asm_ty_isize),

compiler/rustc_target/src/asm/aarch64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ impl AArch64InlineAsmRegClass {
5959
match self {
6060
Self::reg => types! { _: I8, I16, I32, I64, F32, F64; },
6161
Self::vreg | Self::vreg_low16 => types! {
62-
neon: I8, I16, I32, I64, F32, F64,
62+
neon: I8, I16, I32, I64, F16, F32, F64,
6363
VecI8(8), VecI16(4), VecI32(2), VecI64(1), VecF32(2), VecF64(1),
64-
VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF32(4), VecF64(2);
64+
VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF16(4),VecF16(8),VecF32(4), VecF64(2);
6565
},
6666
Self::preg => &[],
6767
}

compiler/rustc_target/src/asm/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,15 @@ pub enum InlineAsmType {
707707
I32,
708708
I64,
709709
I128,
710+
F16,
710711
F32,
711712
F64,
712713
VecI8(u64),
713714
VecI16(u64),
714715
VecI32(u64),
715716
VecI64(u64),
716717
VecI128(u64),
718+
VecF16(u64),
717719
VecF32(u64),
718720
VecF64(u64),
719721
}
@@ -730,13 +732,15 @@ impl InlineAsmType {
730732
Self::I32 => 4,
731733
Self::I64 => 8,
732734
Self::I128 => 16,
735+
Self::F16 => 2,
733736
Self::F32 => 4,
734737
Self::F64 => 8,
735738
Self::VecI8(n) => n * 1,
736739
Self::VecI16(n) => n * 2,
737740
Self::VecI32(n) => n * 4,
738741
Self::VecI64(n) => n * 8,
739742
Self::VecI128(n) => n * 16,
743+
Self::VecF16(n) => n * 2,
740744
Self::VecF32(n) => n * 4,
741745
Self::VecF64(n) => n * 8,
742746
})
@@ -751,13 +755,15 @@ impl fmt::Display for InlineAsmType {
751755
Self::I32 => f.write_str("i32"),
752756
Self::I64 => f.write_str("i64"),
753757
Self::I128 => f.write_str("i128"),
758+
Self::F16 => f.write_str("f16"),
754759
Self::F32 => f.write_str("f32"),
755760
Self::F64 => f.write_str("f64"),
756761
Self::VecI8(n) => write!(f, "i8x{n}"),
757762
Self::VecI16(n) => write!(f, "i16x{n}"),
758763
Self::VecI32(n) => write!(f, "i32x{n}"),
759764
Self::VecI64(n) => write!(f, "i64x{n}"),
760765
Self::VecI128(n) => write!(f, "i128x{n}"),
766+
Self::VecF16(n) => write!(f, "f16x{n}"),
761767
Self::VecF32(n) => write!(f, "f32x{n}"),
762768
Self::VecF64(n) => write!(f, "f64x{n}"),
763769
}

tests/ui/asm/aarch64/type-check-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ error: type `Simd256bit` cannot be used with this register class
111111
LL | asm!("{}", in(vreg) f64x4);
112112
| ^^^^^
113113
|
114-
= note: register class `vreg` supports these types: i8, i16, i32, i64, f32, f64, i8x8, i16x4, i32x2, i64x1, f32x2, f64x1, i8x16, i16x8, i32x4, i64x2, f32x4, f64x2
114+
= note: register class `vreg` supports these types: i8, i16, i32, i64, f16, f32, f64, i8x8, i16x4, i32x2, i64x1, f32x2, f64x1, i8x16, i16x8, i32x4, i64x2, f16x4, f16x8, f32x4, f64x2
115115

116116
error: incompatible types for asm inout argument
117117
--> $DIR/type-check-3.rs:88:33

tests/ui/asm/aarch64/type-f16.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ only-aarch64
2+
//@ run-pass
3+
4+
#![feature(f16, f128)]
5+
use std::arch::asm;
6+
#[inline(never)]
7+
pub fn f32_to_f16_asm(a: f32) -> f16 {
8+
let ret: f16;
9+
unsafe {
10+
asm!(
11+
"fcvt {ret:h}, {a:s}",
12+
a = in(vreg) a,
13+
ret = lateout(vreg) ret,
14+
options(nomem, nostack),
15+
);
16+
}
17+
ret
18+
}
19+
fn main() {
20+
f32_to_f16_asm(1.0 as f32);
21+
}

0 commit comments

Comments
 (0)