Skip to content

Commit c13e2eb

Browse files
adamgemmellJamieCunliffejacobbramleySevenarth
authored andcommitted
Add SVE support to stdarch-verify
Co-authored-by: Jamie Cunliffe <[email protected]> Co-authored-by: Jacob Bramley <[email protected]> Co-authored-by: Luca Vizzarro <[email protected]>
1 parent b04d87c commit c13e2eb

File tree

4 files changed

+190889
-64
lines changed

4 files changed

+190889
-64
lines changed

Diff for: crates/stdarch-verify/src/lib.rs

+69-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
4545
for &mut (ref mut file, ref path) in &mut files {
4646
for mut item in file.items.drain(..) {
4747
match item {
48-
syn::Item::Fn(f) => functions.push((f, path)),
48+
syn::Item::Fn(f) => {
49+
functions.push((f, path));
50+
}
4951
syn::Item::Mod(ref mut m) => {
5052
if let Some(ref mut m) = m.content {
5153
for i in m.1.drain(..) {
@@ -71,12 +73,9 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
7173
assert!(!tests.is_empty());
7274

7375
functions.retain(|(f, _)| {
74-
if let syn::Visibility::Public(_) = f.vis {
75-
if f.sig.unsafety.is_some() {
76-
return true;
77-
}
78-
}
79-
false
76+
matches!(f.vis, syn::Visibility::Public(_))
77+
// Many SVE intrinsics are safe
78+
&& (f.sig.unsafety.is_some() || f.sig.ident.to_string().starts_with("sv"))
8079
});
8180
assert!(!functions.is_empty());
8281

@@ -99,7 +98,7 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
9998
for generic in f.sig.generics.params.iter() {
10099
match *generic {
101100
syn::GenericParam::Const(ref c) => const_arguments.push(to_type(&c.ty)),
102-
syn::GenericParam::Type(ref _t) => (),
101+
syn::GenericParam::Type(_) => (),
103102
_ => panic!("invalid generic argument on {name}"),
104103
};
105104
}
@@ -118,25 +117,31 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
118117
};
119118

120119
let required_const = find_required_const("rustc_args_required_const", &f.attrs);
121-
let mut legacy_const_generics =
120+
let mut const_generics_indices =
122121
find_required_const("rustc_legacy_const_generics", &f.attrs);
123-
if !required_const.is_empty() && !legacy_const_generics.is_empty() {
122+
if !required_const.is_empty() && !const_generics_indices.is_empty() {
124123
panic!(
125124
"Can't have both #[rustc_args_required_const] and \
126125
#[rustc_legacy_const_generics]"
127126
);
128127
}
129128

129+
// Newer intrinsics don't have legacy support - assume they belong at the end of the argument list
130+
if required_const.is_empty() && const_generics_indices.is_empty() {
131+
const_generics_indices =
132+
(arguments.len()..(arguments.len() + const_arguments.len())).collect();
133+
}
134+
130135
// The list of required consts, used to verify the arguments, comes from either the
131136
// `rustc_args_required_const` or the `rustc_legacy_const_generics` attribute.
132137
let required_const = if required_const.is_empty() {
133-
legacy_const_generics.clone()
138+
const_generics_indices.clone()
134139
} else {
135140
required_const
136141
};
137142

138-
legacy_const_generics.sort();
139-
for (idx, ty) in legacy_const_generics
143+
const_generics_indices.sort();
144+
for (idx, ty) in const_generics_indices
140145
.into_iter()
141146
.zip(const_arguments.into_iter())
142147
{
@@ -145,12 +150,12 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
145150

146151
// strip leading underscore from fn name when building a test
147152
// _mm_foo -> mm_foo such that the test name is test_mm_foo.
148-
let test_name_string = format!("{name}");
149-
let mut test_name_id = test_name_string.as_str();
150-
while test_name_id.starts_with('_') {
151-
test_name_id = &test_name_id[1..];
152-
}
153-
let has_test = tests.contains(&format!("test_{test_name_id}"));
153+
let test_name = name.to_string();
154+
let test_name_id = test_name.trim_start_matches('_');
155+
let has_test = tests.contains(&format!("test_{test_name_id}"))
156+
// SVE load/store tests
157+
|| tests.iter().any(|t| t.starts_with(&format!("test_{test_name_id}"))
158+
|| t.ends_with(&format!("_with_{test_name_id}")));
154159

155160
let doc = find_doc(&f.attrs);
156161

@@ -221,8 +226,53 @@ fn to_type(t: &syn::Type) -> proc_macro2::TokenStream {
221226
"p16" => quote! { &P16 },
222227
"Ordering" => quote! { &ORDERING },
223228
"CpuidResult" => quote! { &CPUID },
229+
"T" => quote! { &GENERICT },
224230

225231
// arm ...
232+
"svbool_t" => quote! { &SVBOOL },
233+
"svint8_t" => quote! { &SVI8 },
234+
"svint8x2_t" => quote! { &SVI8X2 },
235+
"svint8x3_t" => quote! { &SVI8X3 },
236+
"svint8x4_t" => quote! { &SVI8X4 },
237+
"svint16_t" => quote! { &SVI16 },
238+
"svint16x2_t" => quote! { &SVI16X2 },
239+
"svint16x3_t" => quote! { &SVI16X3 },
240+
"svint16x4_t" => quote! { &SVI16X4 },
241+
"svint32_t" => quote! { &SVI32 },
242+
"svint32x2_t" => quote! { &SVI32X2 },
243+
"svint32x3_t" => quote! { &SVI32X3 },
244+
"svint32x4_t" => quote! { &SVI32X4 },
245+
"svint64_t" => quote! { &SVI64 },
246+
"svint64x2_t" => quote! { &SVI64X2 },
247+
"svint64x3_t" => quote! { &SVI64X3 },
248+
"svint64x4_t" => quote! { &SVI64X4 },
249+
"svuint8_t" => quote! { &SVU8 },
250+
"svuint8x2_t" => quote! { &SVU8X2 },
251+
"svuint8x3_t" => quote! { &SVU8X3 },
252+
"svuint8x4_t" => quote! { &SVU8X4 },
253+
"svuint16_t" => quote! { &SVU16 },
254+
"svuint16x2_t" => quote! { &SVU16X2 },
255+
"svuint16x3_t" => quote! { &SVU16X3 },
256+
"svuint16x4_t" => quote! { &SVU16X4 },
257+
"svuint32_t" => quote! { &SVU32 },
258+
"svuint32x2_t" => quote! { &SVU32X2 },
259+
"svuint32x3_t" => quote! { &SVU32X3 },
260+
"svuint32x4_t" => quote! { &SVU32X4 },
261+
"svuint64_t" => quote! { &SVU64 },
262+
"svuint64x2_t" => quote! { &SVU64X2 },
263+
"svuint64x3_t" => quote! { &SVU64X3 },
264+
"svuint64x4_t" => quote! { &SVU64X4 },
265+
"svfloat32_t" => quote! { &SVF32 },
266+
"svfloat32x2_t" => quote! { &SVF32X2 },
267+
"svfloat32x3_t" => quote! { &SVF32X3 },
268+
"svfloat32x4_t" => quote! { &SVF32X4 },
269+
"svfloat64_t" => quote! { &SVF64 },
270+
"svfloat64x2_t" => quote! { &SVF64X2 },
271+
"svfloat64x3_t" => quote! { &SVF64X3 },
272+
"svfloat64x4_t" => quote! { &SVF64X4 },
273+
"svprfop" => quote! { &SVPRFOP },
274+
"svpattern" => quote! { &SVPATTERN },
275+
226276
"int8x4_t" => quote! { &I8X4 },
227277
"int8x8_t" => quote! { &I8X8 },
228278
"int8x8x2_t" => quote! { &I8X8X2 },

0 commit comments

Comments
 (0)