From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p4IIp5h1032071 for ; Wed, 18 May 2011 20:51:05 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuwDADIU1E3UGyoDkWdsb2JhbACmHBQBAQEBCQsLBxQDIokOvVCGGQSQEYQvHYor X-IronPort-AV: E=Sophos;i="4.65,232,1304287200"; d="scan'208";a="94954628" Received: from smtp3-g21.free.fr ([212.27.42.3]) by mail2-smtp-roc.national.inria.fr with ESMTP; 18 May 2011 20:50:59 +0200 Received: from [192.168.0.11] (unknown [78.192.0.38]) by smtp3-g21.free.fr (Postfix) with ESMTP id 3E985A62B7; Wed, 18 May 2011 20:50:53 +0200 (CEST) Message-ID: <4DD4150E.6080400@frisch.fr> Date: Wed, 18 May 2011 20:50:54 +0200 From: Alain Frisch User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: Joel Reymont CC: caml-list References: <346B52D2-EE21-43D1-B41E-3AEB3BBF0013@gmail.com> In-Reply-To: <346B52D2-EE21-43D1-B41E-3AEB3BBF0013@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] optimizing numerical code 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.) -- Alain