Everyone should know SIMD
Points and comments are a snapshot, not live.
SIMD follows a simple five-step pattern accessible to any programmer.
Mitchell Hashimoto argues that SIMD vectorization is not as complex as its reputation suggests. He demonstrates a common five-step pattern: broadcast constants, loop over vector-width chunks, perform parallel operations, reduce the vector result, and handle the scalar tail. A real-world example from his terminal emulator Ghostty shows a 5x speedup scanning for control characters. The post uses Zig's generic vectors, noting that compilers often miss auto-vectorization opportunities, especially with early loop breaks. Hand-written SIMD ensures predictable, explicit optimization for hot loops processing contiguous data.
The key insight is that everyday SIMD for common patterns like scanning or comparing follows a regular structure that developers can learn quickly, without needing CPU-specific intrinsics or assembly.
What commenters are saying
Commenters split into two camps: those who trust compilers to auto-vectorize and those who find manual SIMD necessary. Several note that auto-vectorization fails on loops with early breaks, the exact case in the article. A pro-tip: changing data layout from Array of Structs to Struct of Arrays enables better SIMD. The thread notes that gather instructions in AVX2 reduce the AoS vs SoA penalty, but gathers remain expensive. Zig's lack of runtime vector-width dispatch is cited as a limitation; Mitchell confirms Ghostty uses the Highway library for runtime dispatch on hot paths. A commenter notes that `@sin()` on Zig vectors unpacks to scalar operations, contradicting Zig's ethos of no hidden execution.