Two additions I think are required: 1) The spec should state that mallocBytes and allocaBytes return a block of memory sufficiently aligned for any of the primitive types supported by the architecture. 2) The description of Storable should require sizeOf x `mod` alignment x = 0 The library implementation of mallocArray implicitly assumes this, and C also requires that elements of an array are allocated contiguously.
On 09-Jan-2003, Ross Paterson <ross@soi.city.ac.uk> wrote:
Two additions I think are required:
1) The spec should state that mallocBytes and allocaBytes return a block of memory sufficiently aligned for any of the primitive types supported by the architecture.
I disagree. These routines should only be required to align the memory sufficiently for any of the primitive types which could fit in the amount of space allocated. For example, double precision floats might occupy 8 bytes, and require 8-byte alignment, but four-bytes allocations should not be required to be 8-byte aligned. (This is something the C standard got wrong, IMHO.) -- Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit The University of Melbourne | of excellence is a lethal habit" WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
Fergus Henderson <fjh@cs.mu.OZ.AU> wrote,
On 09-Jan-2003, Ross Paterson <ross@soi.city.ac.uk> wrote:
Two additions I think are required:
1) The spec should state that mallocBytes and allocaBytes return a block of memory sufficiently aligned for any of the primitive types supported by the architecture.
I disagree. These routines should only be required to align the memory sufficiently for any of the primitive types which could fit in the amount of space allocated. For example, double precision floats might occupy 8 bytes, and require 8-byte alignment, but four-bytes allocations should not be required to be 8-byte aligned.
(This is something the C standard got wrong, IMHO.)
I agree with Fergus. Ross Paterson <ross@soi.city.ac.uk> wrote,
2) The description of Storable should require
sizeOf x `mod` alignment x = 0
The library implementation of mallocArray implicitly assumes this, and C also requires that elements of an array are allocated contiguously.
Ok. I attach the amended description of these functions. Thanks, Manuel -=- \item[sizeOf~~~~::\ Storable a => a -> Int] \item[alignment~::\ Storable a => a -> Int]\combineitems The function \code{sizeOf} computes the storage requirements (in bytes) of the argument, and alignment computes the alignment constraint of the argument. An alignment constraint \code{x} is fulfilled by any address divisible by \code{x}. Both functions do not evaluate their argument, but compute the result on the basis of the type of the argument alone. We require that all the elements of a contiguous array of storable values meet the alignment constraint of these values; more formally, we require that % \begin{quote} \begin{verbatim} sizeOf v `mod` alignment v == 0 \end{verbatim}% \end{quote}
On Mon, Jan 13, 2003 at 09:00:33PM +1100, Manuel M T Chakravarty wrote:
Fergus Henderson <fjh@cs.mu.OZ.AU> wrote,
On 09-Jan-2003, Ross Paterson <ross@soi.city.ac.uk> wrote:
Two additions I think are required:
1) The spec should state that mallocBytes and allocaBytes return a block of memory sufficiently aligned for any of the primitive types supported by the architecture.
I disagree. These routines should only be required to align the memory sufficiently for any of the primitive types which could fit in the amount of space allocated. For example, double precision floats might occupy 8 bytes, and require 8-byte alignment, but four-bytes allocations should not be required to be 8-byte aligned.
(This is something the C standard got wrong, IMHO.)
I agree with Fergus.
Yes, that's even better: a C malloc will satisfy this constraint, but so will others.
\item[sizeOf~~~~::\ Storable a => a -> Int] \item[alignment~::\ Storable a => a -> Int]\combineitems [...] We require that all the elements of a contiguous array of storable values meet the alignment constraint of these values; more formally, we require that % \begin{quote} \begin{verbatim} sizeOf v `mod` alignment v == 0 \end{verbatim}% \end{quote}
How about just: We require that the size is divisible by the alignment. (Thus each element of a contiguous array of storable values will be properly aligned if the first one is.)
Ross Paterson <ross@soi.city.ac.uk> wrote,
On Mon, Jan 13, 2003 at 09:00:33PM +1100, Manuel M T Chakravarty wrote:
Fergus Henderson <fjh@cs.mu.OZ.AU> wrote,
On 09-Jan-2003, Ross Paterson <ross@soi.city.ac.uk> wrote:
Two additions I think are required:
1) The spec should state that mallocBytes and allocaBytes return a block of memory sufficiently aligned for any of the primitive types supported by the architecture.
I disagree. These routines should only be required to align the memory sufficiently for any of the primitive types which could fit in the amount of space allocated. For example, double precision floats might occupy 8 bytes, and require 8-byte alignment, but four-bytes allocations should not be required to be 8-byte aligned.
(This is something the C standard got wrong, IMHO.)
I agree with Fergus.
Yes, that's even better: a C malloc will satisfy this constraint, but so will others.
It now requires, The block of memory is sufficiently aligned for any of the basic foreign types (see Section~\ref{sec:foreign-types}) that fits into a memory block of the allocated size.
\item[sizeOf~~~~::\ Storable a => a -> Int] \item[alignment~::\ Storable a => a -> Int]\combineitems [...] We require that all the elements of a contiguous array of storable values meet the alignment constraint of these values; more formally, we require that % \begin{quote} \begin{verbatim} sizeOf v `mod` alignment v == 0 \end{verbatim}% \end{quote}
How about just:
We require that the size is divisible by the alignment. (Thus each element of a contiguous array of storable values will be properly aligned if the first one is.)
Ok, I am using your more concise wording. Cheers, Manuel
participants (3)
-
Fergus Henderson -
Manuel M T Chakravarty -
Ross Paterson