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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id B8EA8BB81 for ; Sat, 19 Nov 2005 17:02:42 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAJG2gaa003947 for ; Sat, 19 Nov 2005 17:02:42 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA10764 for ; Sat, 19 Nov 2005 17:02:41 +0100 (MET) Received: from mx2.mail.ru (mx2.mail.ru [194.67.23.122]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAJG2f0s000745 for ; Sat, 19 Nov 2005 17:02:41 +0100 Received: from [80.237.161.183] (port=28433 helo=bely) by mx2.mail.ru with asmtp id 1EdVAm-0006hn-00 for caml-list@inria.fr; Sat, 19 Nov 2005 19:02:40 +0300 Received: from localhost (HELO BELY) [127.0.0.1] by bely (0.0.0.2) with ESMTP (Classic Hamster Vr. 2.0 Build 2.0.0.1) ; Sat, 19 Nov 2005 18:49:49 +0300 To: caml-list@inria.fr Subject: Bigarray access optimization? From: Dmitry Bely Date: Sat, 19 Nov 2005 18:49:49 +0300 Message-ID: <4q68ljs2.fsf@mail.ru> User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.5 (chayote, windows-nt) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Posting-Agent: Hamster/2.0.0.1 X-Miltered: at nez-perce with ID 437F4CA2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 437F4CA1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bigarray:01 bigarray:01 elt:01 ocamlopt:01 sizeof:01 compiler:01 indexing:01 reusing:01 bigarrays:01 -unsafe:01 sar:98 dmitry:01 dmitry:01 bely:02 bely:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 For the following code open Bigarray let smooth (ba:(float, float32_elt, c_layout) Array2.t) = for i = 1 to (Array2.dim1 ba) - 2 do for j = 1 to (Array2.dim2 ba) - 2 do ba.{i,j} <- (ba.{i,j-1} +. ba.{i,j} +. ba.{i,j+1})/.3.0 done done ocamlopt generates the code that independently calculates offsets of involved bigarray elements 4 times (each time using one "imul", one "add" and two "sar" and several move instructions). Of course it's not necessary - we just need to calculate offset once and then add or subtract sizeof(float) to get ba.{i,j+1} and ba.{i,j-1} offsets accordingly. Can the compiler perform such optimization? Say, testing if the difference between two adjacent indexing expressions is a constant and then reusing the already calculated offest if possible? - Dmitry Bely P.S. BTW, relaxing bounds checking for bigarrays when "-unsafe" option is present seems to be quite easy. Is there a reason why it is not done?