diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/foolshell.c | 2 | ||||
| -rw-r--r-- | userspace/sys/syscalls.c | 9 | ||||
| -rw-r--r-- | userspace/task1.c | 43 |
3 files changed, 41 insertions, 13 deletions
diff --git a/userspace/foolshell.c b/userspace/foolshell.c index bf0501f..2abb549 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -227,7 +227,7 @@ int process(char *buf) int pid=fork(); if(pid!=0) { -// printf("new task pid: %i \n",pid); + printf("new task pid: %i \n",pid); } if(pid==0) { diff --git a/userspace/sys/syscalls.c b/userspace/sys/syscalls.c index e6a6a4d..9dfd313 100644 --- a/userspace/sys/syscalls.c +++ b/userspace/sys/syscalls.c @@ -92,8 +92,6 @@ int gettimeofday(struct timeval *tv, void *tz) return syscall(SYSCALL_GETTIMEOFDAY,tv,tz,0); } - - int fork(void) { return syscall(SYSCALL_FORK,0,0,0); @@ -109,9 +107,6 @@ int kill(int pid, int sig) return syscall(SYSCALL_KILL,pid,sig,0); } - - - int link(char *old, char *ne) { return syscall(SYSCALL_LINK,old,ne,0); @@ -122,20 +117,16 @@ int unlink(char *name) return syscall(SYSCALL_UNLINK,name,0,0); } - - int times(struct tms *buf) { return syscall(SYSCALL_TIMES,buf,0,0); } - int wait(int *status) { return syscall(SYSCALL_WAIT,status,0,0); } - int stat(const char *file, struct stat *st) { return syscall(SYSCALL_STAT,file,st,0); 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; |
