|
From: | Matt Wette |
Subject: | Re: native code |
Date: | Wed, 22 Feb 2017 13:44:26 -0800 |
In your dev process are you looking at intermediate stages of .c -> .o to see if gcc is generating tail-calls? I’m guessing it will (w/ -O2) in many cases. mwette$ cat sum.c #include <stdio.h> int sum(int total, int top) { if (top == 1) return total+top; else sum(total+top, top-1); } int main() { printf("%d\n", sum(0, 5)); } mwette$ cat sum.s. # where gcc -O2 [-S] produces tail call in sum() _sum: LFB1: jmp L10 .align 4,0x90 L7: addl %esi, %edi subl $1, %esi L10: cmpl $1, %esi jne L7 leal 1(%rdi), %eax ret Matt |
[Prev in Thread] | Current Thread | [Next in Thread] |