Skip to content
Open
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
4 changes: 2 additions & 2 deletions library/std_detect/src/detect/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ features! {
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] asimd: "neon";
/// FEAT_AdvSIMD (Advanced SIMD/NEON)
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] pmull: "pmull";
implied by target_features: ["aes"];
implied by cfg(target_feature = "aes");
/// FEAT_PMULL (Polynomial Multiply) - Implied by `aes` target_feature
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] fp: "fp";
implied by target_features: ["neon"];
implied by cfg(target_feature = "neon");
/// FEAT_FP (Floating point support) - Implied by `neon` target_feature
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] aes: "aes";
/// FEAT_AES (AES SIMD instructions) & FEAT_PMULL (PMULL{2}, 64-bit operand variants)
Expand Down
119 changes: 117 additions & 2 deletions library/std_detect/src/detect/arch/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ features! {
/// "M" Extension for Integer Multiplication and Division

@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] a: "a";
implied by cfg(any(
target_feature = "a",
all(
target_feature = "zalrsc",
target_feature = "zaamo",
)
));
/// "A" Extension for Atomic Instructions
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zalrsc: "zalrsc";
/// "Zalrsc" Extension for Load-Reserved/Store-Conditional Instructions
Expand Down Expand Up @@ -263,21 +270,37 @@ features! {
/// "Zhinxmin" Extension for Minimal Half-Precision Floating-Point in Integer Registers

@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] c: "c";
implied by cfg(any(
target_feature = "c",
all(
not(target_feature = "d"),
any(not(target_arch = "riscv32"), not(target_feature = "f")),
target_feature = "zca",
)
));
/// "C" Extension for Compressed Instructions
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zca: "zca";
/// "Zca" Compressed Instructions excluding Floating-Point Loads/Stores
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcf: "zcf";
without cfg check: true;
implied by cfg(all(target_arch = "riscv32", target_feature = "c", target_feature = "f"));
/// "Zcf" Compressed Instructions for Single-Precision Floating-Point Loads/Stores on RV32
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcd: "zcd";
without cfg check: true;
implied by cfg(all(target_feature = "c", target_feature = "d"));
/// "Zcd" Compressed Instructions for Double-Precision Floating-Point Loads/Stores
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcb: "zcb";
/// "Zcb" Simple Code-size Saving Compressed Instructions
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcmop: "zcmop";
/// "Zcmop" Extension for Compressed May-Be-Operations

