views:

139

answers:

4

Hi,

Have you had any real use case for using the calling convention fastcall?

Thanks.

+2  A: 

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.

luvieere
Thank you.As a side note:from your article, under "Is __fastcall actually fast?" section:"The bottom line with my tests was that the Register calling convention was not any faster than the C calling convention and was, in most cases, slower. Granted, the differences in time are miniscule but I proved to myself that it would be difficult for proponents of __fastcall to claim that the Register calling convention is faster than any other"... "To repeat what I have already said, I advise that you never use __fastcall unless it is specifically required" :)
rursw1
A: 

if you wantto talk to 3rd party dlls some of them are compiled using different calling conventions

Mark
+3  A: 

__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.

humbagumba
Thanks for the link.
Matt Joiner
+1  A: 

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.

Paul R