News for hackers. Stuff that matters.
Re:C Is Not Suited to SIMD by PaulHoule on Thursday January 23, 2025 @04:10PM (#42808114)
So are those functional languages. The really cool SIMD code I see people writing now is by people like Lemire using the latest extensions who do clever things like decoding UTF-8 which I think will always take assembly language to express unless you are getting an SMT solver to write it for you.
Re:C Is Not Suited to SIMD by dagelf on Monday January 27, 2025 @08:53AM (#42841160)
Link?
Re:C Is Not Suited to SIMD by throwawaymaths on Monday January 27, 2025 @09:17AM (#42841357)
not even an SMT solver, that's not what they are for.
Re:C Is Not Suited to SIMD by 1propionyl on Monday January 27, 2025 @10:47AM (#42842332)
No? SMT solvers underpin the majority of program synthesis research tools.

When you get down to it, you're optimizing (searching) for some program that maximizes/minimizes some objective function with terms for error relative to specification/examples and size of synthesized program, while applying some form of cleverness to pruning the search space.

This is absolutely within the wheelhouse of SMT solvers, and something that they are used for.

SMT doesn't have to be used, but for implementation it enables iterating on the concept more quickly (see also, more broadly: prototyping in Prolog), and in other cases it's simply the most effective tool for the job. So, it tends to get a lot of play.

Re:C Is Not Suited to SIMD by throwawaymaths on Tuesday January 28, 2025 @11:45AM (#42854475)
If SMT solvers were all you needed, then for example, LLVM wouldn't need a polyhedral optimizer. And a polyhedral optimizer is a subset of the sorts of things you will need for doing the sort of things you're asking to do automatically.
Re:C Is Not Suited to SIMD by dzaima on Tuesday January 28, 2025 @12:36PM (#42855279)
SMT solvers might not be feasible for large-scale things, but they can certainly be used to find a sequence of a couple instructions doing a specific thing if you give enough computational resources, and that's what OP was talking about. (whether it'll complete in a reasonable time (i.e. less than like an hour) for something with more than like 4 instructions is a separate question; but 4 instructions is enough for some fancy stuff).

Like, just playing around not particularly seriously, I've gotten SMT to spit out [1] for narrowing & packing four int32x8 vectors into one int8x32 vector, assuming no wrapping necessary (4 minutes via Bitwuzla), among other things; nothing one couldn't figure out by doing a bit of thinking, but it does work! And could conceivably get more feasible for larger tasks over time.

[1]: https://dzaima.github.io/paste/#0KytITM4uLi5PUqjMzTXRAZEGYNK...

Re:C Is Not Suited to SIMD by kibwen on Monday January 27, 2025 @10:50AM (#42842358)
> So are those functional languages.

The author is suggesting array languages as the solution, which are a separate category from functional languages.

Re:C Is Not Suited to SIMD by janwas on Monday January 27, 2025 @01:11PM (#42843944)
Lemire and collaborators often write in C++ intrinsics, or thin platform-specific wrappers on top of them.

I count ~8 different implementations [1], which demonstrates considerable commitment :) Personally, I prefer to write once with portable intrinsics.

https://github.com/simdutf/simdutf/tree/1d5b5cd2b60850954df5...

Re:C Is Not Suited to SIMD by mananaysiempre on Monday January 27, 2025 @06:15PM (#42846942)
I don’t think that really works beyond 128 bits. AVX/AVX2 with its weird tiered 2×128-bit structure occasionally forces you down some really awkward paths. AVX-512 with its masks is powerful and quite elegant, but the idioms it enables don’t really translate to other ISAs. And even in 128-bit land, the difference between good code for SSE and NEON can be quite significant, all because of a single instruction (PMOVMSKB) the latter lacks[1].

Portable instructions and “scalable” length-agnostic vectors are usually fine for straightforward mathy (type-1[2]) SIMD code. But real SIMD trickery, the one that starts as soon as you take your variable byte shuffle out of the stable, is rarely so kind.

[1] https://branchfree.org/2019/04/01/fitting-my-head-through-th...

[2] https://branchfree.org/2024/06/09/a-draft-taxonomy-of-simd-u...

Re:C Is Not Suited to SIMD by janwas on Tuesday January 28, 2025 @01:31AM (#42849487)
Valid points, but I am doing exactly that full-time for the past years :) Including compression and quicksort, which are nontrivial uses of SIMD.

The 2x128 is handled by adopting AVX2 semantics for our InterleaveLower/Upper op, and when we want the extra fixup, there is also InterleaveWholeLower. I agree AVX-512 is awesome, it's my favorite target. Some of its useful ops (compress[store]) are fine to emulate. What idioms did you have in mind that don't translate? Spot on about PMOVMSKB, that's a pain point. We provide several ops to replace it with more relaxed semantics that are easier to emulate on other platforms, for example AllTrue, CountTrue, AllFalse. (I think DanilaK's NEON VSHRN trick is faster than the one from your first link?)