2009-03-23 5 views
9

gccで使用するファストコールの使用例はありますか?可能であれば、ファストコールを使用せずに同等の通話を提供し、それがどう違うのか説明できますか?ここでFastcall GCCの例

答えて

17

です。唯一の違いは関数宣言にあります。 GCC manualに詳細があります。

$ 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 
+1

違いを強調するために通話後のクリーンアップを表示する必要がありますか? +1のマニュアルx-ref。 –