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

Fold aarch64 feature +fp into +neon #91608

Merged
merged 5 commits into from
Mar 23, 2022
Merged
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
10 changes: 6 additions & 4 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]
("x86", "avx512vaes") => smallvec!["vaes"],
("x86", "avx512gfni") => smallvec!["gfni"],
("x86", "avx512vpclmulqdq") => smallvec!["vpclmulqdq"],
("aarch64", "fp") => smallvec!["fp-armv8"],
("aarch64", "rcpc2") => smallvec!["rcpc-immo"],
("aarch64", "dpb") => smallvec!["ccpp"],
("aarch64", "dpb2") => smallvec!["ccdp"],
Expand Down Expand Up @@ -230,6 +229,8 @@ pub fn check_tied_features(
None
}

// Used to generate cfg variables and apply features
// Must express features in the way Rust understands them
pub fn target_features(sess: &Session) -> Vec<Symbol> {
let target_machine = create_informational_target_machine(sess);
let mut features: Vec<Symbol> =
Expand All @@ -239,13 +240,14 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
if sess.is_nightly_build() || gate.is_none() { Some(feature) } else { None }
})
.filter(|feature| {
// check that all features in a given smallvec are enabled
for llvm_feature in to_llvm_features(sess, feature) {
let cstr = SmallCStr::new(llvm_feature);
if unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
return true;
if !unsafe { llvm::LLVMRustHasFeature(target_machine, cstr.as_ptr()) } {
return false;
}
}
false
true
})
.map(|feature| Symbol::intern(feature))
.collect();
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
];

const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
// FEAT_AdvSimd
// FEAT_AdvSimd & FEAT_FP
workingjubilee marked this conversation as resolved.
Show resolved Hide resolved
("neon", None),
// FEAT_FP
("fp", None),
// FEAT_FP16
("fp16", None),
// FEAT_SVE
Expand Down Expand Up @@ -143,7 +141,6 @@ const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
];

const AARCH64_TIED_FEATURES: &[&[&str]] = &[
&["fp", "neon"], // Silicon always has both, so avoid needless complications
&["paca", "pacg"], // Together these represent `pauth` in LLVM
];

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/asm/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl AArch64InlineAsmRegClass {
match self {
Self::reg => types! { _: I8, I16, I32, I64, F32, F64; },
Self::vreg | Self::vreg_low16 => types! {
fp: I8, I16, I32, I64, F32, F64,
neon: I8, I16, I32, I64, F32, F64,
VecI8(8), VecI16(4), VecI32(2), VecI64(1), VecF32(2), VecF64(1),
VecI8(16), VecI16(8), VecI32(4), VecI64(2), VecF32(4), VecF64(2);
},
Expand Down
1 change: 0 additions & 1 deletion library/std/tests/run-time-detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fn aarch64_linux() {
println!("neon: {}", is_aarch64_feature_detected!("neon"));
println!("asimd: {}", is_aarch64_feature_detected!("asimd"));
println!("pmull: {}", is_aarch64_feature_detected!("pmull"));
println!("fp: {}", is_aarch64_feature_detected!("fp"));
println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
println!("sve: {}", is_aarch64_feature_detected!("sve"));
println!("crc: {}", is_aarch64_feature_detected!("crc"));
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/simd-ffi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define MK_TARGETS
# now.
$(1): simd.rs
$$(RUSTC) --target=$(1) --emit=llvm-ir,asm simd.rs \
-C target-feature='+fp,+neon,+sse2' -C extra-filename=-$(1)
-C target-feature='+neon,+sse2' -C extra-filename=-$(1)
endef

$(foreach targetxxx,$(TARGETS),$(eval $(call MK_TARGETS,$(targetxxx))))
2 changes: 1 addition & 1 deletion src/test/ui/asm/aarch64/bad-reg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// only-aarch64
// compile-flags: -C target-feature=+fp
// compile-flags: -C target-feature=+neon

#![feature(asm_const, asm_sym)]

Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/target-feature/aarch64-neon-works.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// only-aarch64
// run-pass
#![allow(dead_code)]
use std::arch::*;
use std::arch::aarch64::*;

// Smoke test to verify aarch64 code that enables NEON compiles.
fn main() {
let _zero = if is_aarch64_feature_detected!("neon") {
unsafe {
let zeros = zero_vector();
vgetq_lane_u8::<1>(zeros)
}
} else {
0
};
}


#[target_feature(enable = "neon")]
unsafe fn zero_vector() -> uint8x16_t {
vmovq_n_u8(0)
}
58 changes: 58 additions & 0 deletions src/test/ui/target-feature/feature-hierarchy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// revisions: aarch64-neon aarch64-sve2
// [aarch64-neon] compile-flags: -Ctarget-feature=+neon --target=aarch64-unknown-linux-gnu
// [aarch64-neon] needs-llvm-components: aarch64
// [aarch64-sve2] compile-flags: -Ctarget-feature=-neon,+sve2 --target=aarch64-unknown-linux-gnu
// [aarch64-sve2] needs-llvm-components: aarch64
// build-pass
#![no_core]
#![crate_type = "rlib"]
#![feature(intrinsics, rustc_attrs, no_core, lang_items, staged_api)]
#![stable(feature = "test", since = "1.0.0")]

// Tests vetting "feature hierarchies" in the cases where we impose them.

// Supporting minimal rust core code
#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
impl Copy for bool {}

extern "rust-intrinsic" {
#[rustc_const_stable(feature = "test", since = "1.0.0")]
fn unreachable() -> !;
}

#[rustc_builtin_macro]
macro_rules! cfg {
($($cfg:tt)*) => {};
}

// Test code
const fn do_or_die(cond: bool) {
if cond {
} else {
unsafe { unreachable() }
}
}

macro_rules! assert {
($x:expr $(,)?) => {
const _: () = do_or_die($x);
};
}


#[cfg(aarch64_neon)]
fn check_neon_not_sve2() {
// This checks that a normal aarch64 target doesn't suddenly jump up the feature hierarchy.
assert!(cfg!(target_feature = "neon"));
assert!(cfg!(not(target_feature = "sve2")));
}

#[cfg(aarch64_sve2)]
fn check_sve2_includes_neon() {
// This checks that aarch64's sve2 includes neon
assert!(cfg!(target_feature = "neon"));
assert!(cfg!(target_feature = "sve2"));
}
64 changes: 64 additions & 0 deletions src/test/ui/target-feature/no-llvm-leaks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// revisions: aarch64 x86-64
// [aarch64] compile-flags: -Ctarget-feature=+neon,+fp16,+fhm --target=aarch64-unknown-linux-gnu
// [aarch64] needs-llvm-components: aarch64
// [x86-64] compile-flags: -Ctarget-feature=+sse4.2,+rdrand --target=x86_64-unknown-linux-gnu
// [x86-64] needs-llvm-components: x86
// build-pass
#![no_core]
#![crate_type = "rlib"]
#![feature(intrinsics, rustc_attrs, no_core, lang_items, staged_api)]
#![stable(feature = "test", since = "1.0.0")]

// Supporting minimal rust core code
#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
impl Copy for bool {}

extern "rust-intrinsic" {
#[rustc_const_stable(feature = "test", since = "1.0.0")]
fn unreachable() -> !;
}

#[rustc_builtin_macro]
macro_rules! cfg {
($($cfg:tt)*) => {};
}

// Test code
const fn do_or_die(cond: bool) {
if cond {
} else {
unsafe { unreachable() }
}
}

macro_rules! assert {
($x:expr $(,)?) => {
const _: () = do_or_die($x);
};
}


#[cfg(target_arch = "aarch64")]
fn check_aarch64() {
// This checks that the rustc feature name is used, not the LLVM feature.
assert!(cfg!(target_feature = "neon"));
assert!(cfg!(not(target_feature = "fp-armv8")));
Copy link
Member

@nagisa nagisa Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll also want to spot check for some other features like sve, f64mm, etc, as a regression test for #95122.

assert!(cfg!(target_feature = "fhm"));
assert!(cfg!(not(target_feature = "fp16fml")));
assert!(cfg!(target_feature = "fp16"));
assert!(cfg!(not(target_feature = "fullfp16")));
}

#[cfg(target_arch = "x86_64")]
fn check_x86_64() {
// This checks that the rustc feature name is used, not the LLVM feature.
assert!(cfg!(target_feature = "rdrand"));
assert!(cfg!(not(target_feature = "rdrnd")));

// Likewise: We enable LLVM's crc32 feature with SSE4.2, but Rust says it's just SSE4.2
assert!(cfg!(target_feature = "sse4.2"));
assert!(cfg!(not(target_feature = "crc32")));
}