Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What language are CLR internal calls written in?

Tags:

c#

.net

clr

cil

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?

like image 638
David Klempfner Avatar asked Dec 15 '19 01:12

David Klempfner


1 Answers

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

like image 156
Anton Nikolaev Avatar answered Nov 08 '22 18:11

Anton Nikolaev