Version française
Home     About     Download     Resources     Contact us    
Browse thread
ackermann test
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] ackermann test
skaller <skaller@users.sourceforge.net> writes:

>> Where can I find the C code you are using?
>
> int ack(int x, int y) {
>   return x==0? y+1: (y==0? ack(x-1,1):ack(x-1,ack(x,y-1)));
> }

If you write it like this:

int ack(int x, int y) {
   if (x==0) return y+1;
   if (y==0) return ack(x-1,1);
   return ack(x-1,ack(x,y-1));
}

then gcc-3.4.3 generates better code (optimizes tail calls).
-fomit-frame-pointer further speeds it up.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/