Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Does Caml have slow arithmetics ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-08 (15:52)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] Does Caml have slow arithmetics ?
On Thu, 08 Jul 2004, Alex Baretta wrote:
> Luc Maranget wrote:
> >+ ocamlopt does it less often. Namely, calls in tail position
> >  become real tail calls when all their arguments are passed in registers.
> >  (This does not apply to self-tail calls which are always optimized)
> What?! Is this true? This effectively means that I cannot count on 
> tail-call elimination in general?

No, you can't.  If you happen to use a register-starved architecture like
IA-32 and call an OCaml-function with more than six parameters, then you
are out of luck, because you'll have to throw things on the stack.  AFAIK,
the OCaml compiler generates closures on the heap to work around this,
but only in cases where the recursion is obvious (self-tail calls).
Hm, shouldn't be too difficult to extend this to mutual recursion?
Or does OCaml already do this?

I usually avoid recursive functions with more than six parameters for
performance reasons.  I wrap them in closures, which bind constant
parameters, or, if there are too many volatile parameters, I modify the
volatile parameters in references outside of the function.  Another (less
efficient) solution would be to use tuples to pass volatile parameters.

The ultimate solution is, of course: buy a better architecture :-)


Markus Mottl

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: