Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is fastcall really faster?

Is the fastcall calling convention really faster than other calling conventions, such as cdecl? Are there any benchmarks out there that show how performance is affected by calling convention?

like image 598
zr. Avatar asked Feb 02 '10 23:02

zr.


People also ask

What is __ Fastcall in C++?

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.

What is Cdecl used for?

The __cdecl keyword instructs the compiler to read and write a parameter list by using C linkage conventions. To set the __cdecl calling convention for a function, place the linkage keyword immediately before the function name or at the beginning of the declarator.

What is __ Stdcall?

__stdcall is the standard calling convention for Win32 system calls. Wikipedia covers the details. It primarily matters when you are calling a function outside of your code (e.g. an OS API) or the OS is calling you (as is the case here with WinMain).

What is __ Thiscall?

__thiscall It's the default calling convention used by member functions that don't use variable arguments ( vararg functions). Under __thiscall , the callee cleans the stack, which is impossible for vararg functions. Arguments are pushed on the stack from right to left.


1 Answers

It depends on the platform. For a Xenon PowerPC, for example, it can be an order of magnitude difference due to a load-hit-store issue with passing data on the stack. I empirically timed the overhead of a cdecl function at about 45 cycles compared to ~4 for a fastcall.

For an out-of-order x86 (Intel and AMD), the impact may be much less, because the registers are all shadowed and renamed anyway.

The answer really is that you need to benchmark it yourself on the particular platform you care about.

like image 171
Crashworks Avatar answered Sep 22 '22 17:09

Crashworks