caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dmitry Bely <dmitry.bely@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Optimizing Float Ref's
Date: Wed, 31 Mar 2010 22:28:38 +0400	[thread overview]
Message-ID: <z2r90823c941003311128oc001e648h1f8ff5c731d5cd28@mail.gmail.com> (raw)
In-Reply-To: <p2tc7e4e9f1003311055xce0919wac2118aa3c05f1cb@mail.gmail.com>

On Wed, Mar 31, 2010 at 9:55 PM, Jake Donham <jake@donham.org> wrote:
> On Wed, Mar 31, 2010 at 10:21 AM, Dmitry Bely <dmitry.bely@gmail.com> wrote:
>> let max_val (a:float array) =
>>  let m = ref min_float in
>>  for i = 0 to (Array.length a) - 1 do
>>    if a.(i) > !m
>>    then m := a.(i)
>>  done;
>>  !m
>>
>> !m is not unboxed (Ocaml 3.11). Should it?
>
> Why do you say that? It looks unboxed in the lambda code:
>
>  (let
>    (max_val/58
>       (function a/59
>         (let (m/60 (field 13 (global Pervasives!)))
>           (seq
>             (for i/61 0 to (- (array.length a/59) 1)
>               (if (>. (array.get a/59 i/61) m/60)
>                 (assign m/60 (array.get a/59 i/61)) 0a))
>             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 %esi.

Ok, probably returning float makes allocation place not obvious. Try
this variant:

let max_val (a:float array) =
  let m = ref min_float in
  for i = 0 to (Array.length a) - 1 do
    if a.(i) > !m
    then m := 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 (== 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


  parent reply	other threads:[~2010-03-31 18:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-28 20:32 Will M Farr
2009-08-30 19:43 ` [Caml-list] " Yaron Minsky
2009-08-31 14:09   ` Till Varoquaux
2009-08-31 14:51     ` Will M Farr
2009-08-31 17:30   ` Jon Harrop
2009-08-31 17:15 ` Jon Harrop
2009-09-03  9:44 ` Xavier Leroy
2009-09-03 10:15   ` Will M Farr
2010-03-31 17:21   ` Dmitry Bely
     [not found]     ` <p2tc7e4e9f1003311055xce0919wac2118aa3c05f1cb@mail.gmail.com>
2010-03-31 18:28       ` Dmitry Bely [this message]
2010-03-31 18:59     ` Alain Frisch
2010-03-31 19:18       ` Dmitry Bely
     [not found]         ` <m2lfbd71dab1003311252v5bda5d13vc2146d2d24270847@mail.gmail.com>
2010-03-31 20:00           ` Dmitry Bely
2010-04-14 18:13         ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=z2r90823c941003311128oc001e648h1f8ff5c731d5cd28@mail.gmail.com \
    --to=dmitry.bely@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).