Ok. This works (replicates Nim performance) for me (on gcc-7.1.0 x86_64 Linux - 
not sure what others): 
    
    
    float fibonacci(int x) {
        return x < 2 ? (float)x : fibonacci(x - 1) + fibonacci(x - 2);
    }
    #include <stdio.h>
    void NimMainInner() {
        printf("%.0f\n", fibonacci(50));
    }
    int main() {
        void (*volatile inner)(void) = NimMainInner;
        inner();
        return 0;
    }
    

Evidently, gcc can only figure out how to unroll the top levels of the 
recursion {to call just fibonacci(38..44)} only if the call site has been 
isolated by being called through a volatile function pointer which Nim happens 
to do.

Reply via email to