r/programming • • Jul 23 '26

Everyone Should Know SIMD

https://mitchellh.com/writing/everyone-should-know-simd
413 Upvotes

82 comments sorted by

View all comments

Show parent comment

13

u/imachug Jul 23 '26

SIMD should be a compiler problem.

I'm interested, what do you think a reasonable API for SIMD would look like? People invent new cross-platform SIMD libraries all the time, but they still aren't wildly popular, and I think that's for two reasons:

  • When you don't worry about performance, even the tiniest complication makes you go "ehh, who cares, I'll just keep this a scalar loop". We already have annotations like #pragma clang loop vectorize, but people use them sparingly.
  • When you do worry about performance, it's usually in a critical loop where you want to squeeze the most out of architecture-specific instructions. But since their capabilities are extremely platform-dependent, we often end up writing different algorithms for different targets. The compiler literally can't generate optimal code for each target, because it's not aware of the specific properties of your data that enable important tricks.

Of course, none of this applies to simple loops, like adding two arrays. But that low-hanging fruit is already pretty much solved.

10

u/mcmcc Jul 23 '26

It really requires a language designed to support it, e.g. https://ispc.github.io/

6

u/Ravek Jul 23 '26

Or APIs that boil down to the same thing. But yeah you can’t just write regular cache-inefficient pointer-chasing OO code and expect your compiler to magically parallelize everything.

1

u/jkrejcha3 Jul 24 '26

Not C, but I do actually think the C# standard library has some pretty neat abstractions for common vector operations

1

u/tanner-gooding Jul 25 '26

Thanks! I think so too ;)

We've added even more for .NET 11