【问题标题】:Fastcall GCC example快速调用 GCC 示例
【发布时间】:2009-03-23 04:46:47
【问题描述】:

有人可以提供一个在 gcc 中使用 fastcall 的示例吗?如果可能,您能否在不使用 fastcall 的情况下提供等效调用并解释它们有何不同?

【问题讨论】:

    标签: c gcc compiler-construction fastcall


    【解决方案1】:

    给定函数调用在 C 代码中的显示方式没有区别。唯一的区别在于函数声明。 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 手动外部参考。
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 2018-01-01
    • 2013-04-19
    • 2016-02-24
    • 1970-01-01
    相关资源
    最近更新 更多