Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastcall GCC example

Could some one provide an example use of fastcall for use with gcc? If possible could you provide the equivalent call without using fastcall and explain how they would be different?

like image 375
Ian Lewis Avatar asked Mar 23 '09 04:03

Ian Lewis


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. The following list shows the implementation of this calling convention. Element.

Is Fastcall faster?

Since it typically saves at least four memory accesses, yes it is generally faster.

Which are function calling conventions in C?

There are three major calling conventions that are used with the C language on 32-bit x86 processors: STDCALL, CDECL, and FASTCALL. In addition, there is another calling convention typically used with C++: THISCALL.


2 Answers

There is no difference in the way a given function call would appear in C code. The only difference would be in the function declaration. The GCC manual has more details.

$ cat fastcall.c
extern void foo1(int x, int y, int z, int a) __attribute__((fastcall));
extern void foo2(int x, int y, int z, int a);

void bar1()
{
    foo1(99, 100, 101, 102);
}

void bar2()
{
    foo2(89, 90, 91, 92);
}

$ gcc -m32 -O3 -S fastcall.c -o -
.
.
bar1:
.
.    
    movl    $100, %edx
    movl    $99, %ecx
    movl    $102, 4(%esp)
    movl    $101, (%esp)
    call    foo1
.
.
bar2:
.
.
    movl    $92, 12(%esp)
    movl    $91, 8(%esp)
    movl    $90, 4(%esp)
    movl    $89, (%esp)
    call    foo2
like image 130
sigjuice Avatar answered Oct 12 '22 17:10

sigjuice


Here are a few links

Is it possible to convince GCC to mimic the fastcall calling convention?

http://www.google.com/search?q=gcc+fastcall

like image 20
Gregor Brandt Avatar answered Oct 12 '22 17:10

Gregor Brandt