Commit 8c705e99 authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Add a setByteArray# primop

Essentially, this is a wrapper around memset
parent e5191c95
......@@ -404,12 +404,14 @@ emitPrimOp res WriteByteArrayOp_Word16 args _ = doWriteByteArrayOp (Just mo_W
emitPrimOp res WriteByteArrayOp_Word32 args _ = doWriteByteArrayOp (Just mo_WordTo32) b32 res args
emitPrimOp res WriteByteArrayOp_Word64 args _ = doWriteByteArrayOp Nothing b64 res args
-- Copying byte arrays
-- Copying and setting byte arrays
emitPrimOp [] CopyByteArrayOp [src,src_off,dst,dst_off,n] live =
doCopyByteArrayOp src src_off dst dst_off n live
emitPrimOp [] CopyMutableByteArrayOp [src,src_off,dst,dst_off,n] live =
doCopyMutableByteArrayOp src src_off dst dst_off n live
emitPrimOp [] SetByteArrayOp [ba,off,len,c] live =
doSetByteArrayOp ba off len c live
-- Population count
emitPrimOp [res] PopCnt8Op [w] live = emitPopCntCall res w W8 live
......@@ -907,6 +909,18 @@ emitCopyByteArray copy src src_off dst dst_off n live = do
src_p <- assignTemp $ cmmOffsetExpr (cmmOffsetB src arrWordsHdrSize) src_off
copy src dst dst_p src_p n live
-- ----------------------------------------------------------------------------
-- Setting byte arrays
-- | Takes a 'MutableByteArray#', an offset into the array, a length,
-- and a byte, and sets each of the selected bytes in the array to the
-- character.
doSetByteArrayOp :: CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr
-> StgLiveVars -> Code
doSetByteArrayOp ba off len c live
= do p <- assignTemp $ cmmOffsetExpr (cmmOffsetB ba arrWordsHdrSize) off
emitMemsetCall p c len (CmmLit (mkIntCLit 1)) live
-- ----------------------------------------------------------------------------
-- Copying pointer arrays
......
......@@ -478,11 +478,13 @@ emitPrimOp res WriteByteArrayOp_Word16 args = doWriteByteArrayOp (Just mo_Wor
emitPrimOp res WriteByteArrayOp_Word32 args = doWriteByteArrayOp (Just mo_WordTo32) res args
emitPrimOp res WriteByteArrayOp_Word64 args = doWriteByteArrayOp Nothing res args
-- Copying byte arrays
-- Copying and setting byte arrays
emitPrimOp [] CopyByteArrayOp [src,src_off,dst,dst_off,n] =
doCopyByteArrayOp src src_off dst dst_off n
emitPrimOp [] CopyMutableByteArrayOp [src,src_off,dst,dst_off,n] =
doCopyMutableByteArrayOp src src_off dst dst_off n
emitPrimOp [] SetByteArrayOp [ba,off,len,c] =
doSetByteArrayOp ba off len c
-- Population count
emitPrimOp [res] PopCnt8Op [w] = emitPopCntCall res w W8
......@@ -813,6 +815,18 @@ emitCopyByteArray copy src src_off dst dst_off n = do
src_p <- assignTempE $ cmmOffsetExpr (cmmOffsetB src arrWordsHdrSize) src_off
copy src dst dst_p src_p n
-- ----------------------------------------------------------------------------
-- Setting byte arrays
-- | Takes a 'MutableByteArray#', an offset into the array, a length,
-- and a byte, and sets each of the selected bytes in the array to the
-- character.
doSetByteArrayOp :: CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr
-> FCode ()
doSetByteArrayOp ba off len c
= do p <- assignTempE $ cmmOffsetExpr (cmmOffsetB ba arrWordsHdrSize) off
emitMemsetCall p c len (CmmLit (mkIntCLit 1))
-- ----------------------------------------------------------------------------
-- Copying pointer arrays
......
......@@ -1057,6 +1057,14 @@ primop CopyMutableByteArrayOp "copyMutableByteArray#" GenPrimOp
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.}
with
has_side_effects = True
code_size = { primOpCodeSizeForeignCall + 4 }
can_fail = True
------------------------------------------------------------------------
section "Arrays of arrays"
{Operations on {\tt ArrayArray\#}. An {\tt ArrayArray\#} contains references to {\em unpointed}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment