Skip to content

Commit

Permalink
mark arm intrinsics as safe
Browse files Browse the repository at this point in the history
  • Loading branch information
usamoi committed Feb 26, 2025
1 parent 3fc9349 commit 742cbfe
Show file tree
Hide file tree
Showing 8 changed files with 17,030 additions and 23,922 deletions.
18,651 changes: 7,907 additions & 10,744 deletions crates/core_arch/src/aarch64/neon/generated.rs

Large diffs are not rendered by default.

149 changes: 72 additions & 77 deletions crates/core_arch/src/aarch64/neon/mod.rs

Large diffs are not rendered by default.

17,545 changes: 7,180 additions & 10,365 deletions crates/core_arch/src/arm_shared/neon/generated.rs

Large diffs are not rendered by default.

1,320 changes: 706 additions & 614 deletions crates/core_arch/src/arm_shared/neon/mod.rs

Large diffs are not rendered by default.

1,979 changes: 690 additions & 1,289 deletions crates/stdarch-gen-arm/spec/neon/aarch64.spec.yml

Large diffs are not rendered by default.

1,275 changes: 450 additions & 825 deletions crates/stdarch-gen-arm/spec/neon/arm_shared.spec.yml

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions crates/stdarch-gen-arm/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ pub struct FnCall(
/// Function turbofish arguments
#[serde(default)]
pub Vec<Expression>,
/// Function requires unsafe wrapper
#[serde(default)]
pub bool,
);

impl FnCall {
pub fn new_expression(fn_ptr: Expression, arguments: Vec<Expression>) -> Expression {
FnCall(Box::new(fn_ptr), arguments, Vec::new()).into()
FnCall(Box::new(fn_ptr), arguments, Vec::new(), false).into()
}

pub fn new_unsafe_expression(fn_ptr: Expression, arguments: Vec<Expression>) -> Expression {
FnCall(Box::new(fn_ptr), arguments, Vec::new(), true).into()
}

pub fn is_llvm_link_call(&self, llvm_link_name: &String) -> bool {
Expand Down Expand Up @@ -84,7 +91,7 @@ impl FnCall {

impl ToTokens for FnCall {
fn to_tokens(&self, tokens: &mut TokenStream) {
let FnCall(fn_ptr, arguments, turbofish) = self;
let FnCall(fn_ptr, arguments, turbofish, _requires_unsafe_wrapper) = self;

fn_ptr.to_tokens(tokens);

Expand Down Expand Up @@ -301,7 +308,7 @@ impl Expression {
}
Self::CastAs(exp, _ty) => exp.requires_unsafe_wrapper(ctx_fn),
// Functions and macros can be unsafe, but can also contain other expressions.
Self::FnCall(FnCall(fn_exp, args, turbo_args)) => {
Self::FnCall(FnCall(fn_exp, args, turbo_args, requires_unsafe_wrapper)) => {
let fn_name = fn_exp.to_string();
fn_exp.requires_unsafe_wrapper(ctx_fn)
|| fn_name.starts_with("_sv")
Expand All @@ -311,6 +318,7 @@ impl Expression {
|| turbo_args
.iter()
.any(|exp| exp.requires_unsafe_wrapper(ctx_fn))
|| *requires_unsafe_wrapper
}
Self::MethodCall(exp, fn_name, args) => match fn_name.as_str() {
// `as_signed` and `as_unsigned` are unsafe because they're trait methods with
Expand Down
19 changes: 14 additions & 5 deletions crates/stdarch-gen-arm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ impl LLVMLink {
})
.try_collect()?;

Ok(FnCall::new_expression(link_sig.fn_name().into(), call_args))
Ok(FnCall::new_unsafe_expression(
link_sig.fn_name().into(),
call_args,
))
}

/// Given a FnCall, apply all the predicate and unsigned conversions as required.
Expand Down Expand Up @@ -1251,7 +1254,7 @@ impl Intrinsic {
.iter()
.map(|sd| sd.try_into())
.try_collect()?;
let mut call: Expression = FnCall(Box::new(name), args, statics).into();
let mut call: Expression = FnCall(Box::new(name), args, statics, false).into();
call.build(self, ctx)?;
Ok(vec![call])
}
Expand Down Expand Up @@ -1320,7 +1323,7 @@ impl Intrinsic {
.iter()
.map(|sd| sd.try_into())
.try_collect()?;
let mut call: Expression = FnCall(Box::new(name), args, statics).into();
let mut call: Expression = FnCall(Box::new(name), args, statics, false).into();
call.build(self, ctx)?;
Ok(vec![call])
}
Expand Down Expand Up @@ -1413,7 +1416,7 @@ impl Intrinsic {
.iter()
.map(|sd| sd.try_into())
.try_collect()?;
let mut call: Expression = FnCall(Box::new(name), args, statics).into();
let mut call: Expression = FnCall(Box::new(name), args, statics, false).into();
call.build(self, ctx)?;

variant.compose = vec![call];
Expand Down Expand Up @@ -1665,7 +1668,13 @@ impl Intrinsic {
.return_type
.as_ref()
.and_then(|t| t.wildcard());
let call = FnCall(Box::new(target_signature.fn_name().into()), args, turbofish).into();
let call = FnCall(
Box::new(target_signature.fn_name().into()),
args,
turbofish,
false,
)
.into();

self.compose = vec![convert_if_required(
ret_wildcard,
Expand Down

0 comments on commit 742cbfe

Please sign in to comment.