From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA29439; Thu, 8 Jul 2004 17:52:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA28872 for ; Thu, 8 Jul 2004 17:51:56 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i68FptEV008559 for ; Thu, 8 Jul 2004 17:51:56 +0200 Received: from fichte.ai.univie.ac.at (markus@localhost [127.0.0.1]) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) with ESMTP id i68FpmDu026356; Thu, 8 Jul 2004 17:51:48 +0200 Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) id i68FpmHb026355; Thu, 8 Jul 2004 17:51:48 +0200 Date: Thu, 8 Jul 2004 17:51:48 +0200 From: Markus Mottl To: Alex Baretta Cc: ocaml Subject: Re: [Caml-list] Does Caml have slow arithmetics ? Message-ID: <20040708155148.GA21304@fichte.ai.univie.ac.at> Mail-Followup-To: Alex Baretta , ocaml References: <20040707091308.GA26172@bourg.inria.fr> <20040707145803.GB27498@yquem.inria.fr> <1089227778.29648.81.camel@pelican.wigram> <20040708034455.GB29942@davidb.org> <40ED190E.3080005@ps.uni-sb.de> <20040708140408.GA2386@davidb.org> <20040708163653.A1260@beaune.inria.fr> <40ED6424.7090903@baretta.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <40ED6424.7090903@baretta.com> User-Agent: Mutt/1.4.1i X-Miltered: at nez-perce with ID 40ED6D9B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 arithmetics:01 baretta:01 ocamlopt:01 tail-call:01 closures:01 recursion:01 recursion:01 closures:01 compiler:01 ocaml:01 ocaml:01 caml:01 afaik:01 alex:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 :-) Regards, Markus -- Markus Mottl http://www.oefai.at/~markus markus@oefai.at ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners