Fastcall GCC example
Asked Answered
B

2

10

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?

Breastfeed answered 23/3, 2009 at 4:46 Comment(0)
T
17

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
Trove answered 23/3, 2009 at 5:6 Comment(1)
Do you need to show the post-call cleanup to emphasize the difference? +1 for the manual x-ref.Chromogenic

© 2022 - 2024 — McMap. All rights reserved.