2 ms·
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
by PaulHoule 2y ago
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.
- dagelf 2y agoLink?
- mananaysiempre 2y agohttps://simdjson.org/publications/ https://simdjson.org/publications/ https://simdutf.github.io/simdutf/ https://simdutf.github.io/simdutf/ https://lemire.me/blog/ https://lemire.me/blog/ https://branchfree.org/ https://branchfree.org/ http://0x80.pl/ http://0x80.pl/
- throwawaymaths 2y agonot even an SMT solver, that's not what they are for.
- 1propionyl 2y agoNo? 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.
- throwawaymaths 2y agoIf 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.
- dzaima 2y agoSMT 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/#0KytITM4uLi5PUqjMzTXRAZEGYNKYqwxZyhQsaAgmjVClzHQQek2BUqlFuSl6mUUgrrmOgkGFAQSYQ2ljKG0KpQ2htIkBKjCD0kYKNkY6ZjoGOiY6hjqmOsY65nZgq8wA#asm https://dzaima.github.io/paste/#0KytITM4uLi5PUqjMzTXRAZEGYNK...
- kibwen 2y ago> So are those functional languages. The author is suggesting array languages as the solution, which are a separate category from functional languages.
- janwas 2y agoLemire 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/1d5b5cd2b60850954df59caa8691ce10ebf04cfe/src https://github.com/simdutf/simdutf/tree/1d5b5cd2b60850954df5...
- mananaysiempre 2y agoI 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-the-arm-holes-or-two-sequences-to-substitute-for-the-missing-pmovmskb-instruction-on-arm-neon/ https://branchfree.org/2019/04/01/fitting-my-head-through-th... [2] https://branchfree.org/2024/06/09/a-draft-taxonomy-of-simd-usage/ https://branchfree.org/2024/06/09/a-draft-taxonomy-of-simd-u...
- janwas 2y agoValid 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?)