3 ms·
I thought modern languages optimized code into SIMD instructions where it could automatically... I know Java does this.
by fnord77 9y ago
I thought modern languages optimized code into SIMD instructions where it could automatically...
I know Java does this.
- burntsushi 9y agoThey do. It's called auto-vectorization and the Rust compiler does it (mostly by virtue of LLVM). But there are thousands[1] of SIMD instructions just for x86_64 alone and auto-vectorization doesn't come close to covering all of them. Even if auto-vectorization does cover the instructions you want to use, you might be justifiably uncomfortable with relying on it for performance in every case (or perhaps you simply can't rely on it), and would instead prefer to explicitly write out the transformations. [1] - https://software.intel.com/sites/landingpage/IntrinsicsGuide/ https://software.intel.com/sites/landingpage/IntrinsicsGuide...
- vvimpcrvsh 9y agoLLVM and rustc are pretty fickle with what they'll autovectorize. The idea of faster is to make things which are impossible to autovectorize easy to write as SIMD. A few examples I'm targeting for the next point release are matrix determinants, cross products, byte-aligned encoding (like https://github.com/AdamNiederer/base100/blob/master/src/lib.rs https://github.com/AdamNiederer/base100/blob/master/src/lib....), and reductive operations like strcmp. AFAIK none of that can be autovectorized at all.
- YSFEJ4SWJUVU6 9y agoDid you also know that a sufficiently smart compiler can deduce the whole programming logic from English prose? It's just pretty hard to create one. Same applies to automatic optimizations in the general case: what do you exactly know about what Java does beyond that it is capable of using SIMD instructions? Have you perhaps evaluated how and where it does so, or how the end result compares to more explicit manual use of stream operations? edit: and for the record, the problem is not as easy as you seem to think it is, given how you described your astonishment.
- exDM69 9y ago> I thought modern languages optimized code into SIMD instructions where it could automatically... Kinda-sorta yes, but not really. Auto-vectorization is a very brittle optimization that only works at the best of times and the slightest change in your code can cause it to fall out of the hot path. You have to be extra careful with aliasing and use the "restrict" keyword a lot. If you really do care about performance, you still have to write your hot loops with explicit SIMD code.