Under what conditions does the .NET JIT compiler perform automatic vectorization?

Does the new RyuJIT compiler create vector (SIMD) CPU instructions, and when?

Side note. The System.Numerics namespace contains types that allow explicit use of vector operations that may or may not generate SIMD instructions depending on the CPU, CLR version, JITer version, whether it compiles directly to native code or not. This question is especially relevant when non-vector code (for example, in C # or F #) will issue SIMD instructions.

+6
source share
1 answer

The generation of SIMD code in RuyJIT is strictly limited to types in the System.Numerics.Vectors namespace. Universal SIMD support will require a very significant revision of the CLR, such code can only be effective if the SIMD variables are correctly aligned. At least 16 for SSE2, up to 32 to be able to use AVX2, up to 64 for the upcoming AVX-512.

Currently, the 32-bit version of the CLR can only be aligned to 4, the 64-bit version to 8. The "natural" alignment for 32-bit and 64-bit code. The necessary changes will affect every part of the CLR, the garbage collector, and the front-end class loader. There is no noise due to such a major change that is under consideration. And there is no sign that this was considered in the CoreCLR project, it would be the most obvious target version.

If you want to use SIMD outside the current support in System.Numerics.Vectors, then do this using the C ++ compiler, using the C ++ / CLI or C ++ / CX language extensions for interaction.

+8
source

All Articles