Skip to content

Add #[inline] to all aarch64 and wasm32 functions - #44

Merged
okaneco merged 1 commit into
okaneco:masterfrom
lilith:add-inline-aarch64-wasm32
Feb 28, 2026
Merged

Add #[inline] to all aarch64 and wasm32 functions#44
okaneco merged 1 commit into
okaneco:masterfrom
lilith:add-inline-aarch64-wasm32

Conversation

@lilith

@lilith lilith commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Summary

The vld_n_replicate_k! macro generates ~300 aarch64 functions with #[target_feature(enable = "neon")] but no #[inline]. Similarly, all 17 wasm32 functions lack #[inline]. The x86/x86_64 modules already have #[inline] on every function.

Without #[inline], rustc does not include function bodies in crate metadata, preventing cross-crate inlining. Every NEON/WASM load and store becomes a function call (bl/call) instead of a single instruction (ldr q/str q).

Impact

Benchmarked with garb (pixel swizzle crate) across Linux, macOS, and Windows aarch64 runners:

Benchmark (8 MiB) Before After Speedup
4bpp inplace swap 788–916 µs 236–242 µs 3.3–3.8x
3bpp inplace swap 966–1292 µs 327–369 µs 2.6–3.5x
3bpp copy swap 771–905 µs 217–255 µs 3.4–4.2x
fill alpha 771–942 µs 236–268 µs 3.3–3.5x

Before the fix, garb's NEON paths were slower than scalar on all aarch64 platforms. After: 2–4x faster than naive scalar loops. The release assembly went from 44 bl calls to safe_unaligned_simd functions down to 0.

Changes

  • src/aarch64.rs: Add #[inline] to both load and store arms of the vld_n_replicate_k! macro (2 lines, affects ~300 generated fns)
  • src/wasm32.rs: Add #[inline] to all 17 hand-written functions

The aarch64 macro `vld_n_replicate_k!` generates ~300 public functions
(all load/store variants) with `#[target_feature(enable = "neon")]` but
no `#[inline]`. Similarly, all 17 wasm32 functions lack `#[inline]`.

Without `#[inline]`, Rust does not emit function bodies in crate
metadata for cross-crate inlining. Every NEON/WASM load and store
becomes a `bl`/`call` instruction in the caller's hot loop instead of
inlining to a single `ldr q`/`str q` instruction.

This was empirically confirmed in garb (pixel swizzle crate): 44 `bl`
calls to safe_unaligned_simd in the release assembly, reduced to 0
after adding `#[inline]`. The x86 modules already had `#[inline]` on
all ~260 functions and were unaffected.

@okaneco okaneco left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, I'll push out a version bump soon.

edit: v0.2.5 is up now.

@okaneco
okaneco merged commit 47b37ba into okaneco:master Feb 28, 2026
27 checks passed
@okaneco okaneco added A-aarch64 aarch64 architecture A-wasm32 wasm32 architecture relnotes PR or issue that should be mentioned in next release notes/changelog update labels Feb 28, 2026
@lilith
lilith deleted the add-inline-aarch64-wasm32 branch March 24, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-aarch64 aarch64 architecture A-wasm32 wasm32 architecture relnotes PR or issue that should be mentioned in next release notes/changelog update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants