[ create a new paste ] login | about

Link: http://codepad.org/2K5gNj3e    [ raw code | fork ]

C, pasted on Sep 7:
// this is a classic recursive function, it's not strictly
// tail-recursive, but it's close enough
long fact(long x) {
    if (x <= 0)
        return 1;
    else
        return x * fact(x - 1);
}

/*
Args used to compile with gcc and llvm-gcc:
-Wall -O3 -fomit-frame-pointer -msse3 -march=native -S
On Windows
gcc: version 4.3.3-dw2-tdm-1 (GCC)
llvm-gcc: gcc version 4.2.1 (Based on Apple Inc. build 5636) (LLVM build)

----------------------------------

GCC:

_fact:
    movl    4(%esp), %edx
    movl    $1, %eax
    testl   %edx, %edx
    jg  L4
    jmp L3
    .p2align 4,,10
L7:
    movl    %ecx, %edx
L4:
    leal    -1(%edx), %ecx
    imull   %edx, %eax
    testl   %ecx, %ecx
    jg  L7
L3:
    rep
    ret

----------------------------------

LLVM-GCC:

_fact:
    pushl   %edi
    pushl   %esi
    subl    $4, %esp
    movl    16(%esp), %esi
    testl   %esi, %esi
    jle LBB1_5  # bb2
LBB1_1: # bb1
    leal    -1(%esi), %edi
    testl   %edi, %edi
    jle LBB1_6  # bb1.fact.exit_crit_edge
LBB1_2: # bb1.i
    leal    -2(%esi), %eax
    movl    %eax, (%esp)
    call    _fact ; see here
    imull   %edi, %eax
LBB1_3: # fact.exit
    imull   %esi, %eax
LBB1_4: # fact.exit
    addl    $4, %esp
    popl    %esi
    popl    %edi
    ret
LBB1_5: # bb2
    movl    $1, %eax
    jmp LBB1_4  # fact.exit
LBB1_6: # bb1.fact.exit_crit_edge
    movl    $1, %eax
    jmp LBB1_3  # fact.exit

*/


Create a new paste based on this one


Comments: