Avoiding gcc function prologue overhead?

后端 未结 5 1716
逝去的感伤
逝去的感伤 2021-02-13 21:57

I\'ve lately encountered a lot of functions where gcc generates really bad code on x86. They all fit a pattern of:

if (some_condition) {
    /* do something real         


        
5条回答
  •  别跟我提以往
    2021-02-13 22:41

    I would do it like this:

    static void complex_function() {}
    
    void foo()
    {
        if(simple_case) {
            // do whatever
            return;
        } else {
            complex_function();
        }
    }
    

    The compiler my insist on inlining complex_function(), in which case you can use the noinline attribute on it.

提交回复
热议问题