caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain.frisch@lexifi.com>
To: Dmitry Bely <dmitry.bely@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Int32 vs float unboxing
Date: Mon, 22 Aug 2011 09:58:31 +0200	[thread overview]
Message-ID: <4E520C27.3020205@lexifi.com> (raw)
In-Reply-To: <CAMT7qiSc+KHupf2RzwmWV_WRwNt91wTsyJ0gtYE00krqBA8WZQ@mail.gmail.com>

On 08/22/2011 09:19 AM, Dmitry Bely wrote:
> In the code below "s" reference is unboxed in sum_float loop, but not
> in sum_in32. Why?
>
> let sum_int32 v =
>    let s = ref 0l in
>    for i=0 to (Array.length v)-1 do
>      s := Int32.add !s (Array.unsafe_get v i)
>    done;
>    Int32.add !s Int32.zero
>
> let sum_float v =
>    let s = ref 0. in
>    for i=0 to (Array.length v)-1 do
>      s := !s +. (Array.unsafe_get v i)
>    done;
>    !s +. 0.

A random guess: since adding Int32.zero is the identity (contrary to 
adding 0.), the compiler is clever enough to optimize away this useless 
operation; unfortunately, this optimization breaks the unboxing pass.

-- Alain

  reply	other threads:[~2011-08-22  7:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-22  7:19 Dmitry Bely
2011-08-22  7:58 ` Alain Frisch [this message]
2011-08-22  8:33   ` Dmitry Bely
2011-08-24  8:10 ` [Caml-list] " Dmitry Bely

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=4E520C27.3020205@lexifi.com \
    --to=alain.frisch@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=dmitry.bely@gmail.com \
    /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).