Skip to content

Commit d7b2790

Browse files
committedSep 14, 2024
Fix target-cpu fpu features on Armv8-R.
This is a follow-up to #123159, but applied to Armv8-R. This required llvm/llvm-project#88287 to work properly. Now that this change exists in rustc's llvm, we can fix Armv8-R's default fpu features. Add a run-make test that target-cpu=cortex-r52 enables double-precision and neon.
1 parent 5e3ede2 commit d7b2790

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed
 

‎compiler/rustc_target/src/spec/targets/armv8r_none_eabihf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn target() -> Target {
3030
// Reference:
3131
// Arm Cortex-R52 Processor Technical Reference Manual
3232
// - Chapter 15 Advanced SIMD and floating-point support
33-
features: "+fp-armv8,-fp64,-d32".into(),
33+
features: "+fp-armv8d16sp".into(),
3434
max_atomic_width: Some(64),
3535
emit_debug_gdb_scripts: false,
3636
// GCC defaults to 8 for arm-none here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// CHECK-LABEL: vadd_q:
2+
// CHECK: vld{{.*}}
3+
// CHECK: vld{{.*}}
4+
// CHECK: vadd.f32{{.*}}q
5+
// CHECK: vst{{.*}} [r0]
6+
// CHECK: bx lr
7+
8+
// CHECK-LABEL: vadd_f64:
9+
// CHECK: vadd.f64 d0, d0, d1
10+
// CHECK: bx lr
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![no_std]
2+
3+
#[no_mangle]
4+
pub fn vadd_q(x: &mut [f32; 4], y: &[f32; 4]) {
5+
for i in 0..4 {
6+
x[i] += y[i];
7+
}
8+
}
9+
10+
#[no_mangle]
11+
pub fn vadd_f64(x: f64, y: f64) -> f64 {
12+
x + y
13+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This tests that target-cpu correctly enables additional floating-point features.
2+
3+
use run_make_support::{llvm_filecheck, llvm_objdump, rustc, static_lib_name};
4+
5+
struct TestCase {
6+
target: &'static str,
7+
cpu: &'static str,
8+
}
9+
10+
static CASES: &[TestCase] = &[TestCase { target: "armv8r-none-eabihf", cpu: "cortex-r52" }];
11+
12+
fn main() {
13+
for case in CASES {
14+
let lib = static_lib_name(case.cpu);
15+
16+
rustc()
17+
.edition("2021")
18+
.arg(format!("--target={}", case.target))
19+
.arg(format!("-Ctarget-cpu={}", case.cpu))
20+
.arg("-Copt-level=3")
21+
.crate_type("rlib")
22+
.input("lib.rs")
23+
.output(&lib)
24+
.run();
25+
26+
let dis = llvm_objdump()
27+
.arg("--arch-name=arm")
28+
.arg(format!("--mcpu={}", case.cpu))
29+
.disassemble()
30+
.input(&lib)
31+
.run()
32+
.stdout_utf8();
33+
34+
let check_file = format!("{}_{}.checks", case.target, case.cpu).replace("-", "_");
35+
llvm_filecheck().patterns(check_file).stdin_buf(dis).run();
36+
}
37+
}

0 commit comments

Comments
 (0)