summaryrefslogtreecommitdiff
path: root/userspace/task1.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-23 21:39:42 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-23 21:39:42 +0200
commitdadd5202a3ccfd8c03fb9eb60e6a15b0fb987672 (patch)
tree3c4b818f90a4862f82ed2e03ceaaf9d7723d293d /userspace/task1.c
parent6c8be13c682a0aef520b2d3efeb67dcf078b1889 (diff)
filesystem stuff and experimenting with userspace tasks
Diffstat (limited to 'userspace/task1.c')
-rw-r--r--userspace/task1.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/userspace/task1.c b/userspace/task1.c
index d3706ee..d9875f4 100644
--- a/userspace/task1.c
+++ b/userspace/task1.c
@@ -1,11 +1,48 @@
-int main(int argc, char **argv)
+typedef unsigned long long ULL;
+
+// a simple cache to speedup successive requests!
+static ULL fib1_cached_index=0;
+static ULL fib1_cached_value=0;
+
+static ULL fib2_cached_index=1;
+static ULL fib2_cached_value=1;
+
+
+ULL fib(ULL i)
{
- signed int i=0;
+ if(i==0)return 0;
+ if(i==1)return 1;
+ if(i==fib1_cached_index)return fib1_cached_value;
+ if(i==fib2_cached_index)return fib2_cached_value;
+
+ ULL value=fib(i-1)+fib(i-2);
+
+ fib1_cached_index=fib2_cached_index;
+ fib1_cached_value=fib2_cached_value;
+
+ fib2_cached_index=i;
+ fib2_cached_value=value;
+
+ return value;
+}
+
+
+
+int main(unsigned int argc, char **argv)
+{
+ ULL i=0;
while(1)
{
i++;
- printf("task 1 : %i \n",i);
+
+ fib(i); //precalc
+
+ // this will exhaust the stack so we call fib every time above
+ #ifdef __linux__
+ if((i%100000000)==1)printf("gcc-fibonacci(%llu) = %llu \n",i,fib(i));
+ #endif
+ if((i%100000000)==1)printf("fibonacci(%u...) = %u... \n",(unsigned)i,(unsigned)fib(i));
}
return 0;