How does JitIntrinsicAttribute affect code generation?
This is specific to RyuJIT, the next generation 64-bit jitter that Microsoft is currently working on. Still in alpha (aka CTP), the next version of .NET and Visual Studio is slated to include it. Currently available in the .NET 4.6 Preview.
One new feature in RyuJIT is its ability to generate SIMD machine code, taking advantage of vectorization instructions in Intel/AMD processors. Making floating point operations on arrays up to x8 times faster. The [JitIntrisic] attribute is a marker for C# code that RyuJIT has special built-in knowledge of, it will generate the SIMD version of the machine code instead of the normal non-vectorized version.
Do keep in mind that this is still a million miles away from the kind of code that current C and C++ compilers can generate. RyuJIT can only do this for anointed types that it knows about. Like System.Numerics.Vector2. SIMD code has very strong alignment requirements to be efficient, aligned to 16 for SSE2 instructions, to 32 for AVX instructions. Getting such alignment in a .NET program is going to require a complete overhaul of the CLR, it currently can only align to 4 in 32-bit mode, to 8 in 64-bit mode.
Long story short: the how you are asking about is the jitter. Mono has been tinkering with its own SIMD support, it appears to have gotten stuck 5 years ago. .NET Core was just recently announced to go open source with the very liberal MIT license, I assume (but don't know for a fact yet) that this is going to include the source code for RyuJIT. The github project is work in progress right now and very incomplete.
UPDATE: This made it into .NET 4.6 RTM. Vector.IsHardwareAccelerated is now internal. Only the System.Numerics.Vector2, Vector3 and Vector4 types get the SIMD love. You can get System.Numerics.Vectors version 4.1.0.0 from Nuget. It exposes more, including Vector<T>
.
2018 update: apparently, [JitIntrinsic]
was not used for its intended purpose and was replaced with System.Runtime.CompilerServices.IntrinsicAttribute
.
The attribute was mentioned in the discussion about moving Vector
classes to the CoreLib:
@jkotas: We should not need the JitIntrinsicAttribute. As far as I know, this attribute was future proofing, never used for anything real. We should delete it, and use the IntrinsicAttribute from CoreLib instead.
And later replaced with Intrinsic
: Replace JitIntrinsicAttribute with IntrinsicAttribute.
See, What does the [Intrinsic] attribute in C# do? for the similar discussion about [Intrinsic]
atrribute, which is actually used to implement low-level optimizations.