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 UAA19932; Mon, 27 Oct 2003 20:18:48 +0100 (MET) 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 UAA31397 for ; Mon, 27 Oct 2003 20:18:46 +0100 (MET) Received: from postfix4-2.free.fr (postfix4-2.free.fr [213.228.0.176]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9RJIj101283 for ; Mon, 27 Oct 2003 20:18:45 +0100 (MET) Received: from jemmapes-4-82-67-191-68.fbx.proxad.net (jemmapes-4-82-67-191-68.fbx.proxad.net [82.67.191.68]) by postfix4-2.free.fr (Postfix) with ESMTP id 8162EC866 for ; Mon, 27 Oct 2003 20:18:36 +0100 (CET) From: Yann Regis-Gianas To: caml-list@inria.fr Subject: Re: [Caml-list] partial eval question Date: Mon, 27 Oct 2003 20:17:50 +0100 User-Agent: KMail/1.5.4 References: <004a01c39c2b$819db8f0$1fcf2952@Archimedes> <20031027081453.37b9f6ee.Damien.Pous@ens-lyon.fr> <16285.15401.421786.814601@beertje.william.bogus> In-Reply-To: <16285.15401.421786.814601@beertje.william.bogus> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200310272017.50686.yann.regisgianas@free.fr> X-Loop: caml-list@inria.fr X-Spam: no; 0.00; yann:01 regis-gianas:01 yann:01 caml-list:01 chesters:01 multi-stage:01 error-prone:01 inlining:01 unrolling:01 sparse:01 metaocaml:01 multi-stage:01 inlining:01 unrolling:01 challenges:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk William Chesters wrote : > And that's an improvement over > > double pow(double x, int n) { > double it = 1; > while (--n >= 0) it *= x; > return it; > } > > double pow3(double x, int n) { > return pow(x, 3); > } > > in what way exactly? (If it doesn't work for you, try > -funroll-all-loops.) > > For these kinds of purposes, Multi-Stage Programming is a very > labour-intensive and error-prone way of doing what mainstream > compilers will do for you already. I agree with you that constant folding, inlining and unrolling are well known by common compilers. However, when you want to _control_ these optimisations, this is more difficult with standard optimizers since they are black-boxes. For example, the benefit of these optimizations is linked with the size of code, the processor type but also with the values of data (think of the sparse matrix example). All these parameters cannot be managed by a low level compiler optimizer. In MetaOCaml, the general process of multi-stage evaluation enables the user-control of optimization simply : let k = eval_processor_capabilities () let rec pow n = function | 1 -> .< fun x -> x >. | n when n < k -> .< fun x -> x * .~(pow (n-1)) x>. | n -> .< fun x -> x *. (.! (pow (n-1)) x >. > Maybe it has useful applications > in e.g. generation of numerical codes, where inlining, unrolling, > "templatization" and partial evaluation are not enough because major > structural transformations are required. But then, maybe > sophisticated jobs like that are always going to be easiest done with > special-purpose code generators? By adding the multi-stage evaluation into a programming language, we obtain one general, transparent and simple tool. Why should we develop or learn the usage of many special-purpose optimizers ? Yes, some work has to be done to enhance its user-friendliness but, in my opinion, this feature can be relevant in many daily programming situations (not only optimization). There are some papers about that, for example : "Accomplishments and Research Challenges in Meta-programming". Tim Sheard. -- Yann Regis-Gianas. ------------------- 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