Safe SIMD in Rust, even on the inside
The article discusses how to use SIMD (Single Instruction, Multiple Data) operations safely in Rust, even internally within libraries, by leveraging Rust's type system and safety guarantees to avoid undefined behavior while still achieving high performance.
Background
- SIMD (Single Instruction, Multiple Data) is a CPU feature that lets one instruction process multiple data points at once — crucial for performance in graphics, audio, encryption, etc.
- Rust's standard library provides safe SIMD through the `std::simd` module (stabilized in 2024), but using it inside a `safe` function has been difficult because the compiler couldn't verify memory alignment and other safety guarantees in all cases.
- This post discusses a technique or crate (likely `portable-simd` or a related approach) that makes SIMD operations safe even when used internally in Rust code, without requiring `unsafe` blocks — a significant ergonomic improvement for performance-sensitive Rust code.
- The author, "Shnatsel" (Sergey "Shnatsel" Davidoff), is a well-known Rust security researcher and contributor to the Rust project's security response team.