[Git][ghc/ghc][master] 2 commits: primops.txt.pp: Move ByteArray# primops to separate file

Marge Bot gitlab at gitlab.haskell.org
Sat Oct 31 06:55:25 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
d5a53c1a by Ben Gamari at 2020-10-31T02:55:10-04:00
primops.txt.pp: Move ByteArray# primops to separate file

This file will be generated.

- - - - -
b4278a41 by Ben Gamari at 2020-10-31T02:55:10-04:00
primops: Generate ByteArray# index/read/write primops

Previously these were mostly undocumented and was ripe for potential
inconsistencies.

- - - - -


3 changed files:

- + compiler/GHC/Builtin/bytearray-ops.txt.pp
- compiler/GHC/Builtin/primops.txt.pp
- + utils/genprimopcode/gen_bytearray_ops.py


Changes:

=====================================
compiler/GHC/Builtin/bytearray-ops.txt.pp
=====================================
@@ -0,0 +1,551 @@
+
+------------------------------------
+-- ByteArray# operations
+------------------------------------
+
+
+-- Do not edit. This file is generated by utils/genprimopcode/gen_bytearray_ops.py.
+-- To regenerate run,
+--
+--      python3 utils/genprimops/gen_bytearray_ops.py > compiler/GHC/Builtin/bytearray-ops.txt.pp
+
+
+------------------------------------
+-- aligned index operations
+------------------------------------
+
+primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
+   ByteArray# -> Int# -> Char#
+   {Read a 8-bit character; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
+   ByteArray# -> Int# -> Char#
+   {Read a 32-bit character; offset in 4-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
+   ByteArray# -> Int# -> Int#
+   {Read a word-sized integer; offset in machine words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
+   ByteArray# -> Int# -> Word#
+   {Read a word-sized unsigned integer; offset in machine words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
+   ByteArray# -> Int# -> Addr#
+   {Read a machine address; offset in machine words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
+   ByteArray# -> Int# -> Float#
+   {Read a single-precision floating-point value; offset in 4-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
+   ByteArray# -> Int# -> Double#
+   {Read a double-precision floating-point value; offset in 8-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
+   ByteArray# -> Int# -> StablePtr# a
+   {Read a {\tt StablePtr#} value; offset in machine words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
+   ByteArray# -> Int# -> Int#
+   {Read a 8-bit signed integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
+   ByteArray# -> Int# -> Int#
+   {Read a 16-bit signed integer; offset in 2-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
+   ByteArray# -> Int# -> INT32
+   {Read a 32-bit signed integer; offset in 4-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
+   ByteArray# -> Int# -> INT64
+   {Read a 64-bit signed integer; offset in 8-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
+   ByteArray# -> Int# -> Word#
+   {Read a 8-bit unsigned integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
+   ByteArray# -> Int# -> Word#
+   {Read a 16-bit unsigned integer; offset in 2-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
+   ByteArray# -> Int# -> WORD32
+   {Read a 32-bit unsigned integer; offset in 4-byte words.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
+   ByteArray# -> Int# -> WORD64
+   {Read a 64-bit unsigned integer; offset in 8-byte words.}
+   with can_fail = True
+
+
+------------------------------------
+-- unaligned index operations
+------------------------------------
+
+primop IndexByteArrayOp_Word8AsChar "indexWord8ArrayAsChar#" GenPrimOp
+   ByteArray# -> Int# -> Char#
+   {Read a 8-bit character; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsWideChar "indexWord8ArrayAsWideChar#" GenPrimOp
+   ByteArray# -> Int# -> Char#
+   {Read a 32-bit character; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsInt "indexWord8ArrayAsInt#" GenPrimOp
+   ByteArray# -> Int# -> Int#
+   {Read a word-sized integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsWord "indexWord8ArrayAsWord#" GenPrimOp
+   ByteArray# -> Int# -> Word#
+   {Read a word-sized unsigned integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsAddr "indexWord8ArrayAsAddr#" GenPrimOp
+   ByteArray# -> Int# -> Addr#
+   {Read a machine address; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsFloat "indexWord8ArrayAsFloat#" GenPrimOp
+   ByteArray# -> Int# -> Float#
+   {Read a single-precision floating-point value; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsDouble "indexWord8ArrayAsDouble#" GenPrimOp
+   ByteArray# -> Int# -> Double#
+   {Read a double-precision floating-point value; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsStablePtr "indexWord8ArrayAsStablePtr#" GenPrimOp
+   ByteArray# -> Int# -> StablePtr# a
+   {Read a {\tt StablePtr#} value; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsInt16 "indexWord8ArrayAsInt16#" GenPrimOp
+   ByteArray# -> Int# -> Int#
+   {Read a 16-bit signed integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsInt32 "indexWord8ArrayAsInt32#" GenPrimOp
+   ByteArray# -> Int# -> INT32
+   {Read a 32-bit signed integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsInt64 "indexWord8ArrayAsInt64#" GenPrimOp
+   ByteArray# -> Int# -> INT64
+   {Read a 64-bit signed integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsWord16 "indexWord8ArrayAsWord16#" GenPrimOp
+   ByteArray# -> Int# -> Word#
+   {Read a 16-bit unsigned integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsWord32 "indexWord8ArrayAsWord32#" GenPrimOp
+   ByteArray# -> Int# -> WORD32
+   {Read a 32-bit unsigned integer; offset in bytes.}
+   with can_fail = True
+
+primop IndexByteArrayOp_Word8AsWord64 "indexWord8ArrayAsWord64#" GenPrimOp
+   ByteArray# -> Int# -> WORD64
+   {Read a 64-bit unsigned integer; offset in bytes.}
+   with can_fail = True
+
+
+------------------------------------
+-- aligned read operations
+------------------------------------
+
+primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
+   {Read a 8-bit character; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
+   {Read a 32-bit character; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
+   {Read a word-sized integer; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
+   {Read a word-sized unsigned integer; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
+   {Read a machine address; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
+   {Read a single-precision floating-point value; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
+   {Read a double-precision floating-point value; offset in 8-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
+   {Read a {\tt StablePtr#} value; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
+   {Read a 8-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
+   {Read a 16-bit signed integer; offset in 2-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT32 #)
+   {Read a 32-bit signed integer; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT64 #)
+   {Read a 64-bit signed integer; offset in 8-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
+   {Read a 8-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
+   {Read a 16-bit unsigned integer; offset in 2-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD32 #)
+   {Read a 32-bit unsigned integer; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD64 #)
+   {Read a 64-bit unsigned integer; offset in 8-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+
+------------------------------------
+-- unaligned read operations
+------------------------------------
+
+primop ReadByteArrayOp_Word8AsChar "readWord8ArrayAsChar#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
+   {Read a 8-bit character; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsWideChar "readWord8ArrayAsWideChar#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
+   {Read a 32-bit character; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsInt "readWord8ArrayAsInt#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
+   {Read a word-sized integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsWord "readWord8ArrayAsWord#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
+   {Read a word-sized unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsAddr "readWord8ArrayAsAddr#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
+   {Read a machine address; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsFloat "readWord8ArrayAsFloat#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
+   {Read a single-precision floating-point value; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsDouble "readWord8ArrayAsDouble#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
+   {Read a double-precision floating-point value; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsStablePtr "readWord8ArrayAsStablePtr#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
+   {Read a {\tt StablePtr#} value; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsInt16 "readWord8ArrayAsInt16#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
+   {Read a 16-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsInt32 "readWord8ArrayAsInt32#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT32 #)
+   {Read a 32-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsInt64 "readWord8ArrayAsInt64#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT64 #)
+   {Read a 64-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsWord16 "readWord8ArrayAsWord16#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
+   {Read a 16-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsWord32 "readWord8ArrayAsWord32#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD32 #)
+   {Read a 32-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop ReadByteArrayOp_Word8AsWord64 "readWord8ArrayAsWord64#" GenPrimOp
+   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD64 #)
+   {Read a 64-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+
+------------------------------------
+-- aligned write operations
+------------------------------------
+
+primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
+   {Write a 8-bit character; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
+   {Write a 32-bit character; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
+   {Write a word-sized integer; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
+   {Write a word-sized unsigned integer; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
+   {Write a machine address; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
+   {Write a single-precision floating-point value; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
+   {Write a double-precision floating-point value; offset in 8-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
+   MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
+   {Write a {\tt StablePtr#} value; offset in machine words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
+   {Write a 8-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
+   {Write a 16-bit signed integer; offset in 2-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> INT32 -> State# s -> State# s
+   {Write a 32-bit signed integer; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> INT64 -> State# s -> State# s
+   {Write a 64-bit signed integer; offset in 8-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
+   {Write a 8-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
+   {Write a 16-bit unsigned integer; offset in 2-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> WORD32 -> State# s -> State# s
+   {Write a 32-bit unsigned integer; offset in 4-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
+   MutableByteArray# s -> Int# -> WORD64 -> State# s -> State# s
+   {Write a 64-bit unsigned integer; offset in 8-byte words.}
+   with has_side_effects = True
+        can_fail = True
+
+
+------------------------------------
+-- unaligned write operations
+------------------------------------
+
+primop WriteByteArrayOp_Word8AsChar "writeWord8ArrayAsChar#" GenPrimOp
+   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
+   {Write a 8-bit character; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsWideChar "writeWord8ArrayAsWideChar#" GenPrimOp
+   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
+   {Write a 32-bit character; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsInt "writeWord8ArrayAsInt#" GenPrimOp
+   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
+   {Write a word-sized integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsWord "writeWord8ArrayAsWord#" GenPrimOp
+   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
+   {Write a word-sized unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsAddr "writeWord8ArrayAsAddr#" GenPrimOp
+   MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
+   {Write a machine address; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsFloat "writeWord8ArrayAsFloat#" GenPrimOp
+   MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
+   {Write a single-precision floating-point value; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsDouble "writeWord8ArrayAsDouble#" GenPrimOp
+   MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
+   {Write a double-precision floating-point value; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsStablePtr "writeWord8ArrayAsStablePtr#" GenPrimOp
+   MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
+   {Write a {\tt StablePtr#} value; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsInt16 "writeWord8ArrayAsInt16#" GenPrimOp
+   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
+   {Write a 16-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsInt32 "writeWord8ArrayAsInt32#" GenPrimOp
+   MutableByteArray# s -> Int# -> INT32 -> State# s -> State# s
+   {Write a 32-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsInt64 "writeWord8ArrayAsInt64#" GenPrimOp
+   MutableByteArray# s -> Int# -> INT64 -> State# s -> State# s
+   {Write a 64-bit signed integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsWord16 "writeWord8ArrayAsWord16#" GenPrimOp
+   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
+   {Write a 16-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsWord32 "writeWord8ArrayAsWord32#" GenPrimOp
+   MutableByteArray# s -> Int# -> WORD32 -> State# s -> State# s
+   {Write a 32-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+
+primop WriteByteArrayOp_Word8AsWord64 "writeWord8ArrayAsWord64#" GenPrimOp
+   MutableByteArray# s -> Int# -> WORD64 -> State# s -> State# s
+   {Write a 64-bit unsigned integer; offset in bytes.}
+   with has_side_effects = True
+        can_fail = True
+


=====================================
compiler/GHC/Builtin/primops.txt.pp
=====================================
@@ -1546,455 +1546,7 @@ primop  GetSizeofMutableByteArrayOp "getSizeofMutableByteArray#" GenPrimOp
    MutableByteArray# s -> State# s -> (# State# s, Int# #)
    {Return the number of elements in the array.}
 
-primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
-   ByteArray# -> Int# -> Char#
-   {Read 8-bit character; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
-   ByteArray# -> Int# -> Char#
-   {Read 31-bit character; offset in 4-byte words.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
-   ByteArray# -> Int# -> Int#
-   with can_fail = True
-
-primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
-   ByteArray# -> Int# -> Word#
-   with can_fail = True
-
-primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
-   ByteArray# -> Int# -> Addr#
-   with can_fail = True
-
-primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
-   ByteArray# -> Int# -> Float#
-   with can_fail = True
-
-primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
-   ByteArray# -> Int# -> Double#
-   with can_fail = True
-
-primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
-   ByteArray# -> Int# -> StablePtr# a
-   with can_fail = True
-
-primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
-   ByteArray# -> Int# -> Int#
-   {Read 8-bit integer; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
-   ByteArray# -> Int# -> Int#
-   {Read 16-bit integer; offset in 16-bit words.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
-   ByteArray# -> Int# -> INT32
-   {Read 32-bit integer; offset in 32-bit words.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
-   ByteArray# -> Int# -> INT64
-   {Read 64-bit integer; offset in 64-bit words.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
-   ByteArray# -> Int# -> Word#
-   {Read 8-bit word; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
-   ByteArray# -> Int# -> Word#
-   {Read 16-bit word; offset in 16-bit words.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
-   ByteArray# -> Int# -> WORD32
-   {Read 32-bit word; offset in 32-bit words.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
-   ByteArray# -> Int# -> WORD64
-   {Read 64-bit word; offset in 64-bit words.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsChar "indexWord8ArrayAsChar#" GenPrimOp
-   ByteArray# -> Int# -> Char#
-   {Read 8-bit character; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsWideChar "indexWord8ArrayAsWideChar#" GenPrimOp
-   ByteArray# -> Int# -> Char#
-   {Read 31-bit character; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsAddr "indexWord8ArrayAsAddr#" GenPrimOp
-   ByteArray# -> Int# -> Addr#
-   {Read address; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsFloat "indexWord8ArrayAsFloat#" GenPrimOp
-   ByteArray# -> Int# -> Float#
-   {Read float; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsDouble "indexWord8ArrayAsDouble#" GenPrimOp
-   ByteArray# -> Int# -> Double#
-   {Read double; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsStablePtr "indexWord8ArrayAsStablePtr#" GenPrimOp
-   ByteArray# -> Int# -> StablePtr# a
-   {Read stable pointer; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsInt16 "indexWord8ArrayAsInt16#" GenPrimOp
-   ByteArray# -> Int# -> Int#
-   {Read 16-bit int; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsInt32 "indexWord8ArrayAsInt32#" GenPrimOp
-   ByteArray# -> Int# -> INT32
-   {Read 32-bit int; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsInt64 "indexWord8ArrayAsInt64#" GenPrimOp
-   ByteArray# -> Int# -> INT64
-   {Read 64-bit int; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsInt "indexWord8ArrayAsInt#" GenPrimOp
-   ByteArray# -> Int# -> Int#
-   {Read int; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsWord16 "indexWord8ArrayAsWord16#" GenPrimOp
-   ByteArray# -> Int# -> Word#
-   {Read 16-bit word; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsWord32 "indexWord8ArrayAsWord32#" GenPrimOp
-   ByteArray# -> Int# -> WORD32
-   {Read 32-bit word; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsWord64 "indexWord8ArrayAsWord64#" GenPrimOp
-   ByteArray# -> Int# -> WORD64
-   {Read 64-bit word; offset in bytes.}
-   with can_fail = True
-
-primop IndexByteArrayOp_Word8AsWord "indexWord8ArrayAsWord#" GenPrimOp
-   ByteArray# -> Int# -> Word#
-   {Read word; offset in bytes.}
-   with can_fail = True
-
-primop  ReadByteArrayOp_Char "readCharArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
-   {Read 8-bit character; offset in bytes.}
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
-   {Read 31-bit character; offset in 4-byte words.}
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Int "readIntArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
-   {Read integer; offset in machine words.}
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word "readWordArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
-   {Read word; offset in machine words.}
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT32 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT64 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD32 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD64 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsChar "readWord8ArrayAsChar#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsWideChar "readWord8ArrayAsWideChar#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsAddr "readWord8ArrayAsAddr#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsFloat "readWord8ArrayAsFloat#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsDouble "readWord8ArrayAsDouble#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsStablePtr "readWord8ArrayAsStablePtr#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsInt16 "readWord8ArrayAsInt16#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsInt32 "readWord8ArrayAsInt32#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT32 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsInt64 "readWord8ArrayAsInt64#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT64 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsInt "readWord8ArrayAsInt#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsWord16 "readWord8ArrayAsWord16#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsWord32 "readWord8ArrayAsWord32#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD32 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsWord64 "readWord8ArrayAsWord64#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD64 #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  ReadByteArrayOp_Word8AsWord "readWord8ArrayAsWord#" GenPrimOp
-   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
-   {Write 8-bit character; offset in bytes.}
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
-   {Write 31-bit character; offset in 4-byte words.}
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
-   MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> INT32 -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> INT64 -> State# s -> State# s
-   with can_fail = True
-        has_side_effects = True
-
-primop  WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> WORD32 -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
-   MutableByteArray# s -> Int# -> WORD64 -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsChar "writeWord8ArrayAsChar#" GenPrimOp
-   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsWideChar "writeWord8ArrayAsWideChar#" GenPrimOp
-   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsAddr "writeWord8ArrayAsAddr#" GenPrimOp
-   MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsFloat "writeWord8ArrayAsFloat#" GenPrimOp
-   MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsDouble "writeWord8ArrayAsDouble#" GenPrimOp
-   MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsStablePtr "writeWord8ArrayAsStablePtr#" GenPrimOp
-   MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsInt16 "writeWord8ArrayAsInt16#" GenPrimOp
-   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsInt32 "writeWord8ArrayAsInt32#" GenPrimOp
-   MutableByteArray# s -> Int# -> INT32 -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsInt64 "writeWord8ArrayAsInt64#" GenPrimOp
-   MutableByteArray# s -> Int# -> INT64 -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsInt "writeWord8ArrayAsInt#" GenPrimOp
-   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsWord16 "writeWord8ArrayAsWord16#" GenPrimOp
-   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsWord32 "writeWord8ArrayAsWord32#" GenPrimOp
-   MutableByteArray# s -> Int# -> WORD32 -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsWord64 "writeWord8ArrayAsWord64#" GenPrimOp
-   MutableByteArray# s -> Int# -> WORD64 -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
-
-primop  WriteByteArrayOp_Word8AsWord "writeWord8ArrayAsWord#" GenPrimOp
-   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
-   with has_side_effects = True
-        can_fail = True
+#include "bytearray-ops.txt.pp"
 
 primop  CompareByteArraysOp "compareByteArrays#" GenPrimOp
    ByteArray# -> Int# -> ByteArray# -> Int# -> Int# -> Int#


=====================================
utils/genprimopcode/gen_bytearray_ops.py
=====================================
@@ -0,0 +1,144 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from typing import Optional, NamedTuple
+import textwrap
+
+class ElementType(NamedTuple):
+    name: str
+    rep_ty: str
+    desc: str
+    width: Optional[int]
+
+MACH_WORD = None
+
+element_types = [
+    # (name, representation type, human description, width)
+    #
+    # width in bytes.
+    # width == None denotes machine word
+
+    ElementType("Char",      "Char#",        "8-bit character",                       1),
+    ElementType("WideChar",  "Char#",        "32-bit character",                      4),
+    ElementType("Int",       "Int#",         "word-sized integer",                    MACH_WORD),
+    ElementType("Word",      "Word#",        "word-sized unsigned integer",           MACH_WORD),
+    ElementType("Addr",      "Addr#",        "machine address",                       MACH_WORD),
+    ElementType("Float",     "Float#",       "single-precision floating-point value", 4),
+    ElementType("Double",    "Double#",      "double-precision floating-point value", 8),
+    ElementType("StablePtr", "StablePtr# a", "{\\tt StablePtr#} value",               MACH_WORD),
+]
+
+# TODO: Eventually when the sized integer primops use proper unboxed types we
+# should rather do:
+#
+#for n in [8,16,32,64]:
+#    element_types += [ ElementType(f"Int{n}",  f"Int{n}#",  f"{n}-bit signed integer",   n // 8) ]
+#
+#for n in [8,16,32,64]:
+#    element_types += [ ElementType(f"Word{n}", f"Word{n}#", f"{n}-bit unsigned integer", n // 8) ]
+
+element_types += [
+    ElementType("Int8",   "Int#",  "8-bit signed integer",  1),
+    ElementType("Int16",  "Int#",  "16-bit signed integer", 2),
+    ElementType("Int32",  "INT32", "32-bit signed integer", 4),
+    ElementType("Int64",  "INT64", "64-bit signed integer", 8),
+
+    ElementType("Word8",  "Word#",  "8-bit unsigned integer",  1),
+    ElementType("Word16", "Word#",  "16-bit unsigned integer", 2),
+    ElementType("Word32", "WORD32", "32-bit unsigned integer", 4),
+    ElementType("Word64", "WORD64", "64-bit unsigned integer", 8),
+]
+
+def pretty_offset(n: Optional[int]) -> str:
+    if n == MACH_WORD:
+        return 'machine words'
+    elif n == 1:
+        return 'bytes'
+    else:
+        return f'{n}-byte words'
+
+def print_block(template: str, **kwargs) -> None:
+    print(textwrap.dedent(template.format(**kwargs)).lstrip())
+
+def header(s: str):
+    print('')
+    print_block('''
+        ------------------------------------
+        -- {s}
+        ------------------------------------
+    ''', s=s)
+
+
+header("ByteArray# operations")
+
+print('''
+-- Do not edit. This file is generated by utils/genprimopcode/gen_bytearray_ops.py.
+-- To regenerate run,
+--
+--      python3 utils/genprimops/gen_bytearray_ops.py > compiler/GHC/Builtin/bytearray-ops.txt.pp
+''')
+
+header('aligned index operations')
+for t in element_types:
+    offset = pretty_offset(t.width)
+    print_block('''
+        primop IndexByteArrayOp_{name} "index{name}Array#" GenPrimOp
+           ByteArray# -> Int# -> {rep_ty}
+           {{Read a {desc}; offset in {offset}.}}
+           with can_fail = True
+    ''', offset = offset, **t._asdict())
+
+header('unaligned index operations')
+for t in element_types:
+    if t.name in ['Int8', 'Word8']: continue
+    print_block('''
+        primop IndexByteArrayOp_Word8As{name} "indexWord8ArrayAs{name}#" GenPrimOp
+           ByteArray# -> Int# -> {rep_ty}
+           {{Read a {desc}; offset in bytes.}}
+           with can_fail = True
+    ''', **t._asdict())
+
+header('aligned read operations')
+for t in element_types:
+    offset = pretty_offset(t.width)
+    print_block('''
+        primop ReadByteArrayOp_{name} "read{name}Array#" GenPrimOp
+           MutableByteArray# s -> Int# -> State# s -> (# State# s, {rep_ty} #)
+           {{Read a {desc}; offset in {offset}.}}
+           with has_side_effects = True
+                can_fail = True
+    ''', offset = offset, **t._asdict())
+
+header('unaligned read operations')
+for t in element_types:
+    if t.name in ['Int8', 'Word8']: continue
+    print_block('''
+        primop ReadByteArrayOp_Word8As{name} "readWord8ArrayAs{name}#" GenPrimOp
+           MutableByteArray# s -> Int# -> State# s -> (# State# s, {rep_ty} #)
+           {{Read a {desc}; offset in bytes.}}
+           with has_side_effects = True
+                can_fail = True
+    ''', **t._asdict())
+
+header('aligned write operations')
+for t in element_types:
+    offset = pretty_offset(t.width)
+    print_block('''
+        primop WriteByteArrayOp_{name} "write{name}Array#" GenPrimOp
+           MutableByteArray# s -> Int# -> {rep_ty} -> State# s -> State# s
+           {{Write a {desc}; offset in {offset}.}}
+           with has_side_effects = True
+                can_fail = True
+    ''', offset = offset, **t._asdict())
+
+header('unaligned write operations')
+for t in element_types:
+    if t.name in ['Int8', 'Word8']: continue
+    print_block('''
+        primop WriteByteArrayOp_Word8As{name} "writeWord8ArrayAs{name}#" GenPrimOp
+           MutableByteArray# s -> Int# -> {rep_ty} -> State# s -> State# s
+           {{Write a {desc}; offset in bytes.}}
+           with has_side_effects = True
+                can_fail = True
+    ''', **t._asdict())
+



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/730ef38f467d67f4f664b2b4a5f4b236864e97b2...b4278a41a18132a981b25c59b296cdf3ba970024

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/730ef38f467d67f4f664b2b4a5f4b236864e97b2...b4278a41a18132a981b25c59b296cdf3ba970024
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201031/e2decf97/attachment-0001.html>


More information about the ghc-commits mailing list