projects
/
libfirm
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
generate real fprem node
[libfirm]
/
ir
/
be
/
test
/
fib.c
1
#include <stdio.h>
2
3
//#define COUNT_BRANCHES
4
5
#ifdef COUNT_BRANCHES
6
int b1, b2, b3;
7
#endif
8
9
unsigned fib(unsigned n)
10
{
11
if(n == 0) {
12
#ifdef COUNT_BRANCHES
13
b1++;
14
#endif
15
return 0;
16
}
17
if(n == 1) {
18
#ifdef COUNT_BRANCHES
19
b2++;
20
#endif
21
return 1;
22
}
23
24
#ifdef COUNT_BRANCHES
25
b3++;
26
#endif
27
return fib(n-1) + fib(n-2);
28
}
29
30
int main(int argc, char** argv) {
31
unsigned n = 8;
32
if(argc > 1)
33
n = (unsigned) atoi(argv[1]);
34
35
#ifdef COUNT_BRANCHES
36
b1 = b2 = b3 = 0;
37
#endif
38
printf("Fib %u: %u\n", n, fib(n));
39
#ifdef COUNT_BRANCHES
40
printf("Branches: 1:%d 2:%d 3:%d\n", b1, b2, b3);
41
#endif
42
43
return 0;
44
}