From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id DAA37BC37 for ; Wed, 27 Jan 2010 17:15:39 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.49,354,1262559600"; d="scan'208";a="42300000" Received: from estephe.inria.fr ([128.93.11.95]) by mail2-relais-roc.national.inria.fr with ESMTP; 27 Jan 2010 17:15:39 +0100 Message-ID: <4B6066AB.5010907@inria.fr> Date: Wed, 27 Jan 2010 17:15:39 +0100 From: Xavier Leroy User-Agent: Thunderbird 2.0.0.17 (X11/20080929) MIME-Version: 1.0 To: Christophe Papazian Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Alignment of data References: <5876A229-025E-47CE-B02F-4B00CD26BFAB@gmail.com> In-Reply-To: <5876A229-025E-47CE-B02F-4B00CD26BFAB@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; alignment:01 alignment:01 ocamlopt:01 aligned:01 aligned:01 powerpc:01 powerpc:01 ocamlopt:01 word-aligned:01 allocator:01 bigarray:01 bigarray:01 stack:01 heap:01 heap:01 > 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