{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UndecidableInstances #-}
-- |
-- Module      : Data.Prim.Class
-- Copyright   : (c) Alexey Kuleshevich 2020
-- License     : BSD3
-- Maintainer  : Alexey Kuleshevich <alexey@kuleshevi.ch>
-- Stability   : experimental
-- Portability : non-portable
--
module Data.Prim.Class
  ( Prim(..)
  , setMutableByteArrayLoop#
  , setOffAddrLoop#
  , errorImpossible
  , bool2Int#
  , int2Bool#
  -- * Backwards compatibility
  , WordPtr(..)
  , ptrToWordPtr
  , wordPtrToPtr
  , IntPtr(..)
  , ptrToIntPtr
  , intPtrToPtr
  ) where


#include "MachDeps.h"
#include "HsBaseConfig.h"

import Control.Prim.Monad.Unsafe
import Data.Bits
import Data.Complex
import Data.Char
import Data.Type.Equality
import Foreign.C.Error (Errno(..))
import Foreign.Prim hiding (Any)
import GHC.Conc
import GHC.Stable
import GHC.Real
import GHC.IO.Device
import GHC.Fingerprint.Type
import GHC.TypeLits as Nats
import Data.Functor.Compose
import Data.Functor.Identity
import qualified Data.Functor.Product as Functor
import Data.Monoid
import System.IO
import Data.Semigroup
#if __GLASGOW_HASKELL__ >= 800
import Data.Functor.Const
#endif /* __GLASGOW_HASKELL__ >= 800 */

#if __GLASGOW_HASKELL__ < 802
import qualified Foreign.Ptr as P
import Unsafe.Coerce
#include "primal_compat.h"

import Foreign.Storable (Storable)

-- | Replacement for `Foreign.Ptr.IntPtr` with exported constructor.
newtype IntPtr = IntPtr Int
  deriving (Eq, Ord, Num, Enum, Storable, Real, Bounded, Integral, Bits, FiniteBits, Read, Show)

-- | Replacement for `Foreign.Ptr.WordPtr` with exported constructor.
newtype WordPtr = WordPtr Word
  deriving (Eq, Ord, Num, Enum, Storable, Real, Bounded, Integral, Bits, FiniteBits, Read, Show)

-- | casts a @Ptr@ to a @WordPtr@
ptrToWordPtr :: Ptr a -> WordPtr
ptrToWordPtr (Ptr a#) = WordPtr (W# (int2Word# (addr2Int# a#)))

-- | casts a @WordPtr@ to a @Ptr@
wordPtrToPtr :: WordPtr -> Ptr a
wordPtrToPtr (WordPtr (W# w#)) = Ptr (int2Addr# (word2Int# w#))

-- | casts a @Ptr@ to an @IntPtr@
ptrToIntPtr :: Ptr a -> IntPtr
ptrToIntPtr (Ptr a#) = IntPtr (I# (addr2Int# a#))

-- | casts an @IntPtr@ to a @Ptr@
intPtrToPtr :: IntPtr -> Ptr a
intPtrToPtr (IntPtr (I# i#)) = Ptr (int2Addr# i#)

instance Prim P.IntPtr where
  type PrimBase P.IntPtr = IntPtr
  -- Constructor for newtype was not exported
  toPrimBase = unsafeCoerce
  fromPrimBase = unsafeCoerce

instance Prim P.WordPtr where
  type PrimBase P.WordPtr = WordPtr
  -- Constructor for newtype was not exported
  toPrimBase = unsafeCoerce
  fromPrimBase = unsafeCoerce
#else
import Foreign.Ptr
#endif

-- | Invariants:
--
-- * Reading should never fail on memory that contains only zeros
--
-- * Writing should always overwrite all of the bytes allocated for the element. In other
--   words, writing to a dirty (uninitilized) region of memory should never leave any
--   garbage around. For example, if a type requires 31 bytes of memory then on any write
--   all 31 bytes must be overwritten.
--
-- * A single thread write/read sequence must always roundtrip
--
-- * This is not a class for serialization, therefore memory layout of unpacked datatype
--   is selfcontained in `Prim` class and representation is not expected to stay the same
--   between different versions of software. Primitive types like `Int`, `Word`, `Char`
--   are an exception to this rule for obvious reasons.
--
class Prim a where
  type PrimBase a :: *

  type SizeOf a :: Nat
  type SizeOf a = SizeOf (PrimBase a)
  type Alignment a :: Nat
  type Alignment a = Alignment (PrimBase a)

  toPrimBase :: a -> PrimBase a
  default toPrimBase :: Coercible a (PrimBase a) => a -> PrimBase a
  toPrimBase = a -> PrimBase a
coerce

  fromPrimBase :: PrimBase a -> a
  default fromPrimBase :: Coercible a (PrimBase a) => PrimBase a -> a
  fromPrimBase = PrimBase a -> a
coerce

  -- | Returned value must match the `SizeOf` type level Nat
  sizeOf# :: Proxy# a -> Int#
  default sizeOf# :: Prim (PrimBase a) => Proxy# a -> Int#
  sizeOf# Proxy# a
_ = Proxy# (PrimBase a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (PrimBase a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (PrimBase a))
  {-# INLINE sizeOf# #-}

  -- | Returned value must match the `Alignment` type level Nat
  alignment# :: Proxy# a -> Int#
  default alignment# :: Prim (PrimBase a) => Proxy# a -> Int#
  alignment# Proxy# a
_ = Proxy# (PrimBase a) -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# (PrimBase a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (PrimBase a))
  {-# INLINE alignment# #-}


  indexByteOffByteArray# :: ByteArray# -> Int# -> a
  default indexByteOffByteArray# :: Prim (PrimBase a) => ByteArray# -> Int# -> a
  indexByteOffByteArray# ByteArray#
ba# Int#
i# = PrimBase a -> a
forall a. Prim a => PrimBase a -> a
fromPrimBase (ByteArray# -> Int# -> PrimBase a
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i# :: PrimBase a)
  {-# INLINE indexByteOffByteArray# #-}

  --
  -- These equalities hold:
  --
  -- > indexByteArray# ba# i# == indexOffAddr# (byteArrayContents# ba#) i#
  --
  -- > indexByteArray# ba# i# == indexByteOffByteArray# ba# (i# *# sizeOf (proxy# :: Proxy# a))
  --
  indexByteArray# :: ByteArray# -> Int# -> a
  default indexByteArray# :: Prim (PrimBase a) => ByteArray# -> Int# -> a
  indexByteArray# ByteArray#
ba# Int#
i# = PrimBase a -> a
forall a. Prim a => PrimBase a -> a
fromPrimBase (ByteArray# -> Int# -> PrimBase a
forall a. Prim a => ByteArray# -> Int# -> a
indexByteArray# ByteArray#
ba# Int#
i# :: PrimBase a)
  {-# INLINE indexByteArray# #-}

  indexOffAddr# :: Addr# -> Int# -> a
  default indexOffAddr# :: Prim (PrimBase a) => Addr# -> Int# -> a
  indexOffAddr# Addr#
addr# Int#
i# = PrimBase a -> a
forall a. Prim a => PrimBase a -> a
fromPrimBase (Addr# -> Int# -> PrimBase a
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# Addr#
addr# Int#
i# :: PrimBase a)
  {-# INLINE indexOffAddr# #-}


  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
  default readByteOffMutableByteArray# ::
    Prim (PrimBase a) => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
  readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s
-> Int# -> State# s -> (# State# s, PrimBase a #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', pa :: PrimBase a #) -> (# State# s
s', PrimBase a -> a
forall a. Prim a => PrimBase a -> a
fromPrimBase PrimBase a
pa #)
  {-# INLINE readByteOffMutableByteArray# #-}

  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
  default readMutableByteArray# ::
    Prim (PrimBase a) => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
  readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s
-> Int# -> State# s -> (# State# s, PrimBase a #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', pa :: PrimBase a #) -> (# State# s
s', PrimBase a -> a
forall a. Prim a => PrimBase a -> a
fromPrimBase PrimBase a
pa #)
  {-# INLINE readMutableByteArray# #-}

  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, a #)
  default readOffAddr# ::
    Prim (PrimBase a) => Addr# -> Int# -> State# s -> (# State# s, a #)
  readOffAddr# Addr#
addr# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, PrimBase a #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# Addr#
addr# Int#
i# State# s
s of
                              (# State# s
s', pa :: PrimBase a #) -> (# State# s
s', PrimBase a -> a
forall a. Prim a => PrimBase a -> a
fromPrimBase PrimBase a
pa #)
  {-# INLINE readOffAddr# #-}


  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> a -> State# s -> State# s
  default writeByteOffMutableByteArray# ::
    Prim (PrimBase a) => MutableByteArray# s -> Int# -> a -> State# s -> State# s
  writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# a
a =
    MutableByteArray# s -> Int# -> PrimBase a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (a -> PrimBase a
forall a. Prim a => a -> PrimBase a
toPrimBase a
a :: PrimBase a)
  {-# INLINE writeByteOffMutableByteArray# #-}

  writeMutableByteArray# :: MutableByteArray# s -> Int# -> a -> State# s -> State# s
  default writeMutableByteArray# ::
    Prim (PrimBase a) => MutableByteArray# s -> Int# -> a -> State# s -> State# s
  writeMutableByteArray# MutableByteArray# s
mba# Int#
i# a
a = MutableByteArray# s -> Int# -> PrimBase a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (a -> PrimBase a
forall a. Prim a => a -> PrimBase a
toPrimBase a
a :: PrimBase a)
  {-# INLINE writeMutableByteArray# #-}

  writeOffAddr# :: Addr# -> Int# -> a -> State# s -> State# s
  default writeOffAddr# :: Prim (PrimBase a) => Addr# -> Int# -> a -> State# s -> State# s
  writeOffAddr# Addr#
addr# Int#
i# a
a = Addr# -> Int# -> PrimBase a -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr# Int#
i# (a -> PrimBase a
forall a. Prim a => a -> PrimBase a
toPrimBase a
a)
  {-# INLINE writeOffAddr# #-}

  -- TODO: implement
  -- setByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
  -- default setMutableByteArray# ::
  --   Prim (PrimBase a) => MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
  -- setByteOffMutableByteArray# mba# i# n# a = setByteOffMutableByteArray# mba# i# n# (toPrimBase a)
  -- {-# INLINE setByteOffMutableByteArray# #-}

  -- | Set the region of MutableByteArray to the same value. Offset is in number of elements
  setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
  default setMutableByteArray# ::
    Prim (PrimBase a) => MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
  setMutableByteArray# MutableByteArray# s
mba# Int#
i# Int#
n# a
a = MutableByteArray# s
-> Int# -> Int# -> PrimBase a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
i# Int#
n# (a -> PrimBase a
forall a. Prim a => a -> PrimBase a
toPrimBase a
a)
  {-# INLINE setMutableByteArray# #-}

  -- | Set the region of memory to the same value. Offset is in number of elements
  setOffAddr# :: Addr# -> Int# -> Int# -> a -> State# s -> State# s
  default setOffAddr# ::
    Prim (PrimBase a) => Addr# -> Int# -> Int# -> a -> State# s -> State# s
  setOffAddr# Addr#
addr# Int#
i# Int#
n# a
a = Addr# -> Int# -> Int# -> PrimBase a -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
i# Int#
n# (a -> PrimBase a
forall a. Prim a => a -> PrimBase a
toPrimBase a
a)
  {-# INLINE setOffAddr# #-}


instance Prim () where
  type PrimBase () = ()
  type SizeOf () = 0
  type Alignment () = 1
  sizeOf# :: Proxy# () -> Int#
sizeOf# Proxy# ()
_ = Int#
0#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# () -> Int#
alignment# Proxy# ()
_ = Int#
1#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> ()
indexByteOffByteArray# ByteArray#
_ Int#
_ = ()
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> ()
indexByteArray# ByteArray#
_ Int#
_ = ()
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> ()
indexOffAddr# Addr#
_ Int#
_ = ()
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, () #)
readByteOffMutableByteArray# MutableByteArray# s
_ Int#
_ State# s
s = (# State# s
s, () #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, () #)
readMutableByteArray# MutableByteArray# s
_ Int#
_ State# s
s = (# State# s
s, () #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, () #)
readOffAddr# Addr#
_ Int#
_ State# s
s = (# State# s
s, () #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> () -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
_ Int#
_ () State# s
s = State# s
s
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> () -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
_ Int#
_ () State# s
s = State# s
s
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> () -> State# s -> State# s
writeOffAddr# Addr#
_ Int#
_ () State# s
s = State# s
s
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> () -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
_ Int#
_ Int#
_ () State# s
s = State# s
s
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> () -> State# s -> State# s
setOffAddr# Addr#
_ Int#
_ Int#
_ () State# s
s = State# s
s
  {-# INLINE setOffAddr# #-}

instance a ~ b => Prim (a :~: b) where
  type PrimBase (a :~: b) = ()
  toPrimBase :: (a :~: b) -> PrimBase (a :~: b)
toPrimBase a :~: b
Refl = ()
  fromPrimBase :: PrimBase (a :~: b) -> a :~: b
fromPrimBase () = a :~: b
forall k (a :: k). a :~: a
Refl


instance Prim Int where
  type PrimBase Int = Int
  type SizeOf Int = SIZEOF_HSINT
  type Alignment Int = ALIGNMENT_HSINT
  sizeOf# :: Proxy# Int -> Int#
sizeOf# Proxy# Int
_ = SIZEOF_HSINT#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Int -> Int#
alignment# Proxy# Int
_ = ALIGNMENT_HSINT#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Int
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Int# -> Int
I# (ByteArray# -> Int# -> Int#
indexWord8ArrayAsInt# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Int
indexByteArray# ByteArray#
ba# Int#
i# = Int# -> Int
I# (ByteArray# -> Int# -> Int#
indexIntArray# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Int
indexOffAddr# Addr#
addr# Int#
i# = Int# -> Int
I# (Addr# -> Int# -> Int#
indexIntOffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readWord8ArrayAsInt# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int
I# Int#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readIntArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int
I# Int#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Int #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Int# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Int# #)
readIntOffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int
I# Int#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Int -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (I# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeWord8ArrayAsInt# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Int -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (I# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeIntArray# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Int -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (I# Int#
a#) = Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeIntOffAddr# Addr#
mba# Int#
i# Int#
a#
  {-# INLINE writeOffAddr# #-}
#if WORD_SIZE_IN_BITS >= 64
  setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> Int -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (I# Int#
a#) = MutableByteArray# s
-> Int# -> Int# -> Int64 -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Int# -> Int64
I64# Int#
a#)
  setOffAddr# :: Addr# -> Int# -> Int# -> Int -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (I# Int#
a#) = Addr# -> Int# -> Int# -> Int64 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (Int# -> Int64
I64# Int#
a#)
#else
  setMutableByteArray# mba# o# n# (I# a#) = setMutableByteArray# mba# o# n# (I32# a#)
  setOffAddr# addr# o# n# (I# a#) = setOffAddr# addr# o# n# (I32# a#)
#endif
  {-# INLINE setMutableByteArray# #-}
  {-# INLINE setOffAddr# #-}

instance Prim Int8 where
  type PrimBase Int8 = Int8
  type SizeOf Int8 = SIZEOF_INT8
  type Alignment Int8 = ALIGNMENT_INT8
  sizeOf# :: Proxy# Int8 -> Int#
sizeOf# Proxy# Int8
_ = SIZEOF_INT8#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Int8 -> Int#
alignment# Proxy# Int8
_ = ALIGNMENT_INT8#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Int8
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Int# -> Int8
I8# (ByteArray# -> Int# -> Int#
indexInt8Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Int8
indexByteArray# ByteArray#
ba# Int#
i# = Int# -> Int8
I8# (ByteArray# -> Int# -> Int#
indexInt8Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Int8
indexOffAddr# Addr#
addr# Int#
i# = Int# -> Int8
I8# (Addr# -> Int# -> Int#
indexInt8OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int8 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readInt8Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int8
I8# Int#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int8 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readInt8Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int8
I8# Int#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Int8 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Int# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Int# #)
readInt8OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int8
I8# Int#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Int8 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (I8# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt8Array# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Int8 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (I8# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt8Array# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Int8 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (I8# Int#
a#) = Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeInt8OffAddr# Addr#
mba# Int#
i# Int#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> Int8 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
i# Int#
n# (I8# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
mba# Int#
i# Int#
n# Int#
a#
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Int8 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Int8
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Int8 -> IO ()
memsetInt8Addr# Addr#
addr# Int#
o# Int#
n# Int8
a)
  {-# INLINE setOffAddr# #-}

instance Prim Int16 where
  type PrimBase Int16 = Int16
  type SizeOf Int16 = SIZEOF_INT16
  type Alignment Int16 = ALIGNMENT_INT16
  sizeOf# :: Proxy# Int16 -> Int#
sizeOf# Proxy# Int16
_ = SIZEOF_INT16#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Int16 -> Int#
alignment# Proxy# Int16
_ = ALIGNMENT_INT16#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Int16
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Int# -> Int16
I16# (ByteArray# -> Int# -> Int#
indexWord8ArrayAsInt16# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Int16
indexByteArray# ByteArray#
ba# Int#
i# = Int# -> Int16
I16# (ByteArray# -> Int# -> Int#
indexInt16Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Int16
indexOffAddr# Addr#
addr# Int#
i# = Int# -> Int16
I16# (Addr# -> Int# -> Int#
indexInt16OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int16 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readWord8ArrayAsInt16# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int16
I16# Int#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int16 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readInt16Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int16
I16# Int#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Int16 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Int# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Int# #)
readInt16OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int16
I16# Int#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Int16 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (I16# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeWord8ArrayAsInt16# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Int16 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (I16# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt16Array# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Int16 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (I16# Int#
a#) = Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeInt16OffAddr# Addr#
mba# Int#
i# Int#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Int16 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Int16
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Int16 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Int16 -> IO ()
memsetInt16MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Int16
a)
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Int16 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Int16
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Int16 -> IO ()
memsetInt16Addr# Addr#
addr# Int#
o# Int#
n# Int16
a)
  {-# INLINE setOffAddr# #-}

instance Prim Int32 where
  type PrimBase Int32 = Int32
  type SizeOf Int32 = SIZEOF_INT32
  type Alignment Int32 = ALIGNMENT_INT32
  sizeOf# :: Proxy# Int32 -> Int#
sizeOf# Proxy# Int32
_ = SIZEOF_INT32#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Int32 -> Int#
alignment# Proxy# Int32
_ = ALIGNMENT_INT32#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Int32
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Int# -> Int32
I32# (ByteArray# -> Int# -> Int#
indexWord8ArrayAsInt32# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Int32
indexByteArray# ByteArray#
ba# Int#
i# = Int# -> Int32
I32# (ByteArray# -> Int# -> Int#
indexInt32Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Int32
indexOffAddr# Addr#
addr# Int#
i# = Int# -> Int32
I32# (Addr# -> Int# -> Int#
indexInt32OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int32 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readWord8ArrayAsInt32# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int32
I32# Int#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int32 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readInt32Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int32
I32# Int#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Int32 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Int# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Int# #)
readInt32OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int32
I32# Int#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Int32 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (I32# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeWord8ArrayAsInt32# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Int32 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (I32# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt32Array# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Int32 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (I32# Int#
a#) = Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeInt32OffAddr# Addr#
mba# Int#
i# Int#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Int32 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Int32
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Int32 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Int32 -> IO ()
memsetInt32MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Int32
a)
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Int32 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Int32
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Int32 -> IO ()
memsetInt32Addr# Addr#
addr# Int#
o# Int#
n# Int32
a)
  {-# INLINE setOffAddr# #-}

instance Prim Int64 where
  type PrimBase Int64 = Int64
  type SizeOf Int64 = SIZEOF_INT64
  type Alignment Int64 = ALIGNMENT_INT64
  sizeOf# :: Proxy# Int64 -> Int#
sizeOf# Proxy# Int64
_ = SIZEOF_INT64#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Int64 -> Int#
alignment# Proxy# Int64
_ = ALIGNMENT_INT64#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Int64
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Int# -> Int64
I64# (ByteArray# -> Int# -> Int#
indexWord8ArrayAsInt64# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Int64
indexByteArray# ByteArray#
ba# Int#
i# = Int# -> Int64
I64# (ByteArray# -> Int# -> Int#
indexInt64Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Int64
indexOffAddr# Addr#
addr# Int#
i# = Int# -> Int64
I64# (Addr# -> Int# -> Int#
indexInt64OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int64 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readWord8ArrayAsInt64# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int64
I64# Int#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Int64 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readInt64Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int64
I64# Int#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Int64 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Int# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Int# #)
readInt64OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Int#
a# #) -> (# State# s
s', Int# -> Int64
I64# Int#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Int64 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (I64# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeWord8ArrayAsInt64# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Int64 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (I64# Int#
a#) = MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt64Array# MutableByteArray# s
mba# Int#
i# Int#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Int64 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (I64# Int#
a#) = Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeInt64OffAddr# Addr#
mba# Int#
i# Int#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Int64 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Int64
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Int64 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Int64 -> IO ()
memsetInt64MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Int64
a)
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Int64 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Int64
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Int64 -> IO ()
memsetInt64Addr# Addr#
addr# Int#
o# Int#
n# Int64
a)
  {-# INLINE setOffAddr# #-}


instance Prim Word where
  type PrimBase Word = Word
  type SizeOf Word = SIZEOF_HSWORD
  type Alignment Word = ALIGNMENT_HSWORD
  sizeOf# :: Proxy# Word -> Int#
sizeOf# Proxy# Word
_ = SIZEOF_HSWORD#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Word -> Int#
alignment# Proxy# Word
_ = ALIGNMENT_HSWORD#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Word
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Word# -> Word
W# (ByteArray# -> Int# -> Word#
indexWord8ArrayAsWord# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Word
indexByteArray# ByteArray#
ba# Int#
i# = Word# -> Word
W# (ByteArray# -> Int# -> Word#
indexWordArray# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Word
indexOffAddr# Addr#
addr# Int#
i# = Word# -> Word
W# (Addr# -> Int# -> Word#
indexWordOffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord8ArrayAsWord# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word
W# Word#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word
W# Word#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Word #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Word# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Word# #)
readWordOffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word
W# Word#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Word -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (W# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord8ArrayAsWord# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Word -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (W# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWordArray# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Word -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (W# Word#
a#) = Addr# -> Int# -> Word# -> State# s -> State# s
forall d. Addr# -> Int# -> Word# -> State# d -> State# d
writeWordOffAddr# Addr#
mba# Int#
i# Word#
a#
  {-# INLINE writeOffAddr# #-}
#if WORD_SIZE_IN_BITS >= 64
  setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> Word -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (W# Word#
a#) = MutableByteArray# s
-> Int# -> Int# -> Word64 -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Word# -> Word64
W64# Word#
a#)
  setOffAddr# :: Addr# -> Int# -> Int# -> Word -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (W# Word#
a#) = Addr# -> Int# -> Int# -> Word64 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (Word# -> Word64
W64# Word#
a#)
#else
  setMutableByteArray# mba# o# n# (W# a#) = setMutableByteArray# mba# o# n# (W32# a#)
  setOffAddr# addr# o# n# (W# a#) = setOffAddr# addr# o# n# (W32# a#)
#endif
  {-# INLINE setMutableByteArray# #-}
  {-# INLINE setOffAddr# #-}

instance Prim Word8 where
  type PrimBase Word8 = Word8
  type SizeOf Word8 = SIZEOF_WORD8
  type Alignment Word8 = ALIGNMENT_WORD8
  sizeOf# :: Proxy# Word8 -> Int#
sizeOf# Proxy# Word8
_ = SIZEOF_WORD8#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Word8 -> Int#
alignment# Proxy# Word8
_ = ALIGNMENT_WORD8#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Word8
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Word# -> Word8
W8# (ByteArray# -> Int# -> Word#
indexWord8Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Word8
indexByteArray# ByteArray#
ba# Int#
i# = Word# -> Word8
W8# (ByteArray# -> Int# -> Word#
indexWord8Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Word8
indexOffAddr# Addr#
addr# Int#
i# = Word# -> Word8
W8# (Addr# -> Int# -> Word#
indexWord8OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word8 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord8Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word8
W8# Word#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word8 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord8Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word8
W8# Word#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Word8 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Word# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Word# #)
readWord8OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word8
W8# Word#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Word8 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (W8# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord8Array# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Word8 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (W8# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord8Array# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Word8 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (W8# Word#
a#) = Addr# -> Int# -> Word# -> State# s -> State# s
forall d. Addr# -> Int# -> Word# -> State# d -> State# d
writeWord8OffAddr# Addr#
mba# Int#
i# Word#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Word8 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
i# Int#
n# (W8# Word#
a#) = MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
mba# Int#
i# Int#
n# (Word# -> Int#
word2Int# Word#
a#)
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Word8 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Word8
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Word8 -> IO ()
memsetWord8Addr# Addr#
addr# Int#
o# Int#
n# Word8
a)
  {-# INLINE setOffAddr# #-}

instance Prim Word16 where
  type PrimBase Word16 = Word16
  type SizeOf Word16 = SIZEOF_WORD16
  type Alignment Word16 = ALIGNMENT_WORD16
  sizeOf# :: Proxy# Word16 -> Int#
sizeOf# Proxy# Word16
_ = SIZEOF_WORD16#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Word16 -> Int#
alignment# Proxy# Word16
_ = ALIGNMENT_WORD16#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Word16
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Word# -> Word16
W16# (ByteArray# -> Int# -> Word#
indexWord8ArrayAsWord16# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Word16
indexByteArray# ByteArray#
ba# Int#
i# = Word# -> Word16
W16# (ByteArray# -> Int# -> Word#
indexWord16Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Word16
indexOffAddr# Addr#
addr# Int#
i# = Word# -> Word16
W16# (Addr# -> Int# -> Word#
indexWord16OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word16 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord8ArrayAsWord16# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word16
W16# Word#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word16 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord16Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word16
W16# Word#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Word16 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Word# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Word# #)
readWord16OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word16
W16# Word#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Word16 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (W16# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord8ArrayAsWord16# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Word16 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (W16# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord16Array# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Word16 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (W16# Word#
a#) = Addr# -> Int# -> Word# -> State# s -> State# s
forall d. Addr# -> Int# -> Word# -> State# d -> State# d
writeWord16OffAddr# Addr#
mba# Int#
i# Word#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Word16 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Word16
a =
    IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Word16 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Word16 -> IO ()
memsetWord16MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Word16
a)
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Word16 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Word16
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Word16 -> IO ()
memsetWord16Addr# Addr#
addr# Int#
o# Int#
n# Word16
a)
  {-# INLINE setOffAddr# #-}

instance Prim Word32 where
  type PrimBase Word32 = Word32
  type SizeOf Word32 = SIZEOF_WORD32
  type Alignment Word32 = ALIGNMENT_WORD32
  sizeOf# :: Proxy# Word32 -> Int#
sizeOf# Proxy# Word32
_ = SIZEOF_WORD32#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Word32 -> Int#
alignment# Proxy# Word32
_ = ALIGNMENT_WORD32#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Word32
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Word# -> Word32
W32# (ByteArray# -> Int# -> Word#
indexWord8ArrayAsWord32# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Word32
indexByteArray# ByteArray#
ba# Int#
i# = Word# -> Word32
W32# (ByteArray# -> Int# -> Word#
indexWord32Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Word32
indexOffAddr# Addr#
addr# Int#
i# = Word# -> Word32
W32# (Addr# -> Int# -> Word#
indexWord32OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word32 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord8ArrayAsWord32# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word32
W32# Word#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word32 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord32Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word32
W32# Word#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Word32 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Word# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Word# #)
readWord32OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word32
W32# Word#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Word32 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (W32# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord8ArrayAsWord32# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Word32 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (W32# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord32Array# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Word32 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (W32# Word#
a#) = Addr# -> Int# -> Word# -> State# s -> State# s
forall d. Addr# -> Int# -> Word# -> State# d -> State# d
writeWord32OffAddr# Addr#
mba# Int#
i# Word#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Word32 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Word32
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Word32 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Word32 -> IO ()
memsetWord32MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Word32
a)
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Word32 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Word32
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Word32 -> IO ()
memsetWord32Addr# Addr#
addr# Int#
o# Int#
n# Word32
a)
  {-# INLINE setOffAddr# #-}

instance Prim Word64 where
  type PrimBase Word64 = Word64
  type SizeOf Word64 = SIZEOF_WORD64
  type Alignment Word64 = ALIGNMENT_WORD64
  sizeOf# :: Proxy# Word64 -> Int#
sizeOf# Proxy# Word64
_ = SIZEOF_WORD64#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Word64 -> Int#
alignment# Proxy# Word64
_ = ALIGNMENT_WORD64#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Word64
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Word# -> Word64
W64# (ByteArray# -> Int# -> Word#
indexWord8ArrayAsWord64# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Word64
indexByteArray# ByteArray#
ba# Int#
i# = Word# -> Word64
W64# (ByteArray# -> Int# -> Word#
indexWord64Array# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Word64
indexOffAddr# Addr#
addr# Int#
i# = Word# -> Word64
W64# (Addr# -> Int# -> Word#
indexWord64OffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word64 #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord8ArrayAsWord64# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word64
W64# Word#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Word64 #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWord64Array# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word64
W64# Word#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Word64 #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Word# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Word# #)
readWord64OffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Word#
a# #) -> (# State# s
s', Word# -> Word64
W64# Word#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Word64 -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (W64# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord8ArrayAsWord64# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Word64 -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (W64# Word#
a#) = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord64Array# MutableByteArray# s
mba# Int#
i# Word#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Word64 -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (W64# Word#
a#) = Addr# -> Int# -> Word# -> State# s -> State# s
forall d. Addr# -> Int# -> Word# -> State# d -> State# d
writeWord64OffAddr# Addr#
mba# Int#
i# Word#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Word64 -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Word64
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Word64 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Word64 -> IO ()
memsetWord64MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Word64
a)
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Word64 -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Word64
a = IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Word64 -> IO ()
memsetWord64Addr# Addr#
addr# Int#
o# Int#
n# Word64
a)
  {-# INLINE setOffAddr# #-}


instance Prim Float where
  type PrimBase Float = Float
  type SizeOf Float = SIZEOF_FLOAT
  type Alignment Float = ALIGNMENT_FLOAT
  sizeOf# :: Proxy# Float -> Int#
sizeOf# Proxy# Float
_ = SIZEOF_FLOAT#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Float -> Int#
alignment# Proxy# Float
_ = ALIGNMENT_FLOAT#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Float
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Float# -> Float
F# (ByteArray# -> Int# -> Float#
indexWord8ArrayAsFloat# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Float
indexByteArray# ByteArray#
ba# Int#
i# = Float# -> Float
F# (ByteArray# -> Int# -> Float#
indexFloatArray# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Float
indexOffAddr# Addr#
addr# Int#
i# = Float# -> Float
F# (Addr# -> Int# -> Float#
indexFloatOffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Float #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Float# #)
readWord8ArrayAsFloat# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Float#
a# #) -> (# State# s
s', Float# -> Float
F# Float#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Float #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Float# #)
readFloatArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Float#
a# #) -> (# State# s
s', Float# -> Float
F# Float#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Float #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Float# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Float# #)
readFloatOffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Float#
a# #) -> (# State# s
s', Float# -> Float
F# Float#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Float -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (F# Float#
a#) = MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Float# -> State# d -> State# d
writeWord8ArrayAsFloat# MutableByteArray# s
mba# Int#
i# Float#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Float -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (F# Float#
a#) = MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Float# -> State# d -> State# d
writeFloatArray# MutableByteArray# s
mba# Int#
i# Float#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Float -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (F# Float#
a#) = Addr# -> Int# -> Float# -> State# s -> State# s
forall d. Addr# -> Int# -> Float# -> State# d -> State# d
writeFloatOffAddr# Addr#
mba# Int#
i# Float#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Float -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (F# Float#
f#) =
    IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Word32 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Word32 -> IO ()
memsetWord32MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Word# -> Word32
W32# (Float# -> Word#
floatToWord32# Float#
f#)))
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Float -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (F# Float#
f#) =
    IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Word32 -> IO ()
memsetWord32Addr# Addr#
addr# Int#
o# Int#
n# (Word# -> Word32
W32# (Float# -> Word#
floatToWord32# Float#
f#)))

instance Prim Double where
  type PrimBase Double = Double
  type SizeOf Double = SIZEOF_DOUBLE
  type Alignment Double = ALIGNMENT_DOUBLE
  sizeOf# :: Proxy# Double -> Int#
sizeOf# Proxy# Double
_ = SIZEOF_DOUBLE#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Double -> Int#
alignment# Proxy# Double
_ = ALIGNMENT_DOUBLE#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Double
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Double# -> Double
D# (ByteArray# -> Int# -> Double#
indexWord8ArrayAsDouble# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Double
indexByteArray# ByteArray#
ba# Int#
i# = Double# -> Double
D# (ByteArray# -> Int# -> Double#
indexDoubleArray# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Double
indexOffAddr# Addr#
addr# Int#
i# = Double# -> Double
D# (Addr# -> Int# -> Double#
indexDoubleOffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Double #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Double# #)
readWord8ArrayAsDouble# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Double#
a# #) -> (# State# s
s', Double# -> Double
D# Double#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Double #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Double# #)
readDoubleArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Double#
a# #) -> (# State# s
s', Double# -> Double
D# Double#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Double #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Double# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Double# #)
readDoubleOffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Double#
a# #) -> (# State# s
s', Double# -> Double
D# Double#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Double -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (D# Double#
a#) = MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Double# -> State# d -> State# d
writeWord8ArrayAsDouble# MutableByteArray# s
mba# Int#
i# Double#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Double -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (D# Double#
a#) = MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Double# -> State# d -> State# d
writeDoubleArray# MutableByteArray# s
mba# Int#
i# Double#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Double -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (D# Double#
a#) = Addr# -> Int# -> Double# -> State# s -> State# s
forall d. Addr# -> Int# -> Double# -> State# d -> State# d
writeDoubleOffAddr# Addr#
mba# Int#
i# Double#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Double -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (D# Double#
d#) =
    IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (MutableByteArray# s -> Int# -> Int# -> Word64 -> IO ()
forall s. MutableByteArray# s -> Int# -> Int# -> Word64 -> IO ()
memsetWord64MutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Word# -> Word64
W64# (Double# -> Word#
doubleToWord64# Double#
d#)))
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Double -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (D# Double#
d#) =
    IO () -> State# s -> State# s
forall s' (m :: * -> *) s.
MonadPrimBase s' m =>
m () -> State# s -> State# s
unsafePrimBase_ (Addr# -> Int# -> Int# -> Word64 -> IO ()
memsetWord64Addr# Addr#
addr# Int#
o# Int#
n# (Word# -> Word64
W64# (Double# -> Word#
doubleToWord64# Double#
d#)))
  {-# INLINE setOffAddr# #-}

bool2Int# :: Bool -> Int#
bool2Int# :: Bool -> Int#
bool2Int# Bool
b = if Bool
b then Int#
1# else Int#
0#
{-# INLINE bool2Int# #-}

int2Bool# :: Int# -> Bool
int2Bool# :: Int# -> Bool
int2Bool# Int#
i# = Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
/=# Int#
0#) -- tagToEnum# (i# /=# 0#) -- (andI# i# 1#)
{-# INLINE int2Bool# #-}

instance Prim Bool where
  type PrimBase Bool = Int8
  fromPrimBase :: PrimBase Bool -> Bool
fromPrimBase (I8# i#) = Int# -> Bool
int2Bool# Int#
i#
  {-# INLINE fromPrimBase #-}
  toPrimBase :: Bool -> PrimBase Bool
toPrimBase Bool
b = Int# -> Int8
I8# (Bool -> Int#
bool2Int# Bool
b)
  {-# INLINE toPrimBase #-}

instance Prim Char where
  type PrimBase Char = Char
  type SizeOf Char = SIZEOF_HSCHAR
  type Alignment Char = ALIGNMENT_HSCHAR
  sizeOf# :: Proxy# Char -> Int#
sizeOf# Proxy# Char
_ = SIZEOF_HSCHAR#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# Char -> Int#
alignment# Proxy# Char
_ = ALIGNMENT_HSCHAR#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Char
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Char# -> Char
C# (ByteArray# -> Int# -> Char#
indexWord8ArrayAsWideChar# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Char
indexByteArray# ByteArray#
ba# Int#
i# = Char# -> Char
C# (ByteArray# -> Int# -> Char#
indexWideCharArray# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Char
indexOffAddr# Addr#
addr# Int#
i# = Char# -> Char
C# (Addr# -> Int# -> Char#
indexWideCharOffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Char #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #)
readWord8ArrayAsWideChar# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Char#
a# #) -> (# State# s
s', Char# -> Char
C# Char#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Char #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #)
readWideCharArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Char#
a# #) -> (# State# s
s', Char# -> Char
C# Char#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Char #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Char# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Char# #)
readWideCharOffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Char#
a# #) -> (# State# s
s', Char# -> Char
C# Char#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Char -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (C# Char#
a#) = MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeWord8ArrayAsWideChar# MutableByteArray# s
mba# Int#
i# Char#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Char -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (C# Char#
a#) = MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeWideCharArray# MutableByteArray# s
mba# Int#
i# Char#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Char -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (C# Char#
a#) = Addr# -> Int# -> Char# -> State# s -> State# s
forall d. Addr# -> Int# -> Char# -> State# d -> State# d
writeWideCharOffAddr# Addr#
mba# Int#
i# Char#
a#
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s -> Int# -> Int# -> Char -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (C# Char#
a#) = MutableByteArray# s
-> Int# -> Int# -> Int32 -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Int# -> Int32
I32# (Char# -> Int#
ord# Char#
a#))
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Char -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (C# Char#
a#) = Addr# -> Int# -> Int# -> Int32 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (Int# -> Int32
I32# (Char# -> Int#
ord# Char#
a#))
  {-# INLINE setOffAddr# #-}

instance Prim (Ptr a) where
  type PrimBase (Ptr a) = Ptr a
  type SizeOf (Ptr a) = SIZEOF_HSPTR
  type Alignment (Ptr a) = ALIGNMENT_HSPTR
  sizeOf# :: Proxy# (Ptr a) -> Int#
sizeOf# Proxy# (Ptr a)
_ = SIZEOF_HSINT#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# (Ptr a) -> Int#
alignment# Proxy# (Ptr a)
_ = ALIGNMENT_HSINT#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Ptr a
indexByteOffByteArray# ByteArray#
ba# Int#
i# = Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr (ByteArray# -> Int# -> Addr#
indexWord8ArrayAsAddr# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Ptr a
indexByteArray# ByteArray#
ba# Int#
i# = Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr (ByteArray# -> Int# -> Addr#
indexAddrArray# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Ptr a
indexOffAddr# Addr#
addr# Int#
i# = Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr (Addr# -> Int# -> Addr#
indexAddrOffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Ptr a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Addr# #)
readWord8ArrayAsAddr# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', Addr#
a# #) -> (# State# s
s', Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr Addr#
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Ptr a #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Addr# #)
readAddrArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', Addr#
a# #) -> (# State# s
s', Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr Addr#
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Ptr a #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, Addr# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Addr# #)
readAddrOffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', Addr#
a# #) -> (# State# s
s', Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr Addr#
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (Ptr Addr#
a#) = MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Addr# -> State# d -> State# d
writeWord8ArrayAsAddr# MutableByteArray# s
mba# Int#
i# Addr#
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Ptr a -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (Ptr Addr#
a#) = MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Addr# -> State# d -> State# d
writeAddrArray# MutableByteArray# s
mba# Int#
i# Addr#
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Ptr a -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (Ptr Addr#
a#) = Addr# -> Int# -> Addr# -> State# s -> State# s
forall d. Addr# -> Int# -> Addr# -> State# d -> State# d
writeAddrOffAddr# Addr#
mba# Int#
i# Addr#
a#
  {-# INLINE writeOffAddr# #-}
#if SIZEOF_HSPTR == SIZEOF_INT64
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Ptr a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Ptr Addr#
a#) = MutableByteArray# s
-> Int# -> Int# -> Int64 -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Int# -> Int64
I64# (Addr# -> Int#
addr2Int# Addr#
a#))
  setOffAddr# :: Addr# -> Int# -> Int# -> Ptr a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (Ptr Addr#
a#) = Addr# -> Int# -> Int# -> Int64 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (Int# -> Int64
I64# (Addr# -> Int#
addr2Int# Addr#
a#))
#elif SIZEOF_HSPTR == SIZEOF_INT32
  setMutableByteArray# mba# o# n# (Ptr a#) = setMutableByteArray# mba# o# n# (I32# (addr2Int# a#))
  setOffAddr# addr# o# n# (Ptr a#) = setOffAddr# addr# o# n# (I32# (addr2Int# a#))
#else
#error Ptr is of unsupported size SIZEOF_HSPTR
#endif
  {-# INLINE setMutableByteArray# #-}
  {-# INLINE setOffAddr# #-}

instance Prim (FunPtr a) where
  type PrimBase (FunPtr a) = Ptr a
  toPrimBase :: FunPtr a -> PrimBase (FunPtr a)
toPrimBase (FunPtr Addr#
addr#) = Addr# -> Ptr a
forall a. Addr# -> Ptr a
Ptr Addr#
addr#
  fromPrimBase :: PrimBase (FunPtr a) -> FunPtr a
fromPrimBase (Ptr addr#) = Addr# -> FunPtr a
forall a. Addr# -> FunPtr a
FunPtr Addr#
addr#


instance Prim (StablePtr a) where
  type PrimBase (StablePtr a) = StablePtr a
  type SizeOf (StablePtr a) = SIZEOF_HSSTABLEPTR
  type Alignment (StablePtr a) = ALIGNMENT_HSSTABLEPTR
  sizeOf# :: Proxy# (StablePtr a) -> Int#
sizeOf# Proxy# (StablePtr a)
_ = SIZEOF_HSINT#
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# (StablePtr a) -> Int#
alignment# Proxy# (StablePtr a)
_ = ALIGNMENT_HSINT#
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> StablePtr a
indexByteOffByteArray# ByteArray#
ba# Int#
i# = StablePtr# a -> StablePtr a
forall a. StablePtr# a -> StablePtr a
StablePtr (ByteArray# -> Int# -> StablePtr# a
forall a. ByteArray# -> Int# -> StablePtr# a
indexWord8ArrayAsStablePtr# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> StablePtr a
indexByteArray# ByteArray#
ba# Int#
i# = StablePtr# a -> StablePtr a
forall a. StablePtr# a -> StablePtr a
StablePtr (ByteArray# -> Int# -> StablePtr# a
forall a. ByteArray# -> Int# -> StablePtr# a
indexStablePtrArray# ByteArray#
ba# Int#
i#)
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> StablePtr a
indexOffAddr# Addr#
addr# Int#
i# = StablePtr# a -> StablePtr a
forall a. StablePtr# a -> StablePtr a
StablePtr (Addr# -> Int# -> StablePtr# a
forall a. Addr# -> Int# -> StablePtr# a
indexStablePtrOffAddr# Addr#
addr# Int#
i#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s
-> Int# -> State# s -> (# State# s, StablePtr a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s
-> Int# -> State# s -> (# State# s, StablePtr# a #)
forall d a.
MutableByteArray# d
-> Int# -> State# d -> (# State# d, StablePtr# a #)
readWord8ArrayAsStablePtr# MutableByteArray# s
mba# Int#
i# State# s
s of
                                             (# State# s
s', StablePtr# a
a# #) -> (# State# s
s', StablePtr# a -> StablePtr a
forall a. StablePtr# a -> StablePtr a
StablePtr StablePtr# a
a# #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s
-> Int# -> State# s -> (# State# s, StablePtr a #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s = case MutableByteArray# s
-> Int# -> State# s -> (# State# s, StablePtr# a #)
forall d a.
MutableByteArray# d
-> Int# -> State# d -> (# State# d, StablePtr# a #)
readStablePtrArray# MutableByteArray# s
mba# Int#
i# State# s
s of
                                      (# State# s
s', StablePtr# a
a# #) -> (# State# s
s', StablePtr# a -> StablePtr a
forall a. StablePtr# a -> StablePtr a
StablePtr StablePtr# a
a# #)
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, StablePtr a #)
readOffAddr# Addr#
mba# Int#
i# State# s
s = case Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
forall d a.
Addr# -> Int# -> State# d -> (# State# d, StablePtr# a #)
readStablePtrOffAddr# Addr#
mba# Int#
i# State# s
s of
                             (# State# s
s', StablePtr# a
a# #) -> (# State# s
s', StablePtr# a -> StablePtr a
forall a. StablePtr# a -> StablePtr a
StablePtr StablePtr# a
a# #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> StablePtr a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# (StablePtr StablePtr# a
a#) = MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
forall d a.
MutableByteArray# d -> Int# -> StablePtr# a -> State# d -> State# d
writeWord8ArrayAsStablePtr# MutableByteArray# s
mba# Int#
i# StablePtr# a
a#
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> StablePtr a -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (StablePtr StablePtr# a
a#) = MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
forall d a.
MutableByteArray# d -> Int# -> StablePtr# a -> State# d -> State# d
writeStablePtrArray# MutableByteArray# s
mba# Int#
i# StablePtr# a
a#
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> StablePtr a -> State# s -> State# s
writeOffAddr# Addr#
mba# Int#
i# (StablePtr StablePtr# a
a#) = Addr# -> Int# -> StablePtr# a -> State# s -> State# s
forall a d. Addr# -> Int# -> StablePtr# a -> State# d -> State# d
writeStablePtrOffAddr# Addr#
mba# Int#
i# StablePtr# a
a#
  {-# INLINE writeOffAddr# #-}
#if SIZEOF_HSSTABLEPTR == SIZEOF_INT64
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> StablePtr a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (StablePtr StablePtr# a
a#) = MutableByteArray# s
-> Int# -> Int# -> Int64 -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# (Int# -> Int64
I64# (StablePtr# a -> Int#
unsafeCoerce# StablePtr# a
a#))
  setOffAddr# :: Addr# -> Int# -> Int# -> StablePtr a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (StablePtr StablePtr# a
a#) = Addr# -> Int# -> Int# -> Int64 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# (Int# -> Int64
I64# (StablePtr# a -> Int#
unsafeCoerce# StablePtr# a
a#))
#elif SIZEOF_HSSTABLEPTR == SIZEOF_INT32
  setMutableByteArray# mba# o# n# (StablePtr a#) = setMutableByteArray# mba# o# n# (I32# (unsafeCoerce# a#))
  setOffAddr# addr# o# n# (StablePtr a#) = setOffAddr# addr# o# n# (I32# (unsafeCoerce# a#))
#else
#error StablePtr is of unsupported size SIZEOF_HSSTABLEPTR
#endif
  {-# INLINE setMutableByteArray# #-}
  {-# INLINE setOffAddr# #-}


instance Prim IntPtr where
  type PrimBase IntPtr = Int

instance Prim WordPtr where
  type PrimBase WordPtr = Word

instance Prim CBool where
  type PrimBase CBool = HTYPE_BOOL

instance Prim CChar where
  type PrimBase CChar = HTYPE_CHAR

instance Prim CSChar where
  type PrimBase CSChar = HTYPE_SIGNED_CHAR

instance Prim CUChar where
  type PrimBase CUChar = HTYPE_UNSIGNED_CHAR

instance Prim CShort where
  type PrimBase CShort = HTYPE_SHORT

instance Prim CUShort where
  type PrimBase CUShort = HTYPE_UNSIGNED_SHORT

instance Prim CInt where
  type PrimBase CInt = HTYPE_INT

instance Prim CUInt where
  type PrimBase CUInt = HTYPE_UNSIGNED_INT

instance Prim CLong where
  type PrimBase CLong = HTYPE_LONG

instance Prim CULong where
  type PrimBase CULong = HTYPE_UNSIGNED_LONG

instance Prim CLLong where
  type PrimBase CLLong = HTYPE_LONG_LONG

instance Prim CULLong where
  type PrimBase CULLong = HTYPE_UNSIGNED_LONG_LONG

instance Prim CPtrdiff where
  type PrimBase CPtrdiff = HTYPE_PTRDIFF_T

instance Prim CSize where
  type PrimBase CSize = HTYPE_SIZE_T

instance Prim CWchar where
  type PrimBase CWchar = HTYPE_WCHAR_T

instance Prim CSigAtomic where
  type PrimBase CSigAtomic = HTYPE_SIG_ATOMIC_T

instance Prim CIntPtr where
  type PrimBase CIntPtr = HTYPE_INTPTR_T

instance Prim CUIntPtr where
  type PrimBase CUIntPtr = HTYPE_UINTPTR_T

instance Prim CIntMax where
  type PrimBase CIntMax = HTYPE_INTMAX_T

instance Prim CUIntMax where
  type PrimBase CUIntMax = HTYPE_UINTMAX_T

instance Prim CFloat where
  type PrimBase CFloat = HTYPE_FLOAT

instance Prim CDouble where
  type PrimBase CDouble = HTYPE_DOUBLE


instance Prim Fd where
  type PrimBase Fd = CInt

instance Prim Errno where
  type PrimBase Errno = CInt


#if defined(HTYPE_DEV_T)
instance Prim CDev where
  type PrimBase CDev = HTYPE_DEV_T
#endif
#if defined(HTYPE_INO_T)
instance Prim CIno where
  type PrimBase CIno = HTYPE_INO_T
#endif
#if defined(HTYPE_MODE_T)
instance Prim CMode where
  type PrimBase CMode = HTYPE_MODE_T
#endif
#if defined(HTYPE_OFF_T)
instance Prim COff where
  type PrimBase COff = HTYPE_OFF_T
#endif
#if defined(HTYPE_PID_T)
instance Prim CPid where
  type PrimBase CPid = HTYPE_PID_T
#endif
#if defined(HTYPE_SSIZE_T)
instance Prim CSsize where
  type PrimBase CSsize = HTYPE_SSIZE_T
#endif
#if defined(HTYPE_GID_T)
instance Prim CGid where
  type PrimBase CGid = HTYPE_GID_T
#endif
#if defined(HTYPE_NLINK_T)
instance Prim CNlink where
  type PrimBase CNlink = HTYPE_NLINK_T
#endif
#if defined(HTYPE_UID_T)
instance Prim CUid where
  type PrimBase CUid = HTYPE_UID_T
#endif
#if defined(HTYPE_CC_T)
instance Prim CCc where
  type PrimBase CCc = HTYPE_CC_T
#endif
#if defined(HTYPE_SPEED_T)
instance Prim CSpeed where
  type PrimBase CSpeed = HTYPE_SPEED_T
#endif
#if defined(HTYPE_TCFLAG_T)
instance Prim CTcflag where
  type PrimBase CTcflag = HTYPE_TCFLAG_T
#endif
#if defined(HTYPE_RLIM_T)
instance Prim CRLim where
  type PrimBase CRLim = HTYPE_RLIM_T
#endif

instance Prim a => Prim (Max a) where
  type PrimBase (Max a) = a
instance Prim a => Prim (Min a) where
  type PrimBase (Min a) = a
instance Prim a => Prim (Data.Semigroup.First a) where
  type PrimBase (Data.Semigroup.First a) = a
instance Prim a => Prim (Data.Semigroup.Last a) where
  type PrimBase (Data.Semigroup.Last a) = a
instance (Prim a, Prim b) => Prim (Arg a b) where
  type PrimBase (Arg a b) = (a, b)
  toPrimBase :: Arg a b -> PrimBase (Arg a b)
toPrimBase (Arg a
a b
b) = (a
a, b
b)
  fromPrimBase :: PrimBase (Arg a b) -> Arg a b
fromPrimBase (a, b) = a -> b -> Arg a b
forall a b. a -> b -> Arg a b
Arg a
a b
b

#if __GLASGOW_HASKELL__ >= 800
instance Prim a => Prim (Const a b) where
  type PrimBase (Const a b) = a
#endif /* __GLASGOW_HASKELL__ >= 800 */


#if __GLASGOW_HASKELL__ >= 802

instance a ~ b => Prim (a :~~: b) where
  type PrimBase (a :~~: b) = ()
  toPrimBase :: (a :~~: b) -> PrimBase (a :~~: b)
toPrimBase a :~~: b
HRefl = ()
  fromPrimBase :: PrimBase (a :~~: b) -> a :~~: b
fromPrimBase () = a :~~: b
forall k1 (a :: k1). a :~~: a
HRefl

#if defined(HTYPE_BLKSIZE_T)
instance Prim CBlkSize where
  type PrimBase CBlkSize = HTYPE_BLKSIZE_T
#endif
#if defined(HTYPE_BLKCNT_T)
instance Prim CBlkCnt where
  type PrimBase CBlkCnt = HTYPE_BLKCNT_T
#endif
#if defined(HTYPE_CLOCKID_T)
instance Prim CClockId where
  type PrimBase CClockId = HTYPE_CLOCKID_T
#endif
#if defined(HTYPE_FSBLKCNT_T)
instance Prim CFsBlkCnt where
  type PrimBase CFsBlkCnt = HTYPE_FSBLKCNT_T
#endif
#if defined(HTYPE_FSFILCNT_T)
instance Prim CFsFilCnt where
  type PrimBase CFsFilCnt = HTYPE_FSFILCNT_T
#endif
#if defined(HTYPE_ID_T)
instance Prim CId where
  type PrimBase CId = HTYPE_ID_T
#endif
#if defined(HTYPE_KEY_T)
instance Prim CKey where
  type PrimBase CKey = HTYPE_KEY_T
#endif
#if defined(HTYPE_TIMER_T)
instance Prim CTimer where
  type PrimBase CTimer = HTYPE_TIMER_T
#endif

#if __GLASGOW_HASKELL__ >= 810

#if defined(HTYPE_SOCKLEN_T)
instance Prim CSocklen where
  type PrimBase CSocklen = HTYPE_SOCKLEN_T
#endif
#if defined(HTYPE_NFDS_T)
instance Prim CNfds where
  type PrimBase CNfds = HTYPE_NFDS_T
#endif

#endif /* __GLASGOW_HASKELL__ >= 810 */

#if __GLASGOW_HASKELL__ >= 806
instance Prim (f a) => Prim (Ap f a) where
  type PrimBase (Ap f a) = f a
#endif /* __GLASGOW_HASKELL__ >= 806 */


#endif /* __GLASGOW_HASKELL__ >= 802 */


instance (Prim (f a), Prim (g a)) => Prim (Functor.Product f g a) where
  type PrimBase (Functor.Product f g a) = (f a, g a)
  toPrimBase :: Product f g a -> PrimBase (Product f g a)
toPrimBase (Functor.Pair f a
fa g a
ga) = (f a
fa, g a
ga)
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase (Product f g a) -> Product f g a
fromPrimBase (fa, ga) = f a -> g a -> Product f g a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Functor.Pair f a
fa g a
ga
  {-# INLINE fromPrimBase #-}


instance Prim (f (g a)) => Prim (Compose f g a) where
  type PrimBase (Compose f g a) = f (g a)

instance Prim a => Prim (Identity a) where
  type PrimBase (Identity a) = a

instance Prim (f a) => Prim (Alt f a) where
  type PrimBase (Alt f a) = f a

instance Prim Ordering where
  type PrimBase Ordering = Int8
  toPrimBase :: Ordering -> PrimBase Ordering
toPrimBase Ordering
o = Int# -> Int8
I8# (Ordering -> Int#
fromOrdering# Ordering
o)
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase Ordering -> Ordering
fromPrimBase (I8# i#) = Int# -> Ordering
toOrdering# Int#
i#
  {-# INLINE fromPrimBase #-}

instance Prim IODeviceType where
  type PrimBase IODeviceType = Int8
  toPrimBase :: IODeviceType -> PrimBase IODeviceType
toPrimBase =
    \case
      IODeviceType
Directory -> PrimBase IODeviceType
0
      IODeviceType
Stream -> PrimBase IODeviceType
1
      IODeviceType
RegularFile -> PrimBase IODeviceType
2
      IODeviceType
RawDevice -> PrimBase IODeviceType
3
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase IODeviceType -> IODeviceType
fromPrimBase =
    \case
      PrimBase IODeviceType
0 -> IODeviceType
Directory
      PrimBase IODeviceType
1 -> IODeviceType
Stream
      PrimBase IODeviceType
2 -> IODeviceType
RegularFile
      PrimBase IODeviceType
_ -> IODeviceType
RawDevice
  {-# INLINE fromPrimBase #-}

instance Prim SeekMode where
  type PrimBase SeekMode = Int8
  toPrimBase :: SeekMode -> PrimBase SeekMode
toPrimBase = \case
    SeekMode
AbsoluteSeek -> PrimBase SeekMode
0
    SeekMode
RelativeSeek -> PrimBase SeekMode
1
    SeekMode
SeekFromEnd  -> PrimBase SeekMode
2
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase SeekMode -> SeekMode
fromPrimBase = \case
    PrimBase SeekMode
0 -> SeekMode
AbsoluteSeek
    PrimBase SeekMode
1 -> SeekMode
RelativeSeek
    PrimBase SeekMode
_ -> SeekMode
SeekFromEnd
  {-# INLINE fromPrimBase #-}

instance Prim BlockReason where
  type PrimBase BlockReason = Int8
  toPrimBase :: BlockReason -> PrimBase BlockReason
toPrimBase =
    \case
      BlockReason
BlockedOnMVar -> PrimBase BlockReason
0
      BlockReason
BlockedOnBlackHole -> PrimBase BlockReason
1
      BlockReason
BlockedOnException -> PrimBase BlockReason
2
      BlockReason
BlockedOnSTM -> PrimBase BlockReason
3
      BlockReason
BlockedOnForeignCall -> PrimBase BlockReason
4
      BlockReason
BlockedOnOther -> PrimBase BlockReason
5
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase BlockReason -> BlockReason
fromPrimBase =
    \case
      PrimBase BlockReason
0 -> BlockReason
BlockedOnMVar
      PrimBase BlockReason
1 -> BlockReason
BlockedOnBlackHole
      PrimBase BlockReason
2 -> BlockReason
BlockedOnException
      PrimBase BlockReason
3 -> BlockReason
BlockedOnSTM
      PrimBase BlockReason
4 -> BlockReason
BlockedOnForeignCall
      PrimBase BlockReason
_ -> BlockReason
BlockedOnOther
  {-# INLINE fromPrimBase #-}


instance Prim ThreadStatus where
  type PrimBase ThreadStatus = Int8
  toPrimBase :: ThreadStatus -> PrimBase ThreadStatus
toPrimBase =
    \case
      ThreadStatus
ThreadRunning -> PrimBase ThreadStatus
0x00
      ThreadStatus
ThreadFinished -> PrimBase ThreadStatus
0x10
      ThreadBlocked BlockReason
br -> Int8
0x20 Int8 -> Int8 -> Int8
forall a. Bits a => a -> a -> a
.|. BlockReason -> PrimBase BlockReason
forall a. Prim a => a -> PrimBase a
toPrimBase BlockReason
br
      ThreadStatus
ThreadDied -> PrimBase ThreadStatus
0x30
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase ThreadStatus -> ThreadStatus
fromPrimBase =
    \case
      PrimBase ThreadStatus
0x00 -> ThreadStatus
ThreadRunning
      PrimBase ThreadStatus
0x10 -> ThreadStatus
ThreadFinished
      PrimBase ThreadStatus
0x30 -> ThreadStatus
ThreadDied
      PrimBase ThreadStatus
x -> BlockReason -> ThreadStatus
ThreadBlocked (BlockReason -> ThreadStatus) -> BlockReason -> ThreadStatus
forall a b. (a -> b) -> a -> b
$ PrimBase BlockReason -> BlockReason
forall a. Prim a => PrimBase a -> a
fromPrimBase (Int8
PrimBase ThreadStatus
x Int8 -> Int8 -> Int8
forall a. Bits a => a -> a -> a
.&. Int8
0xf)
  {-# INLINE fromPrimBase #-}

instance Prim IOMode where
  type PrimBase IOMode = Int8
  toPrimBase :: IOMode -> PrimBase IOMode
toPrimBase =
    \case
      IOMode
ReadMode -> PrimBase IOMode
0
      IOMode
WriteMode -> PrimBase IOMode
1
      IOMode
AppendMode -> PrimBase IOMode
2
      IOMode
ReadWriteMode -> PrimBase IOMode
3
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase IOMode -> IOMode
fromPrimBase =
    \case
      PrimBase IOMode
0 -> IOMode
ReadMode
      PrimBase IOMode
1 -> IOMode
WriteMode
      PrimBase IOMode
2 -> IOMode
AppendMode
      PrimBase IOMode
_ -> IOMode
ReadWriteMode
  {-# INLINE fromPrimBase #-}

instance Prim BufferMode where
  type PrimBase BufferMode = (Int8, Maybe Int)
  toPrimBase :: BufferMode -> PrimBase BufferMode
toPrimBase =
    \case
      BufferMode
NoBuffering -> (Int8
0, Maybe Int
forall a. Maybe a
Nothing)
      BufferMode
LineBuffering -> (Int8
1, Maybe Int
forall a. Maybe a
Nothing)
      BlockBuffering Maybe Int
mb -> (Int8
2, Maybe Int
mb)
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase BufferMode -> BufferMode
fromPrimBase =
    \case
      (0, _) -> BufferMode
NoBuffering
      (1, _) -> BufferMode
LineBuffering
      (_, mb) -> Maybe Int -> BufferMode
BlockBuffering Maybe Int
mb
  {-# INLINE fromPrimBase #-}

instance Prim Newline where
  type PrimBase Newline = Int8
  toPrimBase :: Newline -> PrimBase Newline
toPrimBase =
    \case
      Newline
LF -> PrimBase Newline
0
      Newline
CRLF -> PrimBase Newline
1
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase Newline -> Newline
fromPrimBase =
    \case
      PrimBase Newline
0 -> Newline
LF
      PrimBase Newline
_ -> Newline
CRLF
  {-# INLINE fromPrimBase #-}

instance Prim NewlineMode where
  type PrimBase NewlineMode = Int8
  toPrimBase :: NewlineMode -> PrimBase NewlineMode
toPrimBase (NewlineMode Newline
i Newline
o) =
    (Newline -> PrimBase Newline
forall a. Prim a => a -> PrimBase a
toPrimBase Newline
i Int8 -> Int -> Int8
forall a. Bits a => a -> Int -> a
`unsafeShiftL` Int
1) Int8 -> Int8 -> Int8
forall a. Bits a => a -> a -> a
.|. Newline -> PrimBase Newline
forall a. Prim a => a -> PrimBase a
toPrimBase Newline
o
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase NewlineMode -> NewlineMode
fromPrimBase PrimBase NewlineMode
p =
    Newline -> Newline -> NewlineMode
NewlineMode
      (PrimBase Newline -> Newline
forall a. Prim a => PrimBase a -> a
fromPrimBase ((Int8
PrimBase NewlineMode
p Int8 -> Int -> Int8
forall a. Bits a => a -> Int -> a
`unsafeShiftR` Int
1) Int8 -> Int8 -> Int8
forall a. Bits a => a -> a -> a
.&. Int8
1))
      (PrimBase Newline -> Newline
forall a. Prim a => PrimBase a -> a
fromPrimBase (Int8
PrimBase NewlineMode
p Int8 -> Int8 -> Int8
forall a. Bits a => a -> a -> a
.&. Int8
1))
  {-# INLINE fromPrimBase #-}

instance Prim GeneralCategory where
  type PrimBase GeneralCategory = Word8
  toPrimBase :: GeneralCategory -> PrimBase GeneralCategory
toPrimBase = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8)
-> (GeneralCategory -> Int) -> GeneralCategory -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GeneralCategory -> Int
forall a. Enum a => a -> Int
fromEnum
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase GeneralCategory -> GeneralCategory
fromPrimBase PrimBase GeneralCategory
p
    | Int
ip Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> GeneralCategory -> Int
forall a. Enum a => a -> Int
fromEnum (GeneralCategory
forall a. Bounded a => a
maxBound :: GeneralCategory) = GeneralCategory
NotAssigned
    | Bool
otherwise = Int -> GeneralCategory
forall a. Enum a => Int -> a
toEnum Int
ip
    where
      ip :: Int
ip = Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
PrimBase GeneralCategory
p
  {-# INLINE fromPrimBase #-}


instance Prim a => Prim (Down a) where
  type PrimBase (Down a) = a

instance Prim a => Prim (Dual a) where
  type PrimBase (Dual a) = a

instance Prim a => Prim (Sum a) where
  type PrimBase (Sum a) = a

instance Prim a => Prim (Product a) where
  type PrimBase (Product a) = a

instance Prim All where
  type PrimBase All = Bool

instance Prim Any where
  type PrimBase Any = Bool

instance Prim Fingerprint where
  type PrimBase Fingerprint = (Word64, Word64)
  type Alignment Fingerprint = Alignment Word64
  alignment# :: Proxy# Fingerprint -> Int#
alignment# Proxy# Fingerprint
_ = Proxy# Word64 -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# Word64
forall k (a :: k). Proxy# a
proxy# :: Proxy# Word64)
  toPrimBase :: Fingerprint -> PrimBase Fingerprint
toPrimBase (Fingerprint Word64
a Word64
b) = (Word64
a, Word64
b)
  fromPrimBase :: PrimBase Fingerprint -> Fingerprint
fromPrimBase (a, b) = Word64 -> Word64 -> Fingerprint
Fingerprint Word64
a Word64
b

instance Prim a => Prim (Ratio a) where
  type PrimBase (Ratio a) = (a, a)
  type Alignment (Ratio a) = Alignment a
  alignment# :: Proxy# (Ratio a) -> Int#
alignment# Proxy# (Ratio a)
_ = Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
  toPrimBase :: Ratio a -> PrimBase (Ratio a)
toPrimBase (a
a :% a
b) = (a
a, a
b)
  fromPrimBase :: PrimBase (Ratio a) -> Ratio a
fromPrimBase (a, b) = a
a a -> a -> Ratio a
forall a. a -> a -> Ratio a
:% a
b

instance Prim a => Prim (Complex a) where
  type PrimBase (Complex a) = (a, a)
  type Alignment (Complex a) = Alignment a
  alignment# :: Proxy# (Complex a) -> Int#
alignment# Proxy# (Complex a)
_ = Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
  toPrimBase :: Complex a -> PrimBase (Complex a)
toPrimBase (a
a :+ a
b) = (a
a, a
b)
  fromPrimBase :: PrimBase (Complex a) -> Complex a
fromPrimBase (a, b) = a
a a -> a -> Complex a
forall a. a -> a -> Complex a
:+ a
b

instance (Prim a, Prim b) => Prim (a, b) where
  type PrimBase (a, b) = (a, b)
  type SizeOf (a, b) = SizeOf a + SizeOf b
  type Alignment (a, b) = Alignment a + Alignment b
  sizeOf# :: Proxy# (a, b) -> Int#
sizeOf# Proxy# (a, b)
_ = Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a) Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# (a, b) -> Int#
alignment# Proxy# (a, b)
_ =
    Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a) Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
  {-# INLINE alignment# #-}
  indexByteArray# :: ByteArray# -> Int# -> (a, b)
indexByteArray# ByteArray#
ba# Int#
i# =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b))
     in ByteArray# -> Int# -> (a, b)
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i0#
  {-# INLINE indexByteArray# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> (a, b)
indexByteOffByteArray# ByteArray#
ba# Int#
i0# =
    let i1# :: Int#
i1# = Int#
i0# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
     in (ByteArray# -> Int# -> a
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i0#, ByteArray# -> Int# -> b
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i1#)
  {-# INLINE indexByteOffByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> (a, b)
indexOffAddr# Addr#
addr# Int#
i# =
    let addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b)))
        addr1# :: Addr#
addr1# = Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
     in (Addr# -> Int# -> a
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# Addr#
addr0# Int#
0#, Addr# -> Int# -> b
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# Addr#
addr1# Int#
0#)
  {-# INLINE indexOffAddr# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b) #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b))
     in MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b) #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0#
  {-# INLINE readMutableByteArray# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, (a, b) #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# State# s
s =
    let i1# :: Int#
i1# = Int#
i0# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
     in case MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# State# s
s of
          (# State# s
s', a
a0 #) ->
            case MutableByteArray# s -> Int# -> State# s -> (# State# s, b #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i1# State# s
s' of
              (# State# s
s'', b
a1 #) -> (# State# s
s'', (a
a0, b
a1) #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, (a, b) #)
readOffAddr# Addr#
addr# Int#
i# State# s
s =
    let addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b)))
        addr1# :: Addr#
addr1# = Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
    in case Addr# -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# Addr#
addr0# Int#
0# State# s
s of
         (# State# s
s', a
a0 #) ->
           case Addr# -> Int# -> State# s -> (# State# s, b #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# Addr#
addr1# Int#
0# State# s
s' of
             (# State# s
s'', b
a1 #) -> (# State# s
s'', (a
a0, b
a1) #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> (a, b) -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# (a
a0, b
a1) State# s
s =
    let i1# :: Int#
i1# = Int#
i0# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
    in MutableByteArray# s -> Int# -> b -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i1# b
a1 (MutableByteArray# s -> Int# -> a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# a
a0 State# s
s)
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> (a, b) -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (a, b)
a =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b))
    in MutableByteArray# s -> Int# -> (a, b) -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# (a, b)
a
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> (a, b) -> State# s -> State# s
writeOffAddr# Addr#
addr# Int#
i# (a
a0, b
a1) State# s
s =
    let addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b)))
        addr1# :: Addr#
addr1# = Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
    in Addr# -> Int# -> b -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr1# Int#
0# b
a1 (Addr# -> Int# -> a -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr0# Int#
0# a
a0 State# s
s)
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> (a, b) -> State# s -> State# s
setMutableByteArray# = MutableByteArray# s
-> Int# -> Int# -> (a, b) -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArrayLoop#
    -- TODO: optimize with rewrite rules?
    --  | a0 == a1 = setMutableByteArray# mba# (o# *# 2#) (n# *# 2#) a0 s
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> (a, b) -> State# s -> State# s
setOffAddr# = Addr# -> Int# -> Int# -> (a, b) -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddrLoop#
  {-# INLINE setOffAddr# #-}
  --   | a0 == a1 = setOffAddr# addr# (o# *# 2#) (n# *# 2#) a0 s


instance (Prim a, Prim b, Prim c) => Prim (a, b, c) where
  type PrimBase (a, b, c) = (a, b, c)
  type SizeOf (a, b, c) = SizeOf a + SizeOf b + SizeOf c
  type Alignment (a, b, c) = Alignment a + Alignment b + Alignment c
  sizeOf# :: Proxy# (a, b, c) -> Int#
sizeOf# Proxy# (a, b, c)
_ = Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
           Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
           Int# -> Int# -> Int#
+# Proxy# c -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# c
forall k (a :: k). Proxy# a
proxy# :: Proxy# c)
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# (a, b, c) -> Int#
alignment# Proxy# (a, b, c)
_ = Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
              Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
              Int# -> Int# -> Int#
+# Proxy# c -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# c
forall k (a :: k). Proxy# a
proxy# :: Proxy# c)
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> (a, b, c)
indexByteOffByteArray# ByteArray#
ba# Int#
i0# =
    let i1# :: Int#
i1# = Int#
i0# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        i2# :: Int#
i2# = Int#
i1# Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
    in ( ByteArray# -> Int# -> a
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i0#
       , ByteArray# -> Int# -> b
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i1#
       , ByteArray# -> Int# -> c
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i2#
       )
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> (a, b, c)
indexByteArray# ByteArray#
ba# Int#
i# =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b, c) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b, c)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b, c))
    in ByteArray# -> Int# -> (a, b, c)
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# Int#
i0#
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> (a, b, c)
indexOffAddr# Addr#
addr# Int#
i# =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b, c) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b, c)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b, c))
        i1# :: Int#
i1# = Int#
i0# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        i2# :: Int#
i2# = Int#
i1# Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
    in ( Addr# -> Int# -> a
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# (Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` Int#
i0#) Int#
0#
       , Addr# -> Int# -> b
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# (Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` Int#
i1#) Int#
0#
       , Addr# -> Int# -> c
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# (Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` Int#
i2#) Int#
0#
       )
  {-# INLINE indexOffAddr# #-}
  readMutableByteArray# :: MutableByteArray# s
-> Int# -> State# s -> (# State# s, (a, b, c) #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b, c) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b, c)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b, c))
    in MutableByteArray# s
-> Int# -> State# s -> (# State# s, (a, b, c) #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0#
  {-# INLINE readMutableByteArray# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s
-> Int# -> State# s -> (# State# s, (a, b, c) #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# State# s
s =
    let i1# :: Int#
i1# = Int#
i0# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        i2# :: Int#
i2# = Int#
i1# Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
    in case MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# State# s
s  of { (# State# s
s0, a
a0 #) ->
       case MutableByteArray# s -> Int# -> State# s -> (# State# s, b #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i1# State# s
s0 of { (# State# s
s1, b
a1 #) ->
       case MutableByteArray# s -> Int# -> State# s -> (# State# s, c #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i2# State# s
s1 of { (# State# s
s2, c
a2 #) ->
         (# State# s
s2, (a
a0, b
a1, c
a2) #)
       }}}
  {-# INLINE readByteOffMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, (a, b, c) #)
readOffAddr# Addr#
addr# Int#
i# State# s
s =
    let addr0# :: Addr#
addr0# = Addr#
addr#  Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b, c) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b, c)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b, c)))
        addr1# :: Addr#
addr1# = Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        addr2# :: Addr#
addr2# = Addr#
addr1# Addr# -> Int# -> Addr#
`plusAddr#` Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
    in case Addr# -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# Addr#
addr0# Int#
0# State# s
s  of { (# State# s
s0, a
a0 #) ->
       case Addr# -> Int# -> State# s -> (# State# s, b #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# Addr#
addr1# Int#
0# State# s
s0 of { (# State# s
s1, b
a1 #) ->
       case Addr# -> Int# -> State# s -> (# State# s, c #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# Addr#
addr2# Int#
0# State# s
s1 of { (# State# s
s2, c
a2 #) ->
         (# State# s
s2, (a
a0, b
a1, c
a2) #)
       }}}
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> (a, b, c) -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# (a
a0, b
a1, c
a2) State# s
s =
    let i1# :: Int#
i1# = Int#
i0# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        i2# :: Int#
i2# = Int#
i1# Int# -> Int# -> Int#
+# Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
    in MutableByteArray# s -> Int# -> c -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i2# c
a2
       (MutableByteArray# s -> Int# -> b -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i1# b
a1
        (MutableByteArray# s -> Int# -> a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# a
a0 State# s
s))
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> (a, b, c) -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# (a, b, c)
a State# s
s =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b, c) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b, c)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b, c))
    in MutableByteArray# s -> Int# -> (a, b, c) -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# (a, b, c)
a State# s
s
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> (a, b, c) -> State# s -> State# s
writeOffAddr# Addr#
addr# Int#
i# (a
a0, b
a1, c
a2) State# s
s =
    let addr0# :: Addr#
addr0# = Addr#
addr#  Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (a, b, c) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (a, b, c)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (a, b, c)))
        addr1# :: Addr#
addr1# = Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        addr2# :: Addr#
addr2# = Addr#
addr1# Addr# -> Int# -> Addr#
`plusAddr#` Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
    in Addr# -> Int# -> c -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr2# Int#
0# c
a2
       (Addr# -> Int# -> b -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr1# Int#
0# b
a1
        (Addr# -> Int# -> a -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr0# Int#
0# a
a0 State# s
s))
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> (a, b, c) -> State# s -> State# s
setMutableByteArray# = MutableByteArray# s
-> Int# -> Int# -> (a, b, c) -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArrayLoop#
    --  | a0 == a1 && a1 == a2 = setMutableByteArray# mba# (o# *# 3#) (n# *# 3#) a0 s
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> (a, b, c) -> State# s -> State# s
setOffAddr# = Addr# -> Int# -> Int# -> (a, b, c) -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddrLoop#
    --  | a0 == a1 && a1 == a2 = setOffAddr# addr# (o# *# 3#) (n# *# 3#) a0 s
  {-# INLINE setOffAddr# #-}

-- TODO: Write optimized versions for larger tuples
instance (Prim a, Prim b, Prim c, Prim d) => Prim (a, b, c, d) where
  type PrimBase (a, b, c, d) = ((a, b), (c, d))
  toPrimBase :: (a, b, c, d) -> PrimBase (a, b, c, d)
toPrimBase (a
a, b
b, c
c, d
d) = ((a
a, b
b), (c
c, d
d))
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase (a, b, c, d) -> (a, b, c, d)
fromPrimBase ((a, b), (c, d)) = (a
a, b
b, c
c, d
d)
  {-# INLINE fromPrimBase #-}

instance (Prim a, Prim b, Prim c, Prim d, Prim e) => Prim (a, b, c, d, e) where
  type PrimBase (a, b, c, d, e) = ((a, b), (c, d), e)
  toPrimBase :: (a, b, c, d, e) -> PrimBase (a, b, c, d, e)
toPrimBase (a
a, b
b, c
c, d
d, e
e) = ((a
a, b
b), (c
c, d
d), e
e)
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase (a, b, c, d, e) -> (a, b, c, d, e)
fromPrimBase ((a, b), (c, d), e) = (a
a, b
b, c
c, d
d, e
e)
  {-# INLINE fromPrimBase #-}

instance (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f) => Prim (a, b, c, d, e, f) where
  type PrimBase (a, b, c, d, e, f) = ((a, b), (c, d), (e, f))
  toPrimBase :: (a, b, c, d, e, f) -> PrimBase (a, b, c, d, e, f)
toPrimBase (a
a, b
b, c
c, d
d, e
e, f
f) = ((a
a, b
b), (c
c, d
d), (e
e, f
f))
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase (a, b, c, d, e, f) -> (a, b, c, d, e, f)
fromPrimBase ((a, b), (c, d), (e, f)) = (a
a, b
b, c
c, d
d, e
e, f
f)
  {-# INLINE fromPrimBase #-}

instance (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim g) => Prim (a, b, c, d, e, f, g) where
  type PrimBase (a, b, c, d, e, f, g) = ((a, b, c), (d, e, f), g)
  toPrimBase :: (a, b, c, d, e, f, g) -> PrimBase (a, b, c, d, e, f, g)
toPrimBase (a
a, b
b, c
c, d
d, e
e, f
f, g
g) = ((a
a, b
b, c
c), (d
d, e
e, f
f), g
g)
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g)
fromPrimBase ((a, b, c), (d, e, f), g) = (a
a, b
b, c
c, d
d, e
e, f
f, g
g)
  {-# INLINE fromPrimBase #-}

instance (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim g, Prim h) =>
  Prim (a, b, c, d, e, f, g, h) where
  type PrimBase (a, b, c, d, e, f, g, h) = ((a, b, c), (d, e, f), (g, h))
  toPrimBase :: (a, b, c, d, e, f, g, h) -> PrimBase (a, b, c, d, e, f, g, h)
toPrimBase (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h) = ((a
a, b
b, c
c), (d
d, e
e, f
f), (g
g, h
h))
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h)
fromPrimBase ((a, b, c), (d, e, f), (g, h)) = (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h)
  {-# INLINE fromPrimBase #-}

instance (Prim a, Prim b, Prim c, Prim d, Prim e, Prim f, Prim g, Prim h, Prim i) =>
  Prim (a, b, c, d, e, f, g, h, i) where
  type PrimBase (a, b, c, d, e, f, g, h, i) = ((a, b, c), (d, e, f), (g, h, i))
  toPrimBase :: (a, b, c, d, e, f, g, h, i) -> PrimBase (a, b, c, d, e, f, g, h, i)
toPrimBase (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i) = ((a
a, b
b, c
c), (d
d, e
e, f
f), (g
g, h
h, i
i))
  {-# INLINE toPrimBase #-}
  fromPrimBase :: PrimBase (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i)
fromPrimBase ((a, b, c), (d, e, f), (g, h, i)) = (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i)
  {-# INLINE fromPrimBase #-}


instance Prim a => Prim (Maybe a) where
  type PrimBase (Maybe a) = Maybe a
  type SizeOf (Maybe a) = 1 + SizeOf a
  type Alignment (Maybe a) = 1 + Alignment a
  sizeOf# :: Proxy# (Maybe a) -> Int#
sizeOf# Proxy# (Maybe a)
_ = Int#
1# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# (Maybe a) -> Int#
alignment# Proxy# (Maybe a)
_ = Int#
1# Int# -> Int# -> Int#
+# Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Maybe a
indexByteOffByteArray# ByteArray#
ba# Int#
i# =
    case ByteArray# -> Int# -> Int#
indexInt8Array# ByteArray#
ba# Int#
i# of
      Int#
0# -> Maybe a
forall a. Maybe a
Nothing
      Int#
_  -> a -> Maybe a
forall a. a -> Maybe a
Just (ByteArray# -> Int# -> a
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# (Int#
i# Int# -> Int# -> Int#
+# Int#
1#))
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Maybe a
indexByteArray# ByteArray#
ba# Int#
i# =
    ByteArray# -> Int# -> Maybe a
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# (Int#
i# Int# -> Int# -> Int#
*# Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a)))
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Maybe a
indexOffAddr# Addr#
addr# Int#
i# =
    let addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a)))
    in case Addr# -> Int# -> Int#
indexInt8OffAddr# Addr#
addr0# Int#
0# of
      Int#
0# -> Maybe a
forall a. Maybe a
Nothing
      Int#
_  -> a -> Maybe a
forall a. a -> Maybe a
Just (Addr# -> Int# -> a
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# (Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Int#
1#) Int#
0#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Maybe a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s =
    case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readInt8Array# MutableByteArray# s
mba# Int#
i# State# s
s of
      (# State# s
s', Int#
0# #) -> (# State# s
s', Maybe a
forall a. Maybe a
Nothing #)
      (# State# s
s', Int#
_  #) -> case MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) State# s
s' of
                        (# State# s
s'', a
a #) -> (# State# s
s'', a -> Maybe a
forall a. a -> Maybe a
Just a
a #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Maybe a #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a))
     in MutableByteArray# s -> Int# -> State# s -> (# State# s, Maybe a #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0#
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Maybe a #)
readOffAddr# Addr#
addr# Int#
i# State# s
s =
    let addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a)))
    in case Addr# -> Int# -> State# s -> (# State# s, Int# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Int# #)
readInt8OffAddr# Addr#
addr0# Int#
0# State# s
s of
         (# State# s
s', Int#
0# #) -> (# State# s
s', Maybe a
forall a. Maybe a
Nothing #)
         (# State# s
s', Int#
_  #) -> case Addr# -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# (Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Int#
1#) Int#
0# State# s
s' of
                           (# State# s
s'', a
a #) -> (# State# s
s'', a -> Maybe a
forall a. a -> Maybe a
Just a
a #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Maybe a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# Maybe a
mVal State# s
s =
    case Maybe a
mVal of
      Maybe a
Nothing -> MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
mba# Int#
i# (Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a))) Int#
0# State# s
s
      Just a
a  -> MutableByteArray# s -> Int# -> a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) a
a (MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt8Array# MutableByteArray# s
mba# Int#
i# Int#
1# State# s
s)
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Maybe a -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# Maybe a
mVal State# s
s =
    let k# :: Int#
k# = Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a))
        i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Int#
k# -- Not using writeByteOffMutableByteArray# to avoid k# recomputation
    in case Maybe a
mVal of
         Maybe a
Nothing -> MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
mba# Int#
i0# Int#
k# Int#
0# State# s
s
         Just a
a  -> MutableByteArray# s -> Int# -> a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# (Int#
i0# Int# -> Int# -> Int#
+# Int#
1#) a
a (MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt8Array# MutableByteArray# s
mba# Int#
i0# Int#
1# State# s
s)
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Maybe a -> State# s -> State# s
writeOffAddr# Addr#
addr# Int#
i# Maybe a
mVal State# s
s =
    let k# :: Int#
k# = Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a))
        i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Int#
k#
    in case Maybe a
mVal of
         Maybe a
Nothing -> Addr# -> Int# -> Int# -> Int8 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
i0# Int#
k# (Int# -> Int8
I8# Int#
0#) State# s
s
         Just a
a  ->
           Addr# -> Int# -> a -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# (Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i0# Int# -> Int# -> Int#
+# Int#
1#)) Int#
0# a
a (Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeInt8OffAddr# Addr#
addr# Int#
i0# Int#
1# State# s
s)
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Maybe a -> State# s -> State# s
setMutableByteArray# MutableByteArray# s
mba# Int#
o# Int#
n# Maybe a
mVal State# s
s =
    case Maybe a
mVal of
      Maybe a
Nothing ->
        let k# :: Int#
k# = Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a))
        in MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
mba# (Int#
o# Int# -> Int# -> Int#
*# Int#
k#) (Int#
n# Int# -> Int# -> Int#
*# Int#
k#) Int#
0# State# s
s
      Maybe a
_       -> MutableByteArray# s
-> Int# -> Int# -> Maybe a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArrayLoop# MutableByteArray# s
mba# Int#
o# Int#
n# Maybe a
mVal State# s
s
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Maybe a -> State# s -> State# s
setOffAddr# Addr#
addr# Int#
o# Int#
n# Maybe a
mVal State# s
s =
    case Maybe a
mVal of
      Maybe a
Nothing ->
        let k# :: Int#
k# = Proxy# (Maybe a) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Maybe a)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Maybe a))
        in Addr# -> Int# -> Int# -> Int8 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr# (Int#
o# Int# -> Int# -> Int#
*# Int#
k#) (Int#
n# Int# -> Int# -> Int#
*# Int#
k#) (Int# -> Int8
I8# Int#
0#) State# s
s
      Maybe a
_       ->  Addr# -> Int# -> Int# -> Maybe a -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddrLoop# Addr#
addr# Int#
o# Int#
n# Maybe a
mVal State# s
s
  {-# INLINE setOffAddr# #-}

maxInt# :: Int# -> Int# -> Int#
maxInt# :: Int# -> Int# -> Int#
maxInt# Int#
x# Int#
y# =
  case Int#
x# Int# -> Int# -> Int#
<# Int#
y# of
    Int#
0# -> Int#
x#
    Int#
_  -> Int#
y#
{-# INLINE maxInt# #-}

type family MaxOrdering (o :: Ordering) (x :: Nat) (y :: Nat) where
  MaxOrdering 'LT x y = y
  MaxOrdering o  x y = x

type MaxOf (x :: Nat) (y :: Nat) = MaxOrdering (CmpNat x y) x y

instance (Prim a, Prim b) => Prim (Either a b) where
  type PrimBase (Either a b) = Either a b
  type SizeOf (Either a b) = 1 + MaxOf (SizeOf a) (SizeOf b)
  type Alignment (Either a b) = 1 + MaxOf (Alignment a) (Alignment b)
  sizeOf# :: Proxy# (Either a b) -> Int#
sizeOf# Proxy# (Either a b)
_ = Int#
1# Int# -> Int# -> Int#
+# Int# -> Int# -> Int#
maxInt# (Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)) (Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b))
  {-# INLINE sizeOf# #-}
  alignment# :: Proxy# (Either a b) -> Int#
alignment# Proxy# (Either a b)
_ = Int#
1# Int# -> Int# -> Int#
+# Int# -> Int# -> Int#
maxInt# (Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)) (Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
alignment# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b))
  {-# INLINE alignment# #-}
  indexByteOffByteArray# :: ByteArray# -> Int# -> Either a b
indexByteOffByteArray# ByteArray#
ba# Int#
i# =
    case ByteArray# -> Int# -> Int#
indexInt8Array# ByteArray#
ba# Int#
i# of
      Int#
0# -> a -> Either a b
forall a b. a -> Either a b
Left (ByteArray# -> Int# -> a
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# (Int#
i# Int# -> Int# -> Int#
+# Int#
1#))
      Int#
_  -> b -> Either a b
forall a b. b -> Either a b
Right (ByteArray# -> Int# -> b
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# (Int#
i# Int# -> Int# -> Int#
+# Int#
1#))
  {-# INLINE indexByteOffByteArray# #-}
  indexByteArray# :: ByteArray# -> Int# -> Either a b
indexByteArray# ByteArray#
ba# Int#
i# =
    ByteArray# -> Int# -> Either a b
forall a. Prim a => ByteArray# -> Int# -> a
indexByteOffByteArray# ByteArray#
ba# (Int#
i# Int# -> Int# -> Int#
*# Proxy# (Either a b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Either a b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Either a b)))
  {-# INLINE indexByteArray# #-}
  indexOffAddr# :: Addr# -> Int# -> Either a b
indexOffAddr# Addr#
addr# Int#
i# =
    let addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (Either a b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Either a b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Either a b)))
    in case Addr# -> Int# -> Int#
indexInt8OffAddr# Addr#
addr0# Int#
0# of
      Int#
0# -> a -> Either a b
forall a b. a -> Either a b
Left (Addr# -> Int# -> a
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# (Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Int#
1#) Int#
0#)
      Int#
_  -> b -> Either a b
forall a b. b -> Either a b
Right (Addr# -> Int# -> b
forall a. Prim a => Addr# -> Int# -> a
indexOffAddr# (Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Int#
1#) Int#
0#)
  {-# INLINE indexOffAddr# #-}
  readByteOffMutableByteArray# :: MutableByteArray# s
-> Int# -> State# s -> (# State# s, Either a b #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# State# s
s =
    case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
readInt8Array# MutableByteArray# s
mba# Int#
i# State# s
s of
      (# State# s
s', Int#
0# #) -> case MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) State# s
s' of
                        (# State# s
s'', a
a #) -> (# State# s
s'', a -> Either a b
forall a b. a -> Either a b
Left a
a #)
      (# State# s
s', Int#
_  #) -> case MutableByteArray# s -> Int# -> State# s -> (# State# s, b #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) State# s
s' of
                        (# State# s
s'', b
a #) -> (# State# s
s'', b -> Either a b
forall a b. b -> Either a b
Right b
a #)
  {-# INLINE readByteOffMutableByteArray# #-}
  readMutableByteArray# :: MutableByteArray# s
-> Int# -> State# s -> (# State# s, Either a b #)
readMutableByteArray# MutableByteArray# s
mba# Int#
i# =
    let i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Proxy# (Either a b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Either a b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Either a b))
     in MutableByteArray# s
-> Int# -> State# s -> (# State# s, Either a b #)
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
readByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0#
  {-# INLINE readMutableByteArray# #-}
  readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Either a b #)
readOffAddr# Addr#
addr# Int#
i# State# s
s =
    let addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Proxy# (Either a b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Either a b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Either a b)))
    in case Addr# -> Int# -> State# s -> (# State# s, Int# #)
forall d. Addr# -> Int# -> State# d -> (# State# d, Int# #)
readInt8OffAddr# Addr#
addr0# Int#
0# State# s
s of
         (# State# s
s', Int#
0# #) -> case Addr# -> Int# -> State# s -> (# State# s, a #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# (Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Int#
1#) Int#
0# State# s
s' of
                           (# State# s
s'', a
a #) -> (# State# s
s'', a -> Either a b
forall a b. a -> Either a b
Left a
a #)
         (# State# s
s', Int#
_  #) -> case Addr# -> Int# -> State# s -> (# State# s, b #)
forall a s.
Prim a =>
Addr# -> Int# -> State# s -> (# State# s, a #)
readOffAddr# (Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Int#
1#) Int#
0# State# s
s' of
                           (# State# s
s'', b
a #) -> (# State# s
s'', b -> Either a b
forall a b. b -> Either a b
Right b
a #)
  {-# INLINE readOffAddr# #-}
  writeByteOffMutableByteArray# :: MutableByteArray# s -> Int# -> Either a b -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i# Either a b
eVal State# s
s =
    let a# :: Int#
a# = Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        b# :: Int#
b# = Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
        i1# :: Int#
i1# = Int#
i# Int# -> Int# -> Int#
+# Int#
1#
    in case Either a b
eVal of
         Left a
a -> -- TODO: Optimize duplication away
           MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
mba# (Int#
i1# Int# -> Int# -> Int#
+# Int#
a#) (Int# -> Int# -> Int#
maxInt# Int#
0# (Int#
b# Int# -> Int# -> Int#
-# Int#
a#)) Int#
0#
           (MutableByteArray# s -> Int# -> a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i1# a
a (MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt8Array# MutableByteArray# s
mba# Int#
i# Int#
0# State# s
s))
         Right b
b ->
           MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
mba# (Int#
i1# Int# -> Int# -> Int#
+# Int#
b#) (Int# -> Int# -> Int#
maxInt# Int#
0# (Int#
a# Int# -> Int# -> Int#
-# Int#
b#)) Int#
0#
           (MutableByteArray# s -> Int# -> b -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i1# b
b (MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
writeInt8Array# MutableByteArray# s
mba# Int#
i# Int#
1# State# s
s))
  {-# INLINE writeByteOffMutableByteArray# #-}
  writeMutableByteArray# :: MutableByteArray# s -> Int# -> Either a b -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# Either a b
eVal State# s
s =
    let k# :: Int#
k# = Proxy# (Either a b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Either a b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Either a b))
        i0# :: Int#
i0# = Int#
i# Int# -> Int# -> Int#
*# Int#
k#
    in MutableByteArray# s -> Int# -> Either a b -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeByteOffMutableByteArray# MutableByteArray# s
mba# Int#
i0# Either a b
eVal State# s
s
  {-# INLINE writeMutableByteArray# #-}
  writeOffAddr# :: Addr# -> Int# -> Either a b -> State# s -> State# s
writeOffAddr# Addr#
addr# Int#
i# Either a b
eVal State# s
s =
    let a# :: Int#
a# = Proxy# a -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# a
forall k (a :: k). Proxy# a
proxy# :: Proxy# a)
        b# :: Int#
b# = Proxy# b -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# b
forall k (a :: k). Proxy# a
proxy# :: Proxy# b)
        k# :: Int#
k# = Proxy# (Either a b) -> Int#
forall a. Prim a => Proxy# a -> Int#
sizeOf# (Proxy# (Either a b)
forall k (a :: k). Proxy# a
proxy# :: Proxy# (Either a b))
        addr0# :: Addr#
addr0# = Addr#
addr# Addr# -> Int# -> Addr#
`plusAddr#` (Int#
i# Int# -> Int# -> Int#
*# Int#
k#)
        addr1# :: Addr#
addr1# = Addr#
addr0# Addr# -> Int# -> Addr#
`plusAddr#` Int#
1#
    in case Either a b
eVal of
         Left a
a  ->
           Addr# -> Int# -> Int# -> Int8 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr1# Int#
a# (Int# -> Int# -> Int#
maxInt# Int#
0# (Int#
b# Int# -> Int# -> Int#
-# Int#
a#)) (Int# -> Int8
I8# Int#
0#)
           (Addr# -> Int# -> a -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr1# Int#
0# a
a (Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeInt8OffAddr# Addr#
addr0# Int#
0# Int#
0# State# s
s))
         Right b
b ->
           Addr# -> Int# -> Int# -> Int8 -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddr# Addr#
addr1# Int#
b# (Int# -> Int# -> Int#
maxInt# Int#
0# (Int#
a# Int# -> Int# -> Int#
-# Int#
b#)) (Int# -> Int8
I8# Int#
0#)
           (Addr# -> Int# -> b -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr1# Int#
0# b
b (Addr# -> Int# -> Int# -> State# s -> State# s
forall d. Addr# -> Int# -> Int# -> State# d -> State# d
writeInt8OffAddr# Addr#
addr0# Int#
0# Int#
1# State# s
s))
  {-# INLINE writeOffAddr# #-}
  setMutableByteArray# :: MutableByteArray# s
-> Int# -> Int# -> Either a b -> State# s -> State# s
setMutableByteArray# = MutableByteArray# s
-> Int# -> Int# -> Either a b -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArrayLoop#
  {-# INLINE setMutableByteArray# #-}
  setOffAddr# :: Addr# -> Int# -> Int# -> Either a b -> State# s -> State# s
setOffAddr# = Addr# -> Int# -> Int# -> Either a b -> State# s -> State# s
forall a s.
Prim a =>
Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddrLoop#
  {-# INLINE setOffAddr# #-}


-- | A loop that uses `writeMutableByteArray#` to set the values in the region. It is a
-- suboptimal way to fill the memory with a single value that is why it is only provided
-- here for convenience
setMutableByteArrayLoop# ::
     Prim a => MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArrayLoop# :: MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s
setMutableByteArrayLoop# MutableByteArray# s
mba# Int#
o# Int#
n# a
a = Int# -> State# s -> State# s
go Int#
o#
  where
    k# :: Int#
k# = Int#
o# Int# -> Int# -> Int#
+# Int#
n#
    go :: Int# -> State# s -> State# s
go Int#
i# State# s
s
      | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
<# Int#
k#) = Int# -> State# s -> State# s
go (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) (MutableByteArray# s -> Int# -> a -> State# s -> State# s
forall a s.
Prim a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
writeMutableByteArray# MutableByteArray# s
mba# Int#
i# a
a State# s
s)
      | Bool
otherwise = State# s
s
{-# INLINE setMutableByteArrayLoop# #-}

setOffAddrLoop# :: Prim a => Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddrLoop# :: Addr# -> Int# -> Int# -> a -> State# s -> State# s
setOffAddrLoop# Addr#
addr# Int#
o# Int#
n# a
a = Int# -> State# s -> State# s
go Int#
o#
  where
    k# :: Int#
k# = Int#
o# Int# -> Int# -> Int#
+# Int#
n#
    go :: Int# -> State# s -> State# s
go Int#
i# State# s
s
      | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
<# Int#
k#) = Int# -> State# s -> State# s
go (Int#
i# Int# -> Int# -> Int#
+# Int#
1#) (Addr# -> Int# -> a -> State# s -> State# s
forall a s. Prim a => Addr# -> Int# -> a -> State# s -> State# s
writeOffAddr# Addr#
addr# Int#
i# a
a State# s
s)
      | Bool
otherwise = State# s
s
{-# INLINE setOffAddrLoop# #-}


errorImpossible :: String -> String -> a
errorImpossible :: String -> String -> a
errorImpossible String
fname String
msg =
#if __GLASGOW_HASKELL__ < 800
  error
#else
  String -> a
forall a. String -> a
errorWithoutStackTrace
#endif
  (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"Impossible <" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fname String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
">:" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
msg
{-# NOINLINE errorImpossible #-}