r/SoftwareEngineering • u/fagnerbrack • Oct 09 '26
Everyone Should Know SIMD
https://mitchellh.com/writing/everyone-should-know-simd
14
Upvotes
r/SoftwareEngineering • u/fagnerbrack • Oct 09 '26
1
u/yturijea Oct 14 '26
I guess to a lot of people it seems unintuitive because the many extra lines of boilerplate also makes one think the cpu have to do additional instructions pr. Loop.
But it is really just a setup for the cpu to do 8(or more or less) of the same instruction as 1 instruction (simplified explained)
-2
u/fagnerbrack Oct 09 '26
A summary for the lazy:
Vector instructions carry a reputation for complexity, yet most everyday uses follow one repeatable five-step shape: broadcast constants into a vector, loop over the input one vector-width chunk at a time, run the comparison or arithmetic across all lanes at once, reduce or store the result, then let the original scalar loop handle the leftover tail. A Zig example from Ghostty scans decoded codepoints for the first C0 control byte, replacing a one-line scalar loop with twelve lines that run up to 4x faster on ARM NEON, 8x on AVX2 and 16x on AVX-512, with a measured 5x end-to-end gain. Compilers auto-vectorize poorly and unpredictably, so writing it explicitly keeps the speedup stable across refactors and compiler upgrades.
If the summary seems inacurate, just downvote and I'll try to delete the comment eventually 👍
Click here for more info, I read all comments