From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p4J8P05E000445 for ; Thu, 19 May 2011 10:25:00 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwCAILT1E3B/BfVkWdsb2JhbACmJAEBAQEJCwsHFAMiiQ6/QIYZBJARhC+KSA X-IronPort-AV: E=Sophos;i="4.65,236,1304287200"; d="scan'208";a="99329348" Received: from msa04.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.213]) by mail4-smtp-sop.national.inria.fr with ESMTP; 19 May 2011 10:24:35 +0200 Received: from [192.168.1.63] ([83.199.83.241]) by mwinf5d39 with ME id lLQa1g00B5CQSYr03LQaPY; Thu, 19 May 2011 10:24:35 +0200 Message-ID: <4DD4D3C3.9050603@frisch.fr> Date: Thu, 19 May 2011 10:24:35 +0200 From: Alain Frisch User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: Joel Reymont CC: caml-list References: <346B52D2-EE21-43D1-B41E-3AEB3BBF0013@gmail.com> <4DD4150E.6080400@frisch.fr> In-Reply-To: <4DD4150E.6080400@frisch.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] optimizing numerical code On 05/18/2011 08:50 PM, Alain Frisch wrote: > On 5/18/2011 8:35 PM, Joel Reymont wrote: >> Consider the following two functions that I'm trying to optimize. >> >> Why is there an allocation for every iteration of the loop in >> divergence1 but not in divergence2? > > First, note that the compiler does indeed unbox the reference cell acc > as a local variable. It turns out that the float contained in the > reference is not itself unboxed. This is due to the heuristic used by > ocamlopt to unbox floats. Currently, a float variable is unboxed only if > all the places where its value is used are unboxing contexts. A way to > force unboxing in divergence1 is to replace (!acc) with (!acc +. 0) at > the end. Without this change, the compilers can find a use of !acc as a > boxed float (because this is what the function needs to return) and so > it decides not to unbox acc at all. > > > See also: > http://caml.inria.fr/mantis/view.php?id=5204 > > (The more_unboxing branch in the OCaml SVN implements a different > unboxing strategy.) Actually, even in this branch, acc would not be unboxed. The new heuristic unboxes float variables unless they are both needed in boxed form AND mutated, which is the case for acc in your function. -- Alain