From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 4C758BC57 for ; Wed, 31 Mar 2010 20:28:43 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtgBAMMxs0tKfVI2kWdsb2JhbACREIodCBUBAQEBCQkMBw8ksROBbIU8LYhMAQEDBYR7BIMe X-IronPort-AV: E=Sophos;i="4.51,342,1267398000"; d="scan'208";a="60023616" Received: from mail-ww0-f54.google.com ([74.125.82.54]) by mail4-smtp-sop.national.inria.fr with ESMTP; 31 Mar 2010 20:28:38 +0200 Received: by wwb24 with SMTP id 24so269825wwb.27 for ; Wed, 31 Mar 2010 11:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:content-type :content-transfer-encoding; bh=hu7/72aXxF+unlkMxI8WPOnqa1sjw2dWX7XQZ3VZnsA=; b=ncy7V4Gjqmx55XB94lnLmtrFqYpIPZAFeMhs6Ad9xSUOl1qeAfsEix/uAaY1k6FxKN vfe5VaMZf+mtaBWC++yFFjPVbmaecw1g23I8P2ML47yOzk6dTyz9+hjmDa33zSfd1r7W bcw54IVE4TEbw7QQMHQEYwOS38JGW4Sho4Fzk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=nQbCo6M0F+h/SnFbv6px+0hsQjuQg7djEYtR68e4p8saVjxAMp8E4VsHA20VY/k2hN LhrZzCcfB9ivakLiMSQ8S7l2iQpKFdY5B/FcQWY8UV4FTibqaPf1vqojDgz4PRjBFhV5 8esaoYg21LRqyJcM3rDagZGZwowG9dXU/8bPM= MIME-Version: 1.0 Received: by 10.216.88.147 with HTTP; Wed, 31 Mar 2010 11:28:38 -0700 (PDT) In-Reply-To: References: <4A9F9015.2010408@inria.fr> Date: Wed, 31 Mar 2010 22:28:38 +0400 Received: by 10.216.163.67 with SMTP id z45mr1280319wek.26.1270060118545; Wed, 31 Mar 2010 11:28:38 -0700 (PDT) Message-ID: Subject: Re: [Caml-list] Optimizing Float Ref's From: Dmitry Bely To: Caml List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; ref's:01 val:01 unboxed:01 ocaml:01 unboxed:01 lambda:01 val:01 pervasives:01 seq:01 translated:01 translated:01 c--:01 -unsafe:01 alloc:01 2301:01 On Wed, Mar 31, 2010 at 9:55 PM, Jake Donham wrote: > On Wed, Mar 31, 2010 at 10:21 AM, Dmitry Bely wro= te: >> let max_val (a:float array) =3D >> =A0let m =3D ref min_float in >> =A0for i =3D 0 to (Array.length a) - 1 do >> =A0 =A0if a.(i) > !m >> =A0 =A0then m :=3D a.(i) >> =A0done; >> =A0!m >> >> !m is not unboxed (Ocaml 3.11). Should it? > > Why do you say that? It looks unboxed in the lambda code: > > =A0(let > =A0 =A0(max_val/58 > =A0 =A0 =A0 (function a/59 > =A0 =A0 =A0 =A0 (let (m/60 (field 13 (global Pervasives!))) > =A0 =A0 =A0 =A0 =A0 (seq > =A0 =A0 =A0 =A0 =A0 =A0 (for i/61 0 to (- (array.length a/59) 1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (>. (array.get a/59 i/61) m/60) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (assign m/60 (array.get a/59 i/61)) 0a)) > =A0 =A0 =A0 =A0 =A0 =A0 m/60)))) No. "assign" is translated into memory allocation inside the loop. > My x86 assembler is not very good but it looks to me like m is kept in %e= si. Ok, probably returning float makes allocation place not obvious. Try this variant: let max_val (a:float array) =3D let m =3D ref min_float in for i =3D 0 to (Array.length a) - 1 do if a.(i) > !m then m :=3D a.(i) done; truncate !m It's translated into the following C-- code (-unsafe flag): (function camlT__max_val_58 (a/59: addr) (let m/60 (load (+a "camlPervasives" 52)) (let (i/61 1 bound/65 (+ (or (>>u (load (+a a/59 -4)) 10) 1) -2)) (catch (if (> i/61 bound/65) (exit 3) (loop (if (>f (load float64u (+a (+a a/59 (<< i/61 2)) -4)) (load float64u m/60)) (assign m/60 (alloc 2301 (load float64u (+a (+a a/59 (<< i/61 2)) -4)))) []) (let i/64 i/61 (assign i/61 (+ i/61 2)) (if (=3D=3D i/64 bound/65) (exit 3) [])))) with(3) [])) (+ (<< (intoffloat (load float64u m/60)) 1) 1))) See "alloc 2301" inside the loop? That's boxed float. - Dmitry Bely