On 16/12/2010, at 11:56 PM, Paul Steckler wrote:

> On Thu, Dec 16, 2010 at 10:43 PM, john skaller
> <skal...@users.sourceforge.net> wrote:
>> ~/felix>./cack # C version
> 
> Cack?  Such language!


Last time I ran this test, Felix beat C by 50%.

Note the slower Ocaml speed is a little unfair since C and Felix are using 32 
bit ints,
Ocaml is using 64 bit ints.

The time of this test is determined almost exclusively by how many words are 
pushed
onto the stack for a recursion. I have yet to check the generated assembler to 
find out
why the Felix version is slower. Technically, both versions should use the same 
number
of words: 1 machine address and 2 ints, which is 2 64 bit words.

At the cost of one machine register I know how to reduce the number of
words required by one for any recursive function containing only one recursive
call (to itself). I'm not aware anyone else has used this optimisation so it's 
worth
a paper in a journal :)

Actually .. there's bug in the Felix compiler:

//C FUNC <7354>: ack
int FLX_REGPARM ack( int _i7356_v7356_x, int _i7357_v7357_y){
    start_8832:;
      if(!((_i7356_v7356_x == 0)==1) ) goto _8767;
      return _i7357_v7357_y + 1 ;
    _8767:;
      if(!((_i7357_v7357_y == 0)==1) ) goto _8768;
      _i7357_v7357_y  = 1;
      _i7356_v7356_x  = _i7356_v7356_x - 1 ;
      goto start_8832;
    _8768:;
      _i7357_v7357_y  = ack(_i7356_v7356_x, _i7357_v7357_y - 1 );
      _i7356_v7356_x  = _i7356_v7356_x - 1 ;
      goto start_8832;
}

You probably can't see it .. so I'll tell: the function wasn't declared "export"
in Felix so it *should* have been marked "static". This might help gcc optimise 
it,
since it is no longer necessary to conform to the ABI.

Gcc 3.x is very dumb when it comes to optimising recursive functions:
it should always make a wrapper which conforms to the ABI, so it
can make a private function that doesn't. 3.x doesn't do this, not sure about 
4.x.


--
john skaller
skal...@users.sourceforge.net





------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to