caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Bigarray access optimization?
@ 2005-11-19 15:49 Dmitry Bely
  0 siblings, 0 replies; only message in thread
From: Dmitry Bely @ 2005-11-19 15:49 UTC (permalink / raw)
  To: caml-list

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?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-11-19 16:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-19 15:49 Bigarray access optimization? Dmitry Bely

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).