Search code examples
c#.netclrcil

What language are CLR internal calls written in?


At the bottom of pg 86 in Pro .NET Performance - Optimize Your C# Applications, it talks about the implementaton of ValueType.Equals() and says this:

The definition of CanCompareBits and FastEqualsCheck is deferred to the CLR, they are "internal calls", not implemented in IL

What exactly are "internal calls" and what language are they implemented in if not IL?


Solution

  • Methods, like mentioned CanCompareBits or FastEqualsCheck are marked with [MethodImpl(MethodImplOptions.InternalCall)], which informs clr that it needs to find implementation in it's internals. In terms of CLR it's called FCall, see Calling from managed to native code

    Since coreclr is opensourced it's easy to find actual implementation on github. For FastEqualsCheck see comutilnative.cpp. CoreCLR is written with C++ as well as Mono, so all code for all such internal calls is C/C++.

    In runtime, in opposite to regular .net code which will produce IL (Intermediate language), such internal calls is platform-dependent assember instructions