is_riscv_feature_detected doesn't seem to actually detect anything at runtime #139139
Labels
A-target-feature
Area: Enabling/disabling target features like AVX, Neon, etc.
C-bug
Category: This is a bug.
O-riscv
Target: RISC-V architecture
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
I tried this code
I expected to see this happen
Any way at all under hardware with and without RVV support, with and without
-Ctarget-feature=+v
, to be able to return something other than "enabled and detected", or "not enabled and not detected".I.e. for this feature to be useful for:
#[target_feature(enable = "v")]
, that can be selected at runtime, while the rest of the Rust code does not assume+v
.I do realise that if I compile with
+v
(thuscfg!(target_feature = "v")
returns true everywhere), then the binary will probably be broken on non-rvv hardware. E.g.println!()
could use the very instructions that are not supported, so I can't even print an error.But for the cases above:
Instead, this happened
It seems that if
-Ctarget-feature=+v
is not enabled, thenstd::arch::is_riscv_feature_detected!("v")
always returnsfalse
.It's also curious that inside a
#[target_feature(enable = "v")]
function,cfg!(target_feature="v")
doesn't return true, unless the whole program was built with+v
. Is that working as intended?It seems to me that this should not be the same as #138789, where the reason is that LLVM doesn't have the CPU in its database. Because if it were, then the example code should never show
enabled=true detected=true
, but it does.Not sure if it helps at all, but the code base I'm working on is rvv-vroom. You can run the code related to this bug using
cargo +nightly run
.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: