Top
Best
New

Posted by WadeGrimridge 3 hours ago

Everyone Should Know SIMD(mitchellh.com)
97 points | 33 commentspage 2
histiq 1 hour ago|
[flagged]
qurren 2 hours ago|
I just do gcc -O3 and get SIMD without having to learn it
ashton314 2 hours ago||
In the article, Mitchel mentions how this doesn’t always work. In fact, as someone who’s worked in compiler development, I can say it’s a small miracle when it does work.
mitchellh 2 hours ago||
Case-in-point, the example in my own post doesn't auto-vectorize with LLVM or GCC at highest optimization levels. Basically, compilers will never auto-vectorize loops with an early loop break afaik.
jandrewrogers 1 hour ago|||
Most scalar-to-SIMD conversion requires changing the design of data structures and algorithms to be effective. Compilers are required to exactly reproduce the specified data structures in a deterministic way for obvious reasons.

Even if compilers were clever enough to transform your data structures and algorithms for SIMD (they're not), the data structures are a contract that can't be unilaterally modified.

forrestthewoods 2 hours ago|||
auto-vectorization is not nearly as good as you would hope it to be.

The best SIMD optimizations likely require changing your data format from AoS to SoA.

nylonstrung 2 hours ago|||
The one feature in Jonathan Blow's Jai language I really envy is a a single keyword to switch AoS to SoA and visa-versa at comptime
mbStavola 2 hours ago||
Didn't he drop this feature years ago?
ethin 1 hour ago||||
Either this or you have to do special tricks like pairwise tree reductions and hand-unroll certain portions of loops.
raegis 2 hours ago||||
What are AoS and SoA?
Georgelemental 2 hours ago|||
Array of Structs and Struct of Arrays https://en.wikipedia.org/wiki/AoS_and_SoA
Rendello 1 hour ago||
A good introduction to SoA (for anyone curious) are the two most famous Data-Oriented Design talks by Mike Acton (game engine dev) [1] and Andrew Kelley (Zig lead dev) [2] respectively.

I read a book book about DoD [3] really which confused me at first with all its talk about database table design (in a book about a high-performance C++ game engine?), but when it finally clicked it was amazing. The point is that you want to think hard about your access patterns and what could constitute good "primary keys", then model it accordingly. SoA ends up being useful a lot of the time, because having your data in homogeneous arrays/vectors is great for cache locality and branch elimination. Even without SIMD you can get huge speedups from that, but that's also where your compiler (or you as a programmer) can get incredible SIMD gains.

SoA is not a silver bullet as it may not align well with your access patterns, but it can great to add to your toolkit.

---

Mike Acton: Data-Oriented Design and C++: https://www.youtube.com/watch?v=rX0ItVEVjHc

Andrew Kelley: A Practical Guide to Applying Data Oriented Design: https://www.youtube.com/watch?v=IroPQ150F6c

Richard Fabian: Data-Oriented Design: https://www.dataorienteddesign.com/dodbook/

nylonstrung 2 hours ago|||
Array of Structs and Struct of Arrays
formerly_proven 2 hours ago||||
And -march=native or at least -march=x86-64-v3 or similar, alternatively identifying relevant functions and manually invoking FMV and uarch specialization via target_clones. Plus non-integer code can generally not be autovectorized in normal-math mode since FP is non-commutative.
Joker_vD 2 hours ago|||
Well, then I just prompt Claude and get SIMD without having to learn it /s
llm_nerd 52 minutes ago||
I have no idea why you're being downvoted. HN has a fetish for SIMD, but if you are hand-rolling SIMD and you aren't writing an explicit acceleration library, you're doing it wrong. Like, 100% of the time.

Every modern language has a vectorization optimizing compiler, and through some fairly straightforward techniques this is automagic. And contrary to the various replies, unless you screwed something up compilers are really good at vectorizing on whatever hardware you're targeting, including SVE.