Skip to content

Commit d4c7c76

Browse files
committed
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. In Armv8-R's case, the default features from LLVM for floating-point are sufficient, because there is no integer-only variant of this architecture. Add a run-make test that target-cpu=cortex-r52 enables double-precision and neon.
1 parent 5e3ede2 commit d4c7c76

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ pub(crate) fn target() -> Target {
2121
linker: Some("rust-lld".into()),
2222
relocation_model: RelocModel::Static,
2323
panic_strategy: PanicStrategy::Abort,
24-
// The Cortex-R52 has two variants with respect to floating-point support:
25-
// 1. fp-armv8, SP-only, with 16 DP (32 SP) registers
26-
// 2. neon-fp-armv8, SP+DP, with 32 DP registers
27-
// Use the lesser of these two options as the default, as it will produce code
28-
// compatible with either variant.
24+
// Armv8-R requires a minimum set of floating-point features equivalent to:
25+
// fp-armv8, SP-only, with 16 DP (32 SP) registers
26+
// LLVM defines Armv8-R to include these features automatically.
27+
//
28+
// The Cortex-R52 supports these default features and optionally includes:
29+
// neon-fp-armv8, SP+DP, with 32 DP registers
2930
//
3031
// Reference:
3132
// Arm Cortex-R52 Processor Technical Reference Manual
3233
// - Chapter 15 Advanced SIMD and floating-point support
33-
features: "+fp-armv8,-fp64,-d32".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)