From: Dmitry Bely <dbely@mail.ru>
To: caml-list@inria.fr
Subject: Bigarray access optimization?
Date: Sat, 19 Nov 2005 18:49:49 +0300 [thread overview]
Message-ID: <4q68ljs2.fsf@mail.ru> (raw)
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?
reply other threads:[~2005-11-19 16:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4q68ljs2.fsf@mail.ru \
--to=dbely@mail.ru \
--cc=caml-list@inria.fr \
/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