From 73c4eba4664f9529cc9d0399843f94b5033a1b13 Mon Sep 17 00:00:00 2001 From: Chris Copeland Date: Sat, 14 Sep 2024 21:42:57 -0700 Subject: [PATCH] Add a run-make test for Arm target-cpu features. --- .../arm-target-cpu-features/cortex-m7.checks | 7 +++ .../arm-target-cpu-features/cortex-m85.checks | 12 ++++ tests/run-make/arm-target-cpu-features/lib.rs | 13 +++++ .../run-make/arm-target-cpu-features/rmake.rs | 55 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 tests/run-make/arm-target-cpu-features/cortex-m7.checks create mode 100644 tests/run-make/arm-target-cpu-features/cortex-m85.checks create mode 100644 tests/run-make/arm-target-cpu-features/lib.rs create mode 100644 tests/run-make/arm-target-cpu-features/rmake.rs diff --git a/tests/run-make/arm-target-cpu-features/cortex-m7.checks b/tests/run-make/arm-target-cpu-features/cortex-m7.checks new file mode 100644 index 0000000000000..1888e78310488 --- /dev/null +++ b/tests/run-make/arm-target-cpu-features/cortex-m7.checks @@ -0,0 +1,7 @@ +// Cortex-M7 does not have Advanced SIMD, so don't check anything in vadd_f32_q. +CHECK-LABEL: vadd_f32_q: + +// Cortex-M7 enables double-precision. +CHECK-LABEL: vadd_f64: +CHECK: vadd.f64 d0, d0, d1 +CHECK: bx lr diff --git a/tests/run-make/arm-target-cpu-features/cortex-m85.checks b/tests/run-make/arm-target-cpu-features/cortex-m85.checks new file mode 100644 index 0000000000000..3f1106a3e1b96 --- /dev/null +++ b/tests/run-make/arm-target-cpu-features/cortex-m85.checks @@ -0,0 +1,12 @@ +// Cortex-M85 enables the Helium instructions. +CHECK-LABEL: vadd_f32_q: +CHECK: vld{{.*}} +CHECK: vld{{.*}} +CHECK: vadd.f32{{.*}}q +CHECK: vst{{.*}} [r0] +CHECK: bx lr + +// Cortex-M85 enables double-precision. +CHECK-LABEL: vadd_f64: +CHECK: vadd.f64 d0, d0, d1 +CHECK: bx lr diff --git a/tests/run-make/arm-target-cpu-features/lib.rs b/tests/run-make/arm-target-cpu-features/lib.rs new file mode 100644 index 0000000000000..9825742f4fb87 --- /dev/null +++ b/tests/run-make/arm-target-cpu-features/lib.rs @@ -0,0 +1,13 @@ +#![no_std] + +#[no_mangle] +pub fn vadd_f32_q(x: &mut [f32; 4], y: &[f32; 4]) { + for i in 0..4 { + x[i] += y[i]; + } +} + +#[no_mangle] +pub fn vadd_f64(x: f64, y: f64) -> f64 { + x + y +} diff --git a/tests/run-make/arm-target-cpu-features/rmake.rs b/tests/run-make/arm-target-cpu-features/rmake.rs new file mode 100644 index 0000000000000..63d95827515bb --- /dev/null +++ b/tests/run-make/arm-target-cpu-features/rmake.rs @@ -0,0 +1,55 @@ +// This tests that target-cpu correctly enables additional features for some Arm targets. +// These targets were originally defined in such a way that features provided by target-cpu would be +// disabled by the target spec itself. This was fixed in #123159. + +// FIXME: This test should move to tests/assembly when building without #![no_core] in +// that environment is possible, tracked by #130375. + +use run_make_support::{llvm_filecheck, llvm_objdump, rustc, static_lib_name}; + +struct TestCase { + target: &'static str, + cpu: &'static str, +} + +static CASES: &[TestCase] = &[ + TestCase { target: "thumbv7em-none-eabihf", cpu: "cortex-m7" }, + TestCase { target: "thumbv8m.main-none-eabihf", cpu: "cortex-m85" }, +]; + +fn main() { + for case in CASES { + let lib = static_lib_name(case.cpu); + let checks = format!("{}.checks", case.cpu); + + let rustc_command = || { + let mut cmd = rustc(); + cmd.edition("2021") + .target(case.target) + .arg("-Copt-level=3") + .crate_type("rlib") + .input("lib.rs") + .output(&lib); + cmd + }; + + let objdump_command = || { + let mut cmd = llvm_objdump(); + cmd.arg("--arch-name=arm") + .arg(format!("--mcpu={}", case.cpu)) + .disassemble() + .input(&lib); + cmd + }; + + // First, run without target-cpu and confirm that it fails. + rustc_command().run(); + let dis = objdump_command().run().stdout_utf8(); + llvm_filecheck().patterns(&checks).stdin_buf(dis).run_fail(); + + // Then, run with target-cpu and confirm that it succeeds. + rustc_command().arg(format!("-Ctarget-cpu={}", case.cpu)).run(); + let dis = objdump_command().run().stdout_utf8(); + llvm_filecheck().patterns(&checks).stdin_buf(dis).run(); + } +}