[GHC] #11143: Feature request: Add index/read/write primops with byte offset for ByteArray#
GHC
ghc-devs at haskell.org
Sat Nov 28 08:40:00 UTC 2015
#11143: Feature request: Add index/read/write primops with byte offset for
ByteArray#
-------------------------------------+-------------------------------------
Reporter: vagarenko | Owner:
Type: feature | Status: new
request |
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 7.10.2
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
Currently, primops for indexing `ByteArray#` and reading/writing
`MutableByteArray#` have the following form:
{{{#!hs
indexTYPEArray# :: ByteArray# -> Int# -> TYPE#
readTYPEArray# :: MutableByteArray# s -> Int# -> State# s -> (#State# s,
TYPE##)
writeTYPEArray# :: MutableByteArray# s -> Int# -> TYPE# -> State# s ->
State# s
}}}
where second argument of type `Int#` is an offset measured in terms of the
size of `TYPE#`.
This is inconvinient if I want to store values of different types inside
`ByteArray#`: I have to read values of type `Int8` and then glue them
together with some bitwise operations.
I suggest adding number of primops, similar to existing ones, which would
accept offset in bytes from the start of the `ByteArray#`:
{{{#!hs
-- | Read 8-bit integer; offset in bytes.
indexByteInt8Array# :: ByteArray# -> Int# -> Int#
-- | Read 16-bit integer; offset in bytes.
indexByteInt16Array# :: ByteArray# -> Int# -> Int#
-- | Read 32-bit integer; offset in bytes.
indexByteInt32Array# :: ByteArray# -> Int# -> Int#
-- | Read 8-bit integer; offset in bytes.
readInt8Array# :: MutableByteArray# s -> Int# -> State# s -> (#State# s,
Int##)
-- | Read 16-bit integer; offset in bytes.
readInt16Array# :: MutableByteArray# s -> Int# -> State# s -> (#State# s,
Int##)
-- | Read 32-bit integer; offset in bytes.
readInt32Array# :: MutableByteArray# s -> Int# -> State# s -> (#State# s,
Int##)
}}}
and so on...
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11143>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list