Everyone Should Know SIMD
Summary
Mitchell Hashimoto argues that SIMD has an undeserved reputation for complexity and should be part of every developer's toolkit. He presents a five-step pattern — broadcast constants, loop by vector width, perform the SIMD operation, reduce the result, scalar tail — that covers the vast majority of common vectorization cases. Using a real loop from Ghostty as a worked example, he shows that 12 extra lines of Zig can yield a 5x real-world throughput improvement. He addresses why compiler auto-vectorization is an unreliable substitute, especially when predictability matters. The conclusion is that developers shouldn't fear SIMD: the common shape is learnable, reusable, and worth knowing.
Key Insight
SIMD follows a predictable five-step pattern that any developer can learn, and the performance gains are too significant — and too fragile under compiler auto-vectorization — to leave to chance.
Spicy Quotes (click to share)
- 5
Once you learn the basics, writing SIMD is just about as easy as a for loop. And when it's not, it's usually a good sign to skip it for now.
- 6
Every developer should know at least that much SIMD.
- 4
In real-world end-to-end throughput from terminal program to finalized terminal state on an AVX2 Intel desktop, this was more like a 5x speedup. You always lose some of the ideal speedup due to the other stuff around the SIMD code, but... that's still 5x!
- 6
When this loop matters enough for me to care about a 5x speedup, I want the vectorization to be explicit and predictable. I don't want an unrelated code change or compiler update to quietly turn it back into a scalar loop.
- 5
Every developer should be able to recognize the opportunity and, most importantly, should not be scared of SIMD.
- 3
If you see a hot loop scanning, comparing, counting, or transforming a large amount of contiguous data, you should be able to imagine processing it a vector-width chunk at a time.
- 7
I hate that I have to do this for every post now, but I also want to note this was completely hand-written with no AI assistance.
Tone
technical, educational, opinionated
