diff options
author | Simon Marlow <marlowsd@gmail.com> | 2009-03-06 10:00:18 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2009-03-06 10:00:18 +0000 |
commit | 1b62aecee4a58f52999cfa53f1c6b7744b29b808 (patch) | |
tree | 94ef6f6bb4e555c5ec27fa85e01ce12068bc1b3d /compiler/prelude/primops.txt.pp | |
parent | a0b4833f77f420053e4b78e40ac17d9687d382e0 (diff) | |
download | haskell-1b62aecee4a58f52999cfa53f1c6b7744b29b808.tar.gz |
Partial fix for #2917
- add newAlignedPinnedByteArray# for allocating pinned BAs with
arbitrary alignment
- the old newPinnedByteArray# now aligns to 16 bytes
Foreign.alloca will use newAlignedPinnedByteArray#, and so might end
up wasting less space than before (we used to align to 8 by default).
Foreign.allocaBytes and Foreign.mallocForeignPtrBytes will get 16-byte
aligned memory, which is enough to avoid problems with SSE
instructions on x86, for example.
There was a bug in the old newPinnedByteArray#: it aligned to 8 bytes,
but would have failed if the header was not a multiple of 8
(fortunately it always was, even with profiling). Also we
occasionally wasted some space unnecessarily due to alignment in
allocatePinned().
I haven't done anything about Foreign.malloc/mallocBytes, which will
give you the same alignment guarantees as malloc() (8 bytes on
Linux/x86 here).
Diffstat (limited to 'compiler/prelude/primops.txt.pp')
-rw-r--r-- | compiler/prelude/primops.txt.pp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp index 3779a79b70..942adb0394 100644 --- a/compiler/prelude/primops.txt.pp +++ b/compiler/prelude/primops.txt.pp @@ -814,6 +814,11 @@ primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp {Create a mutable byte array that the GC guarantees not to move.} with out_of_line = True +primop NewAlignedPinnedByteArrayOp_Char "newAlignedPinnedByteArray#" GenPrimOp + Int# -> Int# -> State# s -> (# State# s, MutableByteArray# s #) + {Create a mutable byte array, aligned by the specified amount, that the GC guarantees not to move.} + with out_of_line = True + primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp ByteArray# -> Addr# {Intended for use with pinned arrays; otherwise very unsafe!} |