@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] b: "b";
implied by cfg(any(
target_feature = "b",
all(
target_feature = "zba",
target_feature = "zbb",
target_feature = "zbs",
)
));
/// "B" Extension for Bit Manipulation
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zba: "zba";
/// "Zba" Extension for Address Generation
Expand Down Expand Up @@ -307,10 +330,44 @@ features! {
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zkr: "zkr";
/// "Zkr" Entropy Source Extension
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zkn: "zkn";
implied by cfg(any(
target_feature = "zkn",
all(
target_feature = "zbkb",
target_feature = "zbkc",
target_feature = "zbkx",
target_feature = "zkne",
target_feature = "zknd",
target_feature = "zknh",
)
));
/// "Zkn" Cryptography Extension for NIST Algorithm Suite
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zks: "zks";
implied by cfg(any(
target_feature = "zks",
all(
target_feature = "zbkb",
target_feature = "zbkc",
target_feature = "zbkx",
target_feature = "zksed",
target_feature = "zksh",
)
));
/// "Zks" Cryptography Extension for ShangMi Algorithm Suite
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zk: "zk";
implied by cfg(any(
target_feature = "zk",
all(
target_feature = "zbkb",
target_feature = "zbkc",
target_feature = "zbkx",
target_feature = "zkne",
target_feature = "zknd",
target_feature = "zknh",
target_feature = "zkr",
target_feature = "zkt",
)
));
/// "Zk" Cryptography Extension for Standard Scalar Cryptography
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zkt: "zkt";
/// "Zkt" Cryptography Extension for Data Independent Execution Latency
Expand Down Expand Up @@ -355,16 +412,74 @@ features! {
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksh: "zvksh";
/// "Zvksh" Cryptography Extension for ShangMi Suite: Vector SM3 Secure Hash
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkn: "zvkn";
implied by cfg(any(
target_feature = "zvkn",
all(
target_feature = "zvkned",
target_feature = "zvknhb",
target_feature = "zvkb",
target_feature = "zvkt",
)
));
/// "Zvkn" Cryptography Extension for NIST Algorithm Suite
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvknc: "zvknc";
implied by cfg(any(
target_feature = "zvknc",
Copy link
Member

Choose a reason for hiding this comment

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

This line seems redundant and could be folded into the macro itself: a feature is always implied by itself.

Copy link
Contributor Author

@a4lg a4lg Sep 17, 2025

Choose a reason for hiding this comment

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

... unless implied by is used (even implied by target_features:, which is to be removed in this PR suppresses self implication; see the macro expansion carefully).
So, zvknc runtime (std_detect) target feature is not directly implied by zvknc compiler target feature itself.

Still, you are technically right since... for instance (in this place), zvknc is just a collection of sub-extensions (zvkned, zvknhb...) and zvknc compiler target feature directly/indirectly enables all of them (indirectly enabling runtime target feature zvknc).
The reason I keep zvknc itself is to check validity of the compiler target feature (through check_cfg_feature!).

I think we can keep this (and similar lines) as-is (in this PR).

all(
target_feature = "zvkned",
target_feature = "zvknhb",
target_feature = "zvkb",
target_feature = "zvkt",
target_feature = "zvbc",
)
));
/// "Zvknc" Cryptography Extension for NIST Algorithm Suite with Carryless Multiply
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkng: "zvkng";
implied by cfg(any(
target_feature = "zvkng",
all(
target_feature = "zvkned",
target_feature = "zvknhb",
target_feature = "zvkb",
target_feature = "zvkt",
target_feature = "zvkg",
)
));
/// "Zvkng" Cryptography Extension for NIST Algorithm Suite with GCM
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvks: "zvks";
implied by cfg(any(
target_feature = "zvks",
all(
target_feature = "zvksed",
target_feature = "zvksh",
target_feature = "zvkb",
target_feature = "zvkt",
)
));
/// "Zvks" Cryptography Extension for ShangMi Algorithm Suite
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksc: "zvksc";
implied by cfg(any(
target_feature = "zvksc",
all(
target_feature = "zvksed",
target_feature = "zvksh",
target_feature = "zvkb",
target_feature = "zvkt",
target_feature = "zvbc",
)
));
/// "Zvksc" Cryptography Extension for ShangMi Algorithm Suite with Carryless Multiply
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvksg: "zvksg";
implied by cfg(any(
target_feature = "zvksg",
all(
target_feature = "zvksed",
target_feature = "zvksh",
target_feature = "zvkb",
target_feature = "zvkt",
target_feature = "zvkg",
)
));
/// "Zvksg" Cryptography Extension for ShangMi Algorithm Suite with GCM
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zvkt: "zvkt";
/// "Zvkt" Extension for Vector Data-Independent Execution Latency
Expand Down
33 changes: 22 additions & 11 deletions library/std_detect/src/detect/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#[unstable(feature = "stdarch_internal", issue = "none")]
macro_rules! detect_feature {
($feature:tt, $feature_lit:tt) => {
$crate::detect_feature!($feature, $feature_lit : $feature_lit)
cfg!(target_feature = $feature_lit) || $crate::detect::__is_feature_detected::$feature()
};
($feature:tt, $feature_lit:tt : $($target_feature_lit:tt),*) => {
$(cfg!(target_feature = $target_feature_lit) ||)*
$crate::detect::__is_feature_detected::$feature()
($feature:tt, $feature_lit:tt : cfg($target_feature_cfg:meta)) => {
cfg!($target_feature_cfg) || $crate::detect::__is_feature_detected::$feature()
};
($feature:tt, $feature_lit:tt, without cfg check: true) => {
$crate::detect::__is_feature_detected::$feature()
Expand All @@ -17,14 +16,16 @@ macro_rules! detect_feature {
#[allow(unused_macros, reason = "it's used in the features! macro below")]
macro_rules! check_cfg_feature {
($feature:tt, $feature_lit:tt) => {
check_cfg_feature!($feature, $feature_lit : $feature_lit)
cfg!(target_feature = $feature_lit);
};
($feature:tt, $feature_lit:tt : $($target_feature_lit:tt),*) => {
$(cfg!(target_feature = $target_feature_lit);)*
($feature:tt, $feature_lit:tt : cfg($target_feature_cfg:meta)) => {
cfg!($target_feature_cfg);
};
($feature:tt, $feature_lit:tt, without cfg check: $feature_cfg_check:literal) => {
#[allow(unexpected_cfgs, reason = $feature_lit)]
{ cfg!(target_feature = $feature_lit) }
{
cfg!(target_feature = $feature_lit)
}
};
}

Expand All @@ -39,7 +40,7 @@ macro_rules! features {
$(@NO_RUNTIME_DETECTION: $nort_feature:tt; )*
$(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt;
$(without cfg check: $feature_cfg_check:tt;)?
$(implied by target_features: [$($target_feature_lit:tt),*];)?
$(implied by cfg($target_feature_cfg:meta);)?
$(#[$feature_comment:meta])*)*
) => {
#[macro_export]
Expand All @@ -50,7 +51,12 @@ macro_rules! features {
macro_rules! $macro_name {
$(
($feature_lit) => {
$crate::detect_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? $(: $($target_feature_lit),*)?)
$crate::detect_feature!(
$feature,
$feature_lit
$(, without cfg check: $feature_cfg_check)?
$(: cfg($target_feature_cfg))?
)
};
)*
$(
Expand Down Expand Up @@ -135,7 +141,12 @@ macro_rules! features {
#[deny(unfulfilled_lint_expectations)]
const _: () = {
$(
check_cfg_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? $(: $($target_feature_lit),*)?);
check_cfg_feature!(
$feature,
$feature_lit
$(, without cfg check: $feature_cfg_check)?
$(: cfg($target_feature_cfg))?
);
)*
};

Expand Down
Loading