Skip to content

Commit ec67cdf

Browse files
lengrongfubeetrees
authored andcommitted
Enable f16 in assembly on aarch64 platforms that support it
Signed-off-by: rongfu.leng <[email protected]>
1 parent f167efa commit ec67cdf

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

compiler/rustc_target/src/asm/aarch64.rs

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

tests/assembly/asm/aarch64-types.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@ [arm64ec] compile-flags: --target arm64ec-pc-windows-msvc
66
//@ [arm64ec] needs-llvm-components: aarch64
77

8-
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
8+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch, f16)]
99
#![crate_type = "rlib"]
1010
#![no_core]
1111
#![allow(asm_sub_register, non_camel_case_types)]
@@ -39,6 +39,10 @@ pub struct i32x2(i32, i32);
3939
#[repr(simd)]
4040
pub struct i64x1(i64);
4141
#[repr(simd)]
42+
pub struct f16x4(f16, f16, f16, f16);
43+
#[repr(simd)]
44+
pub struct f16x8(f16, f16, f16, f16, f16, f16, f16, f16);
45+
#[repr(simd)]
4246
pub struct f32x2(f32, f32);
4347
#[repr(simd)]
4448
pub struct f64x1(f64);
@@ -57,6 +61,7 @@ pub struct f64x2(f64, f64);
5761

5862
impl Copy for i8 {}
5963
impl Copy for i16 {}
64+
impl Copy for f16 {}
6065
impl Copy for i32 {}
6166
impl Copy for f32 {}
6267
impl Copy for i64 {}
@@ -67,11 +72,13 @@ impl Copy for i16x4 {}
6772
impl Copy for i32x2 {}
6873
impl Copy for i64x1 {}
6974
impl Copy for f32x2 {}
75+
impl Copy for f16x4 {}
7076
impl Copy for f64x1 {}
7177
impl Copy for i8x16 {}
7278
impl Copy for i16x8 {}
7379
impl Copy for i32x4 {}
7480
impl Copy for i64x2 {}
81+
impl Copy for f16x8 {}
7582
impl Copy for f32x4 {}
7683
impl Copy for f64x2 {}
7784

@@ -165,6 +172,12 @@ check!(reg_i16 i16 reg "mov" "");
165172
// CHECK: //NO_APP
166173
check!(reg_i32 i32 reg "mov" "");
167174

175+
// CHECK-LABEL: reg_f16:
176+
// CHECK: @APP
177+
// CHECK: mov {{[a-z0-9]+}}, {{[a-z0-9]+}}
178+
// CHECK: @NO_APP
179+
check!(reg_f16 f16 reg "mov");
180+
168181
// CHECK-LABEL: {{("#)?}}reg_f32{{"?}}
169182
// CHECK: //APP
170183
// CHECK: mov x{{[0-9]+}}, x{{[0-9]+}}
@@ -255,6 +268,20 @@ check!(vreg_i32x2 i32x2 vreg "fmov" "s");
255268
// CHECK: //NO_APP
256269
check!(vreg_i64x1 i64x1 vreg "fmov" "s");
257270

271+
// neon-LABEL: vreg_f16x4:
272+
// neon: @APP
273+
// neon: vmov.f64 d{{[0-9]+}}, d{{[0-9]+}}
274+
// neon: @NO_APP
275+
#[cfg(neon)]
276+
check!(vreg_f16x4 f16x4 vreg "vmov.f64");
277+
278+
// neon-LABEL: vreg_f16x8:
279+
// neon: @APP
280+
// neon: vorr q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}
281+
// neon: @NO_APP
282+
#[cfg(neon)]
283+
check!(vreg_f16x8 f16x8 vreg "vmov");
284+
258285
// CHECK-LABEL: {{("#)?}}vreg_f32x2{{"?}}
259286
// CHECK: //APP
260287
// CHECK: fmov s{{[0-9]+}}, s{{[0-9]+}}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ error: type `i128` cannot be used with this register class
9595
LL | asm!("{}", in(reg) 0i128);
9696
| ^^^^^
9797
|
98-
= note: register class `reg` supports these types: i8, i16, i32, i64, f32, f64
98+
= note: register class `reg` supports these types: i8, i16, i32, i64, f16, f32, f64
9999

100100
error: type `float64x2_t` cannot be used with this register class
101101
--> $DIR/type-check-3.rs:75:28
102102
|
103103
LL | asm!("{}", in(reg) f64x2);
104104
| ^^^^^
105105
|
106-
= note: register class `reg` supports these types: i8, i16, i32, i64, f32, f64
106+
= note: register class `reg` supports these types: i8, i16, i32, i64, f16, f32, f64
107107

108108
error: type `Simd256bit` cannot be used with this register class
109109
--> $DIR/type-check-3.rs:77:29
110110
|
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+
assert_eq!(f32_to_f16_asm(1.0 as f32), 1.0);
21+
}

0 commit comments

Comments
 (0)