5 ms·
Both ahead of time compilers and JIT compilers often perform autovectorization of tight loops. The problem is that lots of hot loops are not necessarily simple
by oldmanhorton 4mo ago
Both ahead of time compilers and JIT compilers often perform autovectorization of tight loops. The problem is that lots of hot loops are not necessarily simple loops, and in particular a lot of source code is written in a way which uses sequential dependencies that can’t be modeled in SIMD code. Aside from undefined behavior in C/C++, most compilers will fail to autovectorize because doing so would very slightly change the behavior of your code in a very hard to understand way.
- rao-v 4mo agoSurely a high level language can own the contract of making sane choices of when to auto vectorize and when not to (or just inefficiently auto vectorize - that is fine too!)
- throwup238 4mo agoThat’s like saying “surely a high level language can solve the halting problem.” Yes, it can, but only by eliminating the features that make it Turing complete. It’s relatively easy to vectorize map with a closure that can’t mutate anything but once you have nontrivial control flow, the compiler can’t make those kinds of assumptions.
- rao-v 4mo agoIt’s really not! We’re not requiring the language to make optimal choices, just that it convert the same code to these different paradigms (and honestly you could just brute force run the 12 versions and choose the fastest one). Absolutely no theory barriers apply!
- bobbyswiss 4mo agoYou should design it!
- rao-v 4mo agoSome kind soul pointed to Intel’s https://ispc.github.io/ https://ispc.github.io/ which is basically this. Missing some features but roughly has the idea. Keep faith with human ingenuity!