diff --git a/crates/stdarch-verify/src/lib.rs b/crates/stdarch-verify/src/lib.rs index 94569dfd0c..106aeabdb0 100644 --- a/crates/stdarch-verify/src/lib.rs +++ b/crates/stdarch-verify/src/lib.rs @@ -152,6 +152,8 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { } let has_test = tests.contains(&format!("test_{test_name_id}")); + let doc = find_doc(&f.attrs); + quote! { Function { name: stringify!(#name), @@ -162,6 +164,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { file: stringify!(#path), required_const: &[#(#required_const),*], has_test: #has_test, + doc: #doc } } }) @@ -508,6 +511,26 @@ fn find_target_feature(attrs: &[syn::Attribute]) -> Option { }) } +fn find_doc(attrs: &[syn::Attribute]) -> String { + attrs + .iter() + .filter_map(|a| { + if let syn::Meta::NameValue(ref l) = a.meta { + if l.path.is_ident("doc") { + if let syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(ref s), + .. + }) = l.value + { + return Some(s.value()); + } + } + } + return None; + }) + .collect() +} + fn find_required_const(name: &str, attrs: &[syn::Attribute]) -> Vec { attrs .iter() diff --git a/crates/stdarch-verify/tests/arm.rs b/crates/stdarch-verify/tests/arm.rs index 6827d22f50..1b18dbdaad 100644 --- a/crates/stdarch-verify/tests/arm.rs +++ b/crates/stdarch-verify/tests/arm.rs @@ -13,6 +13,7 @@ struct Function { file: &'static str, required_const: &'static [usize], has_test: bool, + doc: &'static str, } static F16: Type = Type::PrimFloat(16); diff --git a/crates/stdarch-verify/tests/mips.rs b/crates/stdarch-verify/tests/mips.rs index 264d478b6a..ba639c3f92 100644 --- a/crates/stdarch-verify/tests/mips.rs +++ b/crates/stdarch-verify/tests/mips.rs @@ -16,6 +16,7 @@ struct Function { file: &'static str, required_const: &'static [usize], has_test: bool, + doc: &'static str, } static F16: Type = Type::PrimFloat(16); diff --git a/crates/stdarch-verify/tests/x86-intel.rs b/crates/stdarch-verify/tests/x86-intel.rs index 8de2c88b81..d035b4edff 100644 --- a/crates/stdarch-verify/tests/x86-intel.rs +++ b/crates/stdarch-verify/tests/x86-intel.rs @@ -20,6 +20,7 @@ struct Function { file: &'static str, required_const: &'static [usize], has_test: bool, + doc: &'static str, } static BF16: Type = Type::BFloat16; @@ -659,6 +660,20 @@ fn matches(rust: &Function, intel: &Intrinsic) -> Result<(), String> { rust.name ); } + if !rust.doc.contains("Intel") { + bail!("No link to Intel"); + } + let recognized_links = [ + "https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html", + "https://software.intel.com/sites/landingpage/IntrinsicsGuide/", + ]; + if !recognized_links.iter().any(|link| rust.doc.contains(link)) { + bail!("Unrecognized Intel Link"); + } + if !rust.doc.contains(&rust.name[1..]) { + // We can leave the leading underscore + bail!("Bad link to Intel"); + } Ok(()) }