Skip to content

Feature request: Add index/read/write primops with byte offset for ByteArray#

Currently, primops for indexing ByteArray# and reading/writing MutableByteArray# have the following form:

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#:

-- | 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...

Trac metadata
Trac field Value
Version 7.10.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information