Have you had any real use case for using the calling convention fastcall?
Thanks.
Calling conventions specify how arguments are passed to a function, how return values are passed back out of a function, how the function is called, and how the function manages the stack and its stack frame. In short, the calling convention specifies how a function call in C or C++ is converted into assembly language.
Microsoft Specific The __fastcall calling convention specifies that arguments to functions are to be passed in registers, when possible. This calling convention only applies to the x86 architecture.
In Linux, GCC sets the de facto standard for calling conventions. Since GCC version 4.5, the stack must be aligned to a 16-byte boundary when calling a function (previous versions only required a 4-byte alignment). A version of cdecl is described in System V ABI for i386 systems.
A calling convention is a scheme for how functions receive parameters from their caller and how they return a result. The calling conventions can differ in where parameters and return values are placed (in registers; on the call stack; a mix of both), the order they are placed.
__fastcall tries to pass the function arguments in the CPU registers instead of the stack if possible, which is faster.
Here's a link to an MSDN article explaining the __fastcall calling convention: http://msdn.microsoft.com/en-us/library/6xa169sk(VS.71).aspx
The first two DWORD or smaller arguments are passed in ECX and EDX registers; all other arguments are passed right to left.
This means this will only work for the first two arguments and only if they're <= 32 Bits.
In general I would say, don't expect any big performance advantages from this.
Here's an article explaining when to use fastcall. It actually specifies a case when you actually have no alternative but to use it:
Some VCL classes, such as TList, allow you to specify a callback function (a sort routine in the case of TList). You will have to use the __fastcall keyword in this case, too, as the VCL expects it.
I have one case where I use it effectively - it's a very small asm routine (3 instructions) which manipulates a single value in a register.
For anything but the very smallest and most performance-critical routines though the calling convention should really make no difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With