Iterative calculations doesn't work - What could be the problem?

HÃ¥vard Ostnes <[email protected]> Tue, 24 Apr 2012 11:50:38 +0000 (UTC)
Newsgroups gmane.comp.micro-kernel.l4.l4ka.general
Message-ID <[email protected]>
Hi!

I have the following code which successfully compiles and runs on L4 on Qemu and 
VMware.

The problem is that the calculations seems to finish immediately and looking at 
the CPU utilization it doesn't even seem to have performed the calculation at 
all.


-----CODE BEGINS-------
//LINUX
//#include <stdio.h>
//#include <unistd.h>
//L4
#include <l4io.h>
#include <l4/ipc.h> 
//#include <l4/types.h>

unsigned int iter_factorial(int n);
unsigned int recr_factorial(int n);

int main() {
  while(1)
    {
      printf("working\n");
      iter_factorial(1000000001);
      printf("Done\n");
      L4_Sleep(L4_TimePeriod(2000000));
      //sleep(2);
    }
}

unsigned int recr_factorial(int n) {
    return n>=1 ? n * recr_factorial(n-1) : 1;
}

unsigned int iter_factorial(int n) {
    int accu = 1;
    int i;
    for(i = 1; i <= n; i++) {
        accu *= i;
    }
    return accu;
}


-------- CODE ENDS----------


I really hope someone could take a look at this to help with my problem as I am 
stuck to the point where I cannot get any further. I have no idea what could be 
the problem.

This is my Makefile:

----- MAKEFILE START ------


srcdir=		@srcdir@
top_srcdir=	@top_srcdir@
top_builddir=	@top_builddir@

include $(top_srcdir)/Mk/l4.base.mk


PROGRAM=	cpu_iterative_a
PROGRAM_DEPS=	$(top_builddir)/lib/l4/libl4.a \
		$(top_builddir)/lib/io/libio.a

SRCS=		crt0-$(ARCH).S iterative_a.cc

LIBS+=		-ll4 -lio
LDFLAGS+=	-Ttext=$(ROOTTASK_LINKBASE)

CFLAGS_powerpc+=	-fno-builtin -msoft-float
CXXFLAGS_powerpc+=	-fno-rtti

include $(top_srcdir)/Mk/l4.prog.mk

------ MAKEFILE END -------