summaryrefslogtreecommitdiff
path: root/compiler/prelude
diff options
context:
space:
mode:
authorDuncan Coutts <duncan@well-typed.com>2013-09-13 09:19:24 +0100
committerAustin Seipp <austin@well-typed.com>2013-09-15 12:56:31 -0500
commitf11289f65e77b9e3178b08f5ca4472762c77c42e (patch)
tree59e4709423698dd9e399c35c86fa562a54c90284 /compiler/prelude
parent865956a6ccd88e71aa07a33667242b95ecf98793 (diff)
downloadhaskell-f11289f65e77b9e3178b08f5ca4472762c77c42e.tar.gz
New primops for byte range copies ByteArray# <-> Addr#
We have primops for copying ranges of bytes between ByteArray#s: * ByteArray# -> MutableByteArray# * MutableByteArray# -> MutableByteArray# This extends it with three further cases: * Addr# -> MutableByteArray# * ByteArray# -> Addr# * MutableByteArray# -> Addr# One use case for these is copying between ForeignPtr-based representations and in-heap arrays (like Text, UArray etc). The implementation is essentially the same as for the existing primops, and shares the memcpy stuff in the code generators. Defficiencies / future directions: none of these primops (existing or the new ones) let one take advantage of knowing that ByteArray#s are word-aligned in memory. Though it is unclear that any of the code generators would make use of this information unless the size to copy is also known at compile time. Signed-off-by: Austin Seipp <austin@well-typed.com>
Diffstat (limited to 'compiler/prelude')
-rw-r--r--compiler/prelude/primops.txt.pp36
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp
index a59dfd624d..71dea22c4f 100644
--- a/compiler/prelude/primops.txt.pp
+++ b/compiler/prelude/primops.txt.pp
@@ -1110,6 +1110,42 @@ primop CopyMutableByteArrayOp "copyMutableByteArray#" GenPrimOp
code_size = { primOpCodeSizeForeignCall + 4 }
can_fail = True
+primop CopyByteArrayToAddrOp "copyByteArrayToAddr#" GenPrimOp
+ ByteArray# -> Int# -> Addr# -> Int# -> State# RealWorld -> State# RealWorld
+ {Copy a range of the ByteArray# to the memory range starting at the Addr#.
+ The ByteArray# and the memory region at Addr# must fully contain the
+ specified ranges, but this is not checked. The Addr# must not point into the
+ ByteArray# (e.g. if the ByteArray# were pinned), but this is not checked
+ either.}
+ with
+ has_side_effects = True
+ code_size = { primOpCodeSizeForeignCall + 4}
+ can_fail = True
+
+primop CopyMutableByteArrayToAddrOp "copyMutableByteArrayToAddr#" GenPrimOp
+ MutableByteArray# RealWorld -> Int# -> Addr# -> Int# -> State# RealWorld -> State# RealWorld
+ {Copy a range of the MutableByteArray# to the memory range starting at the
+ Addr#. The MutableByteArray# and the memory region at Addr# must fully
+ contain the specified ranges, but this is not checked. The Addr# must not
+ point into the MutableByteArray# (e.g. if the MutableByteArray# were
+ pinned), but this is not checked either.}
+ with
+ has_side_effects = True
+ code_size = { primOpCodeSizeForeignCall + 4}
+ can_fail = True
+
+primop CopyAddrToByteArrayOp "copyAddrToByteArray#" GenPrimOp
+ Addr# -> MutableByteArray# s -> Int# -> Int# -> State# RealWorld -> State# RealWorld
+ {Copy a memory range starting at the Addr# to the specified range in the
+ MutableByteArray#. The memory region at Addr# and the ByteArray# must fully
+ contain the specified ranges, but this is not checked. The Addr# must not
+ point into the MutableByteArray# (e.g. if the MutableByteArray# were pinned),
+ but this is not checked either.}
+ with
+ has_side_effects = True
+ code_size = { primOpCodeSizeForeignCall + 4}
+ can_fail = True
+
primop SetByteArrayOp "setByteArray#" GenPrimOp
MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
{Set the range of the MutableByteArray# to the specified character.}