Daniel Peebles wrote: > > Johan Tibell and I have been working on some new primops for GHC that > would allow people to use fast optimized memcpys on unpinned memory.
Why not just use memcpy? > The use > cases I can think of would be in the vector package (possibly the New > stuff in there, but also just as primitives in the classes) Vector already uses memcpy for ByteArray# where possible. Block copy operations on Array# would be helpful, though. > copyByteArray# :: ByteArray# -> Int# -> MutableByteArray# > s -> Int# -> Int# -> State# s -> State# s > copyMutableByteArray# :: MutableByteArray# s -> Int# -> MutableByteArray# > s -> Int# -> Int# -> State# s -> State# s These are just instances of memcpy. FWIW, very similar operations are provided by the primitive package. > cloneArray# :: Array# s a -> State# s -> (# State s, > MutableArray# s a #) > cloneMutableArray# :: MutableArray# s a -> State# s -> (# State s, > MutableArray# s a #) It would be nice if those could be used on array slices. Maybe this: cloneArray# :: Array# a -> Int# -> Int# -> 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 freezeArray# and thawArray# would be safe, i.e., would always copy. Perhaps a block write would also be useful: fillMutableArray# :: MutableArray# s a -> Int# -> Int# -> a -> State# s -> (# State# s, () #) > cloneByteArray# :: ByteArray# -> State# s -> (# State s, > MutableByteArray# s #) > cloneMutableByteArray# :: MutableByteArray# s -> State# s -> (# State s, > MutableByteArray# s #) Aren't these just newMutableByteArray# followed by copy? Why do you want them to be primops? There shouldn't be any speed advantage. > The MutableArray# versions would have to care about the card tables, and > the ByteArray# versions wouldn't. The Mutable -> Mutable versions would > check if the input arrays are the same and use memmove in that case, to > allow fast shuffling around within the same array. IIRC, memmove just calls memcpy if the ranges don't overlap so always calling memmove and having it do the check should be just as fast. Roman _______________________________________________ Cvs-ghc mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-ghc
