__Fastcall convention in C #

Given that:

Microsoft specification

The __fastcall calling convention indicates that arguments to functions should be passed to registers when possible. The following list shows the implementation of this call conditionality.

And that the read / write time in the register is much faster than on the stack, do we have any equivalent of __fastcall in C #?

+4
source share
3 answers

Not directly, C # basically uses what would be equivalent to the MSVC ++ __stdcall convention. However, it can be β€œfixed”, albeit in a relatively dirty way (note that the example is for __cdecl).

This is probably the best. In a high-level language such as C # (hell, even in most C ++ programs), this is the optimization most suitable for the compiler. Forced calling often can make matters worse . And even when it helps, it usually doesn't buy you a lot, at least in C and C ++ programs, where I used them.

+5
source

__ fastcall is used automatically, but only in certain conditions. Here is an interesting article on this subject:

2. The method should have no more than seven parameters.

The reason for this is because in .net the first two parameters are faster than the last two parameters. explain it more clearly. In C #, whenever a method is called, parameters are pushed onto the stack, which are then used by the method. Microsoft Compilers (in X86) now have advanced __FASTCALL optimization technology, with the first two parameters passed as registers. It is currently said to become registered. Well, after registration, a variable or parameter has accelerated promotion with the exclusive privilege of being stored in processors faster than any cache. Note that this is usually done for the variable "i", which we use during the loop or iteration, because of which its access and use is really really valid. Thus, at compile time, the method is compiled into native .Net runtime code with the __FASTCALL action, so a method with fewer parameters is much optimized than with too many parameters.

Source

+4
source

LadaRaider, on a 32-bit Arch, which means "The maximum size of the largest registers is 4 bytes", if you go through "Long Long", which takes 8 bytes, it will use 2 registers 4 bytes, as for the compiler with This. Let them say that u uses only 3 registers, 4 bytes, so u cannot pass 2 "Long Long" variables, for example ... Some data will have to go into memory, which is much slower.

0
source

Source: https://habr.com/ru/post/1338662/


All Articles