Name: Anonymous 2008-11-06 23:48
Data BSTree::retrieve(const KeyType& key, BSTree::Node *cur) const
{
if(!cur)
return Data();
else if(key == cur->data.key)
return cur->data;
cur = key > cur->data.key ? cur->right : cur->left;
return retrieve(key, cur);
}This is a tail-call, yes? But when I compile with "g++ -S BSTree.cpp -Wall -pedantic -O2 -foptimize-sibling-calls", I get this assembly code.
_ZNK6BSTree8retrieveERKjPNS_4NodeE:
.LFB791:
testq %rcx, %rcx
pushq %rbx
.LCFI0:
movq %rdi, %rbx
je .L13
movl (%rdx), %eax
cmpl (%rcx), %eax
je .L14
ja .L15
movq 16(%rcx), %rcx
.L10:
movq %rbx, %rdi
; LOL WTF IS THIS SHIT
call _ZNK6BSTree8retrieveERKjPNS_4NodeE
movq %rbx, %rax
popq %rbx
.p2align 4,,1
.p2align 3
ret
.p2align 4,,10
.p2align 3
.L15:
movq 24(%rcx), %rcx
jmp .L10
.p2align 4,,10
.p2align 3
.L13:
movq %rbx, %rax
movl $0, (%rdi)
movq $_ZNSs4_Rep20_S_empty_rep_storageE+24, 8(%rdi)
popq %rbx
ret
.p2align 4,,10
.p2align 3
.L14:
movl %eax, (%rdi)
leaq 8(%rcx), %rsi
leaq 8(%rdi), %rdi
call _ZNSsC1ERKSs
movq %rbx, %rax
popq %rbx
retI'm about to give up and just put in a fucking goto.