Skip to content

refactor(backend): centralize SIMD dispatch with ZST feature tokens - #30

Open
cijiugechu wants to merge 1 commit into
fast:mainfrom
cijiugechu:refactor/simd-feature-tokens
Open

cijiugechu wants to merge 1 commit into
fast:mainfrom
cijiugechu:refactor/simd-feature-tokens

Conversation

@cijiugechu

@cijiugechu cijiugechu commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a private backend::simd module defining zero-sized CPU feature tokens (NeonToken, Ssse3Token, Avx2Token, X86Token) and a simd_fn! macro that wraps safe #[target_feature] kernels behind token-gated safe functions, inspired by Sergey "Shnatsel" Davidoff's Safe SIMD in Rust, even on the inside.
  • Migrate the safe validate and encode SIMD kernels across validate/{aarch64,x86}.rs and base{16,32,64}/arch/{aarch64,x86}.rs to token-gated simd_fn! definitions, replacing 21 scattered #[target_feature] dispatch unsafe blocks with the single unsafe invocation inside simd_fn! (reducing bases/src totals from 170 to 150 unsafe {} blocks).
  • Leave the pointer-based decode and decode_in_place kernels untouched to avoid introducing buffer abstraction overhead or extra monomorphization.

Design Notes

  • simd_fn! binds each token type to its exact #[target_feature] string at the macro definition and scopes #[allow(unsafe_code)] solely to the generated inner invocation so kernel bodies remain checked by the workspace unsafe_code = "deny" lint.
  • The generated outer trampoline carries #[inline(always)] while the #[target_feature] inner function keeps #[inline], ensuring the token wrapper compiles away cleanly without leaving extra call boundaries.

@cijiugechu
cijiugechu force-pushed the refactor/simd-feature-tokens branch from a8d70e8 to 5d98b0b Compare November 24, 2026 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant