#4928: Add primops for copying/cloning an array
---------------------------------+------------------------------------------
    Reporter:  tibbe             |       Owner:                
        Type:  feature request   |      Status:  new           
    Priority:  normal            |   Component:  Runtime System
     Version:  7.0.1             |    Keywords:                
    Testcase:                    |   Blockedby:                
          Os:  Unknown/Multiple  |    Blocking:                
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown  
---------------------------------+------------------------------------------
 Daniel Peebles's benchmarks show that copying arrays using a
 `indexArray#`/`writeArray#` loop is much slower than using a (new) primop
 that calls `memcpy`. In addition, cloning arrays is slower than it need to
 be due to `newArray#` filling the array with a default element, just to
 have all the elements be overwritten by the contents of the array being
 cloned.

 I suggest we add the following primops:

 {{{
 copyArray#        ::        Array# a -> Int# -> MutableArray# s a -> Int#
 -> Int# -> State# s -> State# s
 copyMutableArray# :: MutableArray# a -> Int# -> MutableArray# s a -> Int#
 -> Int# -> State# s -> State# s

 cloneArray#        ::        Array#   a -> Int# -> Int# -> State# s -> (#
 State# s, Array# a #)
 cloneMutableArray# :: MutableArray# s a -> Int# -> Int# -> State# s -> (#
 State# s, MutableArray# s a #)

 freezeArray# :: MutableArray# s a -> Int# -> Int# -> State# s -> (# State#
 s, Array# a #)
 thawArray#   ::        Array#   a -> Int# -> Int# -> State# s -> (# State#
 s, MutableArray# s a #)
 }}}

 Note that `ByteArray#` versions can be created using FFI calls to `memcpy`
 and thus don't need to be primops.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4928>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to