5 ms·
If I understand correctly, this discussion is specifically about auto-vectorization, which is when the compiler automatically re-writes your code to use highly
by rashkov 4y ago
If I understand correctly, this discussion is specifically about auto-vectorization, which is when the compiler automatically re-writes your code to use highly parallel (and performant) vectorized assembly instructions.
Linus acknowledges that vectorized instructions are valuable, so his rant seems to be specifically about auto-vectorization:
> Yes, yes, yes, you can use it in random places. It's not only some JSON parsing library, you'll find it in other libraries too. I suspect the most use it gets in many situations is - drum roll - implementing memmove/strchr/strcmp style things. And in absolutely zero of those cases will it have been done by the compiler auto-vectorizing it.
In other words.. the people writing foundational parsing libraries (json / strchr / strcmp) are writing their vectorized instructions by hand.
- cmrdporcupine 4y agoWell, also in other words, extant languages and CS education is failing people and they're writing these things the wrong way.
- kolbe 4y agoI use intrinsics by hand all the time. It's very easy to make a problem too complicated to autovectorize. And even if you do get it to autovectorizie, it's not exactly future proof against compiler changes.
- cmrdporcupine 4y agoI have definitely done the same. BTW I really like this library https://github.com/vectorclass/ https://github.com/vectorclass/ I wish I had a similar thing for Rust. And for AArch64/NEON.
- kolbe 4y agoI use Agner as well. I started up my own version for Rust specifically targeting avx512[1], but I've been hitting enough snags to where I think I'll abandon it. It's super green at the moment, and I haven't pushed it to Cargo. But if I'm going to dedicate time to it, then I need it to work for my purposes, and there's a thread-parallel problem that makes this unusable for me at the moment. [1] https://github.com/matthewkolbe/lit_math https://github.com/matthewkolbe/lit_math
- Cloudef 4y agoNote that simply using a SIMD vector class library does not make it "go faster". In fact it can make things worse (due to latency). What you usually need is a problem and then a solution (algorithm) that parallelizes well.
- kolbe 4y agoExplain? My experience has been that you don't need much. I've benchmarked Agner's exp, and if you have 4 calculations to do, then calling it with avx2 will be 4x faster than calling std::exp four times.
- mhh__ 4y agoNote that if you don't write with simd in mind you'll probably write code that cannot ever be autovectorized. SIMD lexing/parsing could mean being less precise with error messages and so on.