From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7M7wbVF025452 for ; Mon, 22 Aug 2011 09:58:37 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnoBAPQKUk7B/BfTkWdsb2JhbAA5CagnAQEBAQkLCwcUAyKBQAEBBThAARALGAkWDwkDAgECAUUGDQEHAQGHb7USgyiDIASTFIUMi2w X-IronPort-AV: E=Sophos;i="4.68,262,1312149600"; d="scan'208";a="116488299" Received: from msa02.smtpout.orange.fr (HELO msa.smtpout.orange.fr) ([193.252.23.211]) by mail1-smtp-roc.national.inria.fr with ESMTP; 22 Aug 2011 09:58:32 +0200 Received: from [192.168.1.63] ([83.199.49.118]) by mwinf5d06 with ME id PKyX1h0072Z0S2z03KyX1Z; Mon, 22 Aug 2011 09:58:32 +0200 X-ME-engine: default Message-ID: <4E520C27.3020205@lexifi.com> Date: Mon, 22 Aug 2011 09:58:31 +0200 From: Alain Frisch Organization: LexiFi User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.20) Gecko/20110804 Thunderbird/3.1.12 MIME-Version: 1.0 To: Dmitry Bely CC: Caml List References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Validation-by: alain@frisch.fr Subject: Re: [Caml-list] Int32 vs float unboxing 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