Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a run-make test for Arm target-cpu features. #130382

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/run-make/arm-target-cpu-features/cortex-m7.checks
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/run-make/arm-target-cpu-features/cortex-m85.checks
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/run-make/arm-target-cpu-features/lib.rs
Original file line number Diff line number Diff line change
@@ -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
}
55 changes: 55 additions & 0 deletions tests/run-make/arm-target-cpu-features/rmake.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading