
#14447: Add unaligned ByteArray# access primops -------------------------------------+------------------------------------- Reporter: reinerp | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 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: -------------------------------------+------------------------------------- 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: {{{#!hs -- | 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: {{{#!hs indexWord16ArrayOffBytes# :: ByteArray# -> Int# -> Word# indexWord16ArrayOffBytes# arr offset = indexWord16OffAddr# (byteArrayContents# arr `plusAddr#` offset) 0# }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14447 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler