Repository navigation
refactor(backend): narrow unsafe scopes in SIMD kernels - #25
Merged
Merged
Conversation
Convert the three `encode_neon` functions to slice-taking safe `#[target_feature]` functions matching `encode_ssse3` and `encode_avx2`, and pass loaded SIMD vectors by value into x86 `encode_chunk_*` and `decode_chunk_*` helpers so they become safe `fn`s without multi-line `(unsafe { ... })` call sites, reducing `unsafe fn` count across `arch/{aarch64,x86}.rs` from 27 to 15.
Add fixed-size array load helpers (`load_16`, `load_16_i8`, `load_8_i16`) for static lookup tables, deduplicate Base32 and Base64 nibble masks in `x86.rs`, drop the unused 9th tuple element in Base32 `encode_128_consts`, deduplicate NEON Base16 16-byte encoding, and coalesce adjacent store-and-advance `unsafe` blocks.
Signed-off-by: tison <wander4096@gmail.com>
tisonkun
approved these changes
Nov 22, 2026
tisonkun
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the cleanup, @cijiugechu! I merged main and pushed a small follow-up commit (1daa238) with Gemini 4 Carbon to take the same idea a step further:
- Converted the three AArch64
encode_neonfunctions to slice-taking safe#[target_feature]functions to matchencode_ssse3/encode_avx2(and factored outencode_16_neonfor Base16). - Changed the nine x86
encode_chunk_*anddecode_chunk_*helpers to take SIMD vectors by value as safefns, matching AArch64/WASM and dropping the remainingunsafe fncount from 27 to 15. - Added typed
[T; N]array helpers (load_16,load_16_i8,load_8_i16) for loading static lookup tables without raw.as_ptr()unsafeblocks. - Deduplicated the Base32 and Base64 nibble masks in
x86.rsagainst the parent backend constants. - Removed the unused 9th tuple element in Base32
encode_128_constsand merged adjacent store-and-advanceunsafeblocks in the decode loops.
LGTM! Welcome to drop a review on the follow-up commit before we merge.
Contributor
|
I'm going to merge this later today, and any review after merge will be welcome. |
Contributor
Author
|
Looks clean, thanks for taking the cleanup further! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
encode_chunk_*/decode_chunk_*chunk helpers, and slice-basedencode_neon/encode_ssse3/encode_avx2functions to safe#[target_feature]functions under the Rust 1.88 MSRV, reducingunsafe fncount acrossarch/{aarch64,x86}.rsfrom 48 to 15 (leaving only raw-pointerdecode_*entry points shared withdecode_in_placeand partial-width tail load/store helpers).unsafeblocks inside raw-pointer SIMD kernels to cover only memory loads/stores and pointer advancement while leaving vector arithmetic in safe code, and load static[T; N]lookup tables via typed array helpers (load_16,load_16_i8,load_8_i16).x86.rsagainst parent backend constants, drop an unused tuple element in Base32encode_128_consts, and tighten// SAFETY:comments and# Safetydocumentation across all six modified backend files.