← Back to context

Comment by wyldfire

8 years ago

The simplest target-independent fearless SIMD is autovectorization[1] . But taking maximum advantage of that probably means writing some code that feels a little unnatural. Also, IIRC bounds checks thwart some autovectorization.

[1] https://llvm.org/docs/Vectorizers.html

I think autovectorization is differently-fearful rather than fearless; you live in perpetual dread of the wind changing and suddenly your code doesn't autovectorize any more.

I've spent quite a bit of time looking at autovectorization, but didn't write about it much here, as it's only good for a pretty small subset of problems. One subtle gotcha I ran into is that `round` doesn't autovectorize, but `float` does, even though today's chips have perfectly good vector round instructions. See rust issue #55107 for a deep dive into that problem.

Autovectorizing is quite a long way away from being as or more performant from using intrinsics or asm.

This makes sense when you think about it. The compiler would either need to be extremely capable of generalizing about some kinds of arithmetic, or it would need millions of special cases to recognize. By writing your own vectorization, you are basically covering your singular special case on your own.

In an LLVM context it also means you don't get runtime feature detection. You would need to build N dlls and then write code to load the proper one at runtime based on feature detection.

JITs could solve that problem, but few JITs currently do very much auto vectorization, because they don't have time.

  • > In an LLVM context it also means you don't get runtime feature detection. You would need to build N dlls and then write code to load the proper one at runtime based on feature detection.

    Does LLVM not support GCC-style function multiversioning?

  • Intel has made quite a few contributions to Hotspot, including AVX support.

    ART started supporting SIMD on Oreo, and it was further expanded on Pie. Naturally very few devices have gotten those improvements thanks the state of Android's updates.

    So on Android's case Renderscript is still the best way for a JIT like approach for SIMD.

    • As far as I know the JVM will only auto-vectorize integers. Is there a way to tag a function such that you want floats vectorized too now?

      ART is a good point, compile on install lets you do this.

      1 reply →