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 DAA22109; Sat, 31 Aug 2002 03:13:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA21783 for ; Sat, 31 Aug 2002 03:13:13 +0200 (MET DST) Received: from mail1.tpgi.com.au (mail.tpgi.com.au [203.12.160.57]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7V1DBD20565 for ; Sat, 31 Aug 2002 03:13:12 +0200 (MET DST) Received: from ozemail.com.au (syd-ts15-2600-232.tpgi.com.au [203.213.83.232]) (authenticated (0 bits)) by mail1.tpgi.com.au (8.11.6/8.11.6) with ESMTP id g7V1D4224631; Sat, 31 Aug 2002 11:13:05 +1000 Message-ID: <3D701820.1040600@ozemail.com.au> Date: Sat, 31 Aug 2002 11:13:04 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: Oleg CC: caml-list@inria.fr Subject: Re: inlining tail-recursive functions (Re: [Caml-list] O'Caml vs C++: a little benchmark) References: <200208181716.NAA10426@hickory.cc.columbia.edu> <200208232134.RAA09914@dewberry.cc.columbia.edu> <3D6CD46E.1030701@ozemail.com.au> <200208281720.NAA06955@dewberry.cc.columbia.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oleg wrote: > On Wednesday 28 August 2002 09:47 am, John Max Skaller wrote: > >>> BTW does O'Caml inline tail-recursive functions? >>> >>Do you mean loop unrolling? I hear that it doesn't >>do loop unrolling. [There's nothing to gain from >>a simple inlining, unless the loop is only executed >>once or twice - you'd only save a single function call] >> > > It's been mentioned that O'Caml can inline functions that are not recursive > (including inlining across module boundaries). Tail-recursive functions can > be, basically, transformed into non-recursive functions by the compiler. So I > was wondering if O'Caml inlined them. The benefits of inlining tail-recursive > functions should thus be the same as the benefits of inlining non-recursive > functions. I don't think so. For a tail rec function transformed into a loop, there is little difference between inlining the loop, or just doing a standard call to a function containing the loop .. assuming functional code, and assuming the loop is executed many times. If the loop is very short, there may be some advantage in unrolling it. The difference would only be a single function call, which has negligible cost compared to a large number of loop iterations. There *might* be a small architectural advantage inlining the loop, if that tends to localise all the variables (more efficient caching of memory blocks). This happens to be the case in my Felix compiler, where a reference to a variable from another function costs an extra indirection, and probably requires two pages of virtual memory instead of the one page and no indirection required if the loop were inlined. But Ocaml doesn't work the way Felix does, so I doubt there would be any advantage (all values are separately heap allocated anyhow, which is not true in Felix, which uses 'frames' to reduce heap allocations] -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- 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