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

--
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to