Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Christophe Papazian <christophe.papazian@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Alignment of data
Date: Wed, 27 Jan 2010 17:15:39 +0100	[thread overview]
Message-ID: <4B6066AB.5010907@inria.fr> (raw)
In-Reply-To: <5876A229-025E-47CE-B02F-4B00CD26BFAB@gmail.com>

> I am working on some ppc architecture, and I realize that I have a 
> (very) big slowdown due to bad alignment of data by ocamlopt. I need to 
> have my data aligned in memory depending of the size of the data : 
> floats are to be aligned on 8 bytes, int on 4 bytes, etc....

First, make sure that misalignment is really the source of your
slowdown.  The PowerPC processors I'm familiar with can access
4-aligned 8-byte floats with minimal overhead, while the penalty is
much bigger for other misalignments.  Indeed, the PowerPC calling
conventions mandate that some 8-byte float arguments are passed on the
stack at 4-aligned addresses, so that's strong incentive for the
hardware people to implement those accesses efficiently.

> BUT, after verification, I remark that ocamlopt doesn't align as I need. 
> I tried to use ARCH_ALIGN_DOUBLE, but it doesn't seem to be what I 
> thought, and doesn't change anything for my needs. Is there ANY way to 
> obtain what I need easily or at least quickly ?

Data allocated in the Caml heap is word-aligned, where a word is 4
bytes on a 32-bit platform and 8 bytes on a 64-bit platform.  This is
deeply ingrained in the Caml GC and allocator, so don't expect to
change this easily.

What you can do, however:

1- Use the 64-bit PowerPC port.  Everything will be 8-aligned then.

2- Use a bigarray instead of a float array.  Bigarray data is
allocated outside the heap, at naturally-aligned addresses.

- Xavier Leroy


  parent reply	other threads:[~2010-01-27 16:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-27 12:03 Christophe Papazian
2010-01-27 15:26 ` [Caml-list] " Goswin von Brederlow
2010-01-27 16:15 ` Xavier Leroy [this message]
2010-01-27 17:20   ` Christophe Papazian
2010-01-27 17:56     ` Richard Jones
     [not found] <20100127161719.C6A10BC37@yquem.inria.fr>
2010-01-27 16:38 ` Pascal Cuoq
2010-01-27 21:01   ` [Caml-list] " Goswin von Brederlow

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=4B6066AB.5010907@inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=christophe.papazian@gmail.com \
    /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