-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
ARM target-feature cfgs are not enabled when the target-feature is enabled #83975
Comments
This seems relevant: rust/compiler/rustc_codegen_ssa/src/target_features.rs Lines 12 to 51 in b97fd3e
I didn't know that cfg_target_feature isn't stabilized yet, which is easy to miss since I didn't need to enable any unstable features. That list of supported features seems to line up with the cfgs which are actually enabled. One remaining question is why |
LLVM has Also, despite the
|
So the target_features allowed in |
…ments, r=petrochenkov Categorize and explain target features support There are 3 different uses of the `-C target-feature` args passed to rustc: 1. All of the features are passed to LLVM, which uses them to configure code-generation. This is sort-of stabilized since 1.0 though LLVM does change/add/remove target features regularly. 2. Target features which are in [the compiler's allowlist](https://github.com/rust-lang/rust/blob/69e1d22ddbc67b25141a735a22a8895a678b32ca/compiler/rustc_codegen_ssa/src/target_features.rs#L12-L34) can be used in `cfg!(target_feature)` etc. These may have different names than in LLVM and are renamed before passing them to LLVM. 3. Target features which are in the allowlist and which are stabilized or feature-gate-enabled can be used in `#[target_feature]`. It can be confusing that `rustc --print target-features` just prints out the LLVM features without separating out the rustc features or even mentioning that the dichotomy exists. This improves the situation by separating out the rustc and LLVM target features and adding a brief explanation about the difference. Abbreviated Example Output: ``` $ rustc --print target-features Features supported by rustc for this target: adx - Support ADX instructions. aes - Enable AES instructions. ... xsaves - Support xsaves instructions. crt-static - Enables libraries with C Run-time Libraries(CRT) to be statically linked. Code-generation features supported by LLVM for this target: 16bit-mode - 16-bit mode (i8086). 32bit-mode - 32-bit mode (80386). ... x87 - Enable X87 float instructions. xop - Enable XOP instructions. Use +feature to enable a feature, or -feature to disable it. For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2 Code-generation features cannot be used in cfg or #[target_feature], and may be renamed or removed in a future version of LLVM or rustc. ``` Motivated by rust-lang#83975. CC rust-lang#49653
To the best of my knowledge, all of the above features are valid for my target, an STM32H743XIH6. At the very least
fp-armv8d16
is valid for Cortex-M7 targets: fpv5 has the same instructions as ARMv8. If any of the target features are not valid, rustc should print a warning message.However, rustc doesn't appear to actually enable any of the target_feature cfgs, somehow deciding that
vfp2
is good enough - despite the fact thatvfp2
isn't even a valid option forARMv7e-M
1. Testing the enabled features usingcfg!
or#[cfg()]
gives the same result (I wish I had found--print cfg
sooner).I did some comparisons using godbolt: Rust | C GCC/Clang
It appears that the
target-feature
s are working, at least the ones that I can easily generate instructions for. Enabling any feature which tells LLVM there's 64-bit float support causes it to emit all 64-bit float instructions. Disablingv7clrex
causes it to stop emittingclrex
.I think what's happening is there's some logic in LLVM which enables other target features and internal flags based on the target features it's given. Then it/rustc finds a minimum set of target-features which would end up enabling the resulting internal flags - e.g.vfp2
enablesfp64
so sincefp64
is enabled we'll say thatvfp2
is enabled. Then that reduced set of features is what actually ends up ascfg
s. This makes#[cfg(target_feature = "")]
almost useless on ARM since most of the target-features say they are disabled even when they seem to work.Footnotes
Armv7-M Architecture Reference Manual section A2.5 ↩
The text was updated successfully, but these errors were encountered: