How does JitIntrinsicAttribute affect code generation?

I was looking at the .NET source code and saw this attribute . It says:

Attribute that can be attached to JIT internal methods / properties

and according to MSDN :

Indicates that the modified method is an internal value for which the just-in-time (JIT) compiler can perform special code generation. This class cannot be inherited.

but it was hard for me to find how to do this. On which code does it perform special code generation?

My main hunch is that processor instructions like SIMD are mostly used, something like Java JIT. . Here is an example . I wonder what kind of acceleration it does, and I wonder if Mono does it either.

+4
source share
2 answers

This refers to RyuJIT , the next-generation 64-bit jitter that Microsoft is currently working on. Still in the alpha version (aka CTP), the next version of .NET and Visual Studio are planning to enable it. Currently available in .NET 4.6 Preview.

One of RyuJIT's new features is the ability to generate native SIMD code, taking advantage of the vectorization instructions in Intel / AMD processors. Operations with floating point arrays are 8 times faster. The [JitIntrisic] attribute is a marker for C # code, about which RyuJIT has special built-in knowledge, it will generate a SIMD version of machine code instead of a regular non-vectorized version.

Keep in mind that this is still a million miles from the code that modern C and C ++ compilers can generate. RyuJIT can only do this for anointed types that he knows about. Like System.Numerics.Vector2. The SIMD code has very strict alignment requirements in order to be effective, aligned at 16 for SSE2 instructions and 32 for AVX instructions. Obtaining such alignment in a .NET program will require a complete revision of the CLR; at present, it can only be aligned to 4 in 32-bit mode and to 8 in 64-bit mode.

In short: as you ask, this is jitter. Mono was messing around with its own SIMD support, it seems he was stuck 5 years ago . It has recently been announced that .NET Core will become open source with a very liberal MIT license, I assume (but do not know for sure) that this will include source code for RyuJIT. The github project is currently under development and very incomplete.


UPDATE: This did it in .NET 4.6 RTM. Vector.IsHardwareAccelerated is now internal. Only the types System.Numerics.Vector2, Vector3 and Vector4 receive SIMD love. You can get System.Numerics.Vectors version 4.1.0.0 from Nuget . This provides more, including Vector<T> .

+15
source

2018 update: apparently [JitIntrinsic] not used for its intended purpose and was replaced by System.Runtime.CompilerServices.IntrinsicAttribute .

The attribute was mentioned when discussing moving Vector classes in CoreLib :

@jkotas: we don't need a JitIntrinsicAttribute. As far as I know, this attribute was a test for the future, has never been used for anything real. We need to remove it and use the IntrinsicAttribute from CoreLib instead.

And later replaced by Intrinsic : replace the JitIntrinsicAttribute attribute with IntrinsicAttribute .

See what the [Intrinsic] attribute does in C #? for a similar discussion of the [Intrinsic] attribute, which is actually used to implement low-level optimizations.

0
source

All Articles