From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A40F7BC8D for ; Sat, 15 Jan 2005 18:13:22 +0100 (CET) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.193]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0FHDLkh014500 for ; Sat, 15 Jan 2005 18:13:22 +0100 Received: by wproxy.gmail.com with SMTP id 69so185912wri for ; Sat, 15 Jan 2005 09:13:21 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=NkJX+KQ/K3ht83DP9s6nfWodKQ1K5I+kfyYsmnzdDbn/GAeYmuS/C5rFMlU2S2ttrs3Bs2Up+EyTp85ux1NkDTyML8xxhuMahoRt+8dEnYeD1sTvbHpxATLfQxkWHQixJGZ1lXUb2jkKHLAmzAm4fY1Sbd8ySjBQBy1JmpeQB+Y= Received: by 10.54.44.50 with SMTP id r50mr162618wrr; Sat, 15 Jan 2005 09:13:21 -0800 (PST) Received: by 10.54.2.70 with HTTP; Sat, 15 Jan 2005 09:13:21 -0800 (PST) Message-ID: <891bd3390501150913453772a4@mail.gmail.com> Date: Sat, 15 Jan 2005 12:13:21 -0500 From: Yaron Minsky Reply-To: yminsky@cs.cornell.edu To: Xavier Leroy Subject: Re: [Caml-list] Ocaml sums the harmonic series -- four ways, four benchmarks: floating point performance Cc: "Will M. Farr" , shootout-list@lists.alioth.debian.org, caml-list@yquem.inria.fr In-Reply-To: <20050115115519.GA11037@yquem.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <3D3A6BF5-657B-11D9-A551-000393A34E82@mit.edu> <20050115115519.GA11037@yquem.inria.fr> X-Miltered: at nez-perce with ID 41E94F31.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 caml-list:01 ocaml:01 wrote:01 compiler:01 ocamlopt:01 unboxed:01 surprising:01 compiler:01 unboxing:01 inlining:01 inlined:01 unboxed:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.0 X-Spam-Level: On Sat, 15 Jan 2005 12:55:19 +0100, Xavier Leroy wrote: > The following slight modification of your code generates asm code that > is closest to what a C compiler would produce: > > let sum_harmonic5 n = > let sum = ref 1.0 in > let ifloat = ref 2.0 in > for i = 2 to n do > sum := !sum +. 1.0/.(!ifloat); > ifloat := !ifloat +. 1.0 > done; > !sum +. 0.0;; > > The + 0.0 at the end is ugly but convinces ocamlopt that !sum is best > kept unboxed during the loop. That last comment is very interesting and surprising to me. I've looked over the optimization suggestions for the compiler, and I don't understand why that last +. convinces the compiler to unbox sum. Can you explain why that is? Floating point performance is important to me, and I'd like to get a better grasp on it. (As a general matter, it would be nice to have some tools to understand things like unboxing and inlining a little better. For example, it would be great to have something akin to -dtypes that outputs information with which one could check whether a certain function call is inlined, or whether a certain float is unboxed.) y