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
1 change: 0 additions & 1 deletion fearless_simd/src/generated/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ impl Simd for Avx2 {
#[inline]
Copy link
Member

Choose a reason for hiding this comment

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

This function should still be #[inline] (indeed, I believe that it possibly should be inline(always)). This is because we don't want to force LLVM to change its calling convention to call this function, we just want to break unneeded inlining.

fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {
#[target_feature(enable = "avx2,fma")]
#[inline]
unsafe fn vectorize_avx2<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
Expand Down
5 changes: 4 additions & 1 deletion fearless_simd/src/generated/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ impl Simd for Fallback {
}
#[inline]
fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {
f()
fn vectorize_inner<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
vectorize_inner(f)
}
#[inline(always)]
fn splat_f32x4(self, val: f32) -> f32x4<Self> {
Expand Down
1 change: 0 additions & 1 deletion fearless_simd/src/generated/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ impl Simd for Neon {
#[inline]
Copy link
Member

Choose a reason for hiding this comment

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

As here

fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {
#[target_feature(enable = "neon")]
#[inline]
unsafe fn vectorize_neon<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
Expand Down
1 change: 0 additions & 1 deletion fearless_simd/src/generated/sse4_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ impl Simd for Sse4_2 {
#[inline]
Copy link
Member

Choose a reason for hiding this comment

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

And here

fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {
#[target_feature(enable = "sse4.2")]
#[inline]
unsafe fn vectorize_sse4_2<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
Expand Down
5 changes: 4 additions & 1 deletion fearless_simd/src/generated/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ impl Simd for WasmSimd128 {
}
#[inline]
fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {
f()
fn vectorize_inner<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
vectorize_inner(f)
}
#[inline(always)]
fn splat_f32x4(self, val: f32) -> f32x4<Self> {
Expand Down
15 changes: 12 additions & 3 deletions fearless_simd_gen/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,26 @@ pub(crate) trait Level {
let vectorize_body = if let Some(target_features) = self.enabled_target_features() {
let vectorize = format_ident!("vectorize_{}", self.name().to_ascii_lowercase());
quote! {
// This function is deliberately not marked #[inline]:
// The closure passed to it is already required to be #[inline(always)],
// so this wrapper is the only opportunity for the compiler to make inlining decisions.
#[target_feature(enable = #target_features)]
#[inline]
unsafe fn #vectorize<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
unsafe { #vectorize(f) }
}
} else {
// If this SIMD level doesn't do runtime feature detection/enabling, just call the inner function as-is
// This SIMD level doesn't do runtime feature detection/enabling, so we could just call the passed closure as-is.
//
// But the inner function is required to be annotated `#[inline(always)]`,
// so we wrap it in a function that isn't `#[inline(always)]`
// to let the compiler make its own inlining decisions, as opposed to forcing it to inline everything.
quote! {
f()
fn vectorize_inner<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
vectorize_inner(f)
}
};

Expand Down