Add unaligned ByteArray# access primops
I would like unaligned store and unaligned load primops in GHC.Prim. Specifically: for X in {Int,Int16,Int32,Int64,Word,Word16,Word32,Word64,Float,Double,WideChar,Addr,StablePtr} and where X# is the corresponding Int#/Word#/Float#/Double#/Char#/Addr#/StablePtr# type, I'd like the following primitives:
-- | Reads an 'X#', offset in bytes
indexXArrayOffBytes# :: ByteArray# -> Int# -> X#
-- | Reads an 'X#', offset in bytes
readXArrayOffBytes# :: MutableByteArray# s -> Int# -> State# s -> (#State# s, X# #)
-- | Writes an 'X#', offset in bytes
writeXArrayOffBytes# :: MutableByteArray# s -> Int# -> X# -> State# s -> State# s
Note that the indexXOffAddr# family of functions already provides unaligned loads and similarly writeXOffAddr# provides unaligned stores, so GHC's code generator must handle these already. For example, we could use these to provide unaligned loads for pinned ByteArray#s:
indexWord16ArrayOffBytes# :: ByteArray# -> Int# -> Word#
indexWord16ArrayOffBytes# arr offset =
indexWord16OffAddr# (byteArrayContents# arr `plusAddr#` offset) 0#
Trac metadata
Trac field | Value |
---|---|
Version | 8.2.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |