{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
module Data.Prim.Memory.Bytes
( module Data.Prim
, Bytes
, toByteArray#
, fromByteArray#
, cloneBytes
, emptyBytes
, eqBytes
, singletonBytes
, isEmptyBytes
, createBytes
, createBytes_
, createBytesST
, createBytesST_
, Pinned(..)
, isPinnedBytes
, isPinnedMBytes
, toPinnedBytes
, toPinnedMBytes
, toInconclusiveBytes
, toInconclusiveMBytes
, relaxPinnedBytes
, relaxPinnedMBytes
, ensurePinnedBytes
, ensurePinnedMBytes
, MBytes
, toMutableByteArray#
, fromMutableByteArray#
, isSameBytes
, isSamePinnedBytes
, isSameMBytes
, indexOffBytes
, indexByteOffBytes
, byteCountBytes
, countBytes
, countRemBytes
, compareBytes
, compareByteOffBytes
, thawBytes
, freezeMBytes
, allocMBytes
, singletonMBytes
, allocPinnedMBytes
, allocAlignedMBytes
, allocUnpinnedMBytes
, allocZeroMBytes
, allocZeroPinnedMBytes
, allocZeroAlignedMBytes
, shrinkMBytes
, resizeMBytes
, reallocMBytes
, coerceStateMBytes
, cloneMBytes
, withCloneMBytes
, withCloneMBytes_
, withCloneMBytesST
, withCloneMBytesST_
, loadListMBytes
, loadListMBytes_
, copyBytesToMBytes
, moveMBytesToMBytes
, getByteCountMBytes
, getCountMBytes
, getCountRemOfMBytes
, readOffMBytes
, readByteOffMBytes
, writeOffMBytes
, writeByteOffMBytes
, setMBytes
, zeroMBytes
, withPtrBytes
, withNoHaltPtrBytes
, withPtrMBytes
, withNoHaltPtrMBytes
, toPtrBytes
, toPtrMBytes
, toForeignPtrBytes
, toForeignPtrMBytes
, toUArrayBytes
, fromUArrayBytes
, toUMArrayMBytes
, fromUMArrayMBytes
, fromListBytes
, fromListBytesN
, fromListZeroBytesN_
, appendBytes
, concatBytes
, toListBytes
, toListSlackBytes
, casMBytes
, casBoolMBytes
, casBoolFetchMBytes
, atomicReadMBytes
, atomicWriteMBytes
, atomicModifyMBytes
, atomicModifyMBytes_
, atomicBoolModifyFetchOldMBytes
, atomicModifyFetchOldMBytes
, atomicModifyFetchNewMBytes
, atomicAddFetchOldMBytes
, atomicAddFetchNewMBytes
, atomicSubFetchOldMBytes
, atomicSubFetchNewMBytes
, atomicAndFetchOldMBytes
, atomicAndFetchNewMBytes
, atomicNandFetchOldMBytes
, atomicNandFetchNewMBytes
, atomicOrFetchOldMBytes
, atomicOrFetchNewMBytes
, atomicXorFetchOldMBytes
, atomicXorFetchNewMBytes
, atomicNotFetchOldMBytes
, atomicNotFetchNewMBytes
, prefetchBytes0
, prefetchMBytes0
, prefetchBytes1
, prefetchMBytes1
, prefetchBytes2
, prefetchMBytes2
, prefetchBytes3
, prefetchMBytes3
) where
import Control.Monad.ST
import Control.Prim.Monad
import Data.Maybe (fromMaybe)
import Data.Prim
import Data.Prim.Atomic
import Data.Prim.Memory.Internal
import Foreign.Prim
eqBytes :: Bytes p1 -> Bytes p2 -> Bool
eqBytes :: Bytes p1 -> Bytes p2 -> Bool
eqBytes Bytes p1
b1 Bytes p2
b2 = Bytes p1 -> Bytes p2 -> Bool
forall (p1 :: Pinned) (p2 :: Pinned). Bytes p1 -> Bytes p2 -> Bool
isSameBytes Bytes p1
b1 Bytes p2
b2 Bool -> Bool -> Bool
|| Bytes p1 -> Bytes p2 -> Bool
forall mr1 mr2. (MemRead mr1, MemRead mr2) => mr1 -> mr2 -> Bool
eqByteMem Bytes p1
b1 Bytes p2
b2
{-# INLINE eqBytes #-}
compareBytes :: Prim e => Bytes p1 -> Off e -> Bytes p2 -> Off e -> Count e -> Ordering
compareBytes :: Bytes p1 -> Off e -> Bytes p2 -> Off e -> Count e -> Ordering
compareBytes (Bytes ByteArray#
b1#) Off e
off1 (Bytes ByteArray#
b2#) Off e
off2 Count e
c =
Int# -> Ordering
toOrdering# (ByteArray# -> Int# -> ByteArray# -> Int# -> Int# -> Int#
compareByteArrays# ByteArray#
b1# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off1) ByteArray#
b2# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off2) (Count e -> Int#
forall e. Prim e => Count e -> Int#
unCountBytes# Count e
c))
{-# INLINE compareBytes #-}
coerceStateMBytes :: MBytes p s' -> MBytes p s
coerceStateMBytes :: MBytes p s' -> MBytes p s
coerceStateMBytes = MBytes p s' -> MBytes p s
unsafeCoerce#
emptyBytes :: Bytes p
emptyBytes :: Bytes p
emptyBytes = Bytes 'Pin -> Bytes p
forall (p' :: Pinned) (p :: Pinned). Bytes p' -> Bytes p
castPinnedBytes (Bytes 'Pin -> Bytes p) -> Bytes 'Pin -> Bytes p
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (Bytes 'Pin)) -> Bytes 'Pin
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (Bytes 'Pin)) -> Bytes 'Pin)
-> (forall s. ST s (Bytes 'Pin)) -> Bytes 'Pin
forall a b. (a -> b) -> a -> b
$ Count Word8 -> ST s (MBytes 'Pin s)
forall s (m :: * -> *) e.
(MonadPrim s m, Prim e) =>
Count e -> m (MBytes 'Pin s)
allocPinnedMBytes (Count Word8
0 :: Count Word8) ST s (MBytes 'Pin s)
-> (MBytes 'Pin s -> ST s (Bytes 'Pin)) -> ST s (Bytes 'Pin)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MBytes 'Pin s -> ST s (Bytes 'Pin)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Bytes p)
freezeMBytes
{-# INLINE emptyBytes #-}
isEmptyBytes :: Bytes p -> Bool
isEmptyBytes :: Bytes p -> Bool
isEmptyBytes Bytes p
b = Bytes p -> Count Word8
forall (p :: Pinned). Bytes p -> Count Word8
byteCountBytes Bytes p
b Count Word8 -> Count Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Count Word8
0
{-# INLINE isEmptyBytes #-}
singletonBytes :: forall e p. (Prim e, Typeable p) => e -> Bytes p
singletonBytes :: e -> Bytes p
singletonBytes e
a = (forall s. ST s (Bytes p)) -> Bytes p
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (Bytes p)) -> Bytes p)
-> (forall s. ST s (Bytes p)) -> Bytes p
forall a b. (a -> b) -> a -> b
$ e -> ST s (MBytes p s)
forall e (p :: Pinned) (m :: * -> *) s.
(Prim e, Typeable p, MonadPrim s m) =>
e -> m (MBytes p s)
singletonMBytes e
a ST s (MBytes p s)
-> (MBytes p s -> ST s (Bytes p)) -> ST s (Bytes p)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MBytes p s -> ST s (Bytes p)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Bytes p)
freezeMBytes
{-# INLINE singletonBytes #-}
singletonMBytes :: forall e p m s. (Prim e, Typeable p, MonadPrim s m) => e -> m (MBytes p s)
singletonMBytes :: e -> m (MBytes p s)
singletonMBytes e
a = do
MBytes p s
mb <- Count e -> m (MBytes p s)
forall (p :: Pinned) e s (m :: * -> *).
(Typeable p, Prim e, MonadPrim s m) =>
Count e -> m (MBytes p s)
allocMBytes (Count e
1 :: Count e)
MBytes p s
mb MBytes p s -> m () -> m (MBytes p s)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ MBytes p s -> Off e -> e -> m ()
forall s (m :: * -> *) e (p :: Pinned).
(MonadPrim s m, Prim e) =>
MBytes p s -> Off e -> e -> m ()
writeOffMBytes MBytes p s
mb Off e
0 e
a
{-# INLINE singletonMBytes #-}
cloneBytes :: Typeable p => Bytes p -> Bytes p
cloneBytes :: Bytes p -> Bytes p
cloneBytes Bytes p
b = (forall s. ST s (Bytes p)) -> Bytes p
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (Bytes p)) -> Bytes p)
-> (forall s. ST s (Bytes p)) -> Bytes p
forall a b. (a -> b) -> a -> b
$ Bytes p -> ST s (MBytes p s)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
Bytes p -> m (MBytes p s)
thawBytes Bytes p
b ST s (MBytes p s)
-> (MBytes p s -> ST s (MBytes p s)) -> ST s (MBytes p s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MBytes p s -> ST s (MBytes p s)
forall s (m :: * -> *) (p :: Pinned).
(MonadPrim s m, Typeable p) =>
MBytes p s -> m (MBytes p s)
cloneMBytes ST s (MBytes p s)
-> (MBytes p s -> ST s (Bytes p)) -> ST s (Bytes p)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MBytes p s -> ST s (Bytes p)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Bytes p)
freezeMBytes
{-# INLINE cloneBytes #-}
cloneMBytes :: (MonadPrim s m, Typeable p) => MBytes p s -> m (MBytes p s)
cloneMBytes :: MBytes p s -> m (MBytes p s)
cloneMBytes MBytes p s
mb = do
Count Word8
n <- MBytes p s -> m (Count Word8)
forall s (m :: * -> *) e (p :: Pinned).
(MonadPrim s m, Prim e) =>
MBytes p s -> m (Count e)
getCountMBytes MBytes p s
mb
MBytes p s
mb' <- Count Word8 -> m (MBytes p s)
forall (p :: Pinned) e s (m :: * -> *).
(Typeable p, Prim e, MonadPrim s m) =>
Count e -> m (MBytes p s)
allocMBytes (Count Word8
n :: Count Word8)
MBytes p s
mb' MBytes p s -> m () -> m (MBytes p s)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ MBytes p s
-> Off Word8 -> MBytes p s -> Off Word8 -> Count Word8 -> m ()
forall s (m :: * -> *) e (ps :: Pinned) (pd :: Pinned).
(MonadPrim s m, Prim e) =>
MBytes ps s -> Off e -> MBytes pd s -> Off e -> Count e -> m ()
moveMBytesToMBytes MBytes p s
mb Off Word8
0 MBytes p s
mb' Off Word8
0 Count Word8
n
{-# INLINE cloneMBytes #-}
copyBytesToMBytes ::
(MonadPrim s m, Prim e) => Bytes ps -> Off e -> MBytes pd s -> Off e -> Count e -> m ()
copyBytesToMBytes :: Bytes ps -> Off e -> MBytes pd s -> Off e -> Count e -> m ()
copyBytesToMBytes (Bytes ByteArray#
src#) Off e
srcOff (MBytes MutableByteArray# s
dst#) Off e
dstOff Count e
c =
(State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ ((State# s -> State# s) -> m ()) -> (State# s -> State# s) -> m ()
forall a b. (a -> b) -> a -> b
$
ByteArray#
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
forall d.
ByteArray#
-> Int#
-> MutableByteArray# d
-> Int#
-> Int#
-> State# d
-> State# d
copyByteArray# ByteArray#
src# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
srcOff) MutableByteArray# s
dst# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
dstOff) (Count e -> Int#
forall e. Prim e => Count e -> Int#
unCountBytes# Count e
c)
{-# INLINE copyBytesToMBytes #-}
moveMBytesToMBytes ::
(MonadPrim s m, Prim e) => MBytes ps s-> Off e -> MBytes pd s -> Off e -> Count e -> m ()
moveMBytesToMBytes :: MBytes ps s -> Off e -> MBytes pd s -> Off e -> Count e -> m ()
moveMBytesToMBytes (MBytes MutableByteArray# s
src#) Off e
srcOff (MBytes MutableByteArray# s
dst#) Off e
dstOff Count e
c =
(State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (MutableByteArray# s
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
forall d.
MutableByteArray# d
-> Int#
-> MutableByteArray# d
-> Int#
-> Int#
-> State# d
-> State# d
copyMutableByteArray# MutableByteArray# s
src# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
srcOff) MutableByteArray# s
dst# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
dstOff) (Count e -> Int#
forall e. Prim e => Count e -> Int#
unCountBytes# Count e
c))
{-# INLINE moveMBytesToMBytes #-}
createBytes ::
forall p e b s m. (Prim e, Typeable p, MonadPrim s m)
=> Count e
-> (MBytes p s -> m b)
-> m (b, Bytes p)
createBytes :: Count e -> (MBytes p s -> m b) -> m (b, Bytes p)
createBytes Count e
n MBytes p s -> m b
f = do
MBytes p s
mb <- Count e -> m (MBytes p s)
forall (p :: Pinned) e s (m :: * -> *).
(Typeable p, Prim e, MonadPrim s m) =>
Count e -> m (MBytes p s)
allocMBytes Count e
n
!b
res <- MBytes p s -> m b
f MBytes p s
mb
(,) b
res (Bytes p -> (b, Bytes p)) -> m (Bytes p) -> m (b, Bytes p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MBytes p s -> m (Bytes p)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Bytes p)
freezeMBytes MBytes p s
mb
{-# INLINE createBytes #-}
createBytes_ ::
forall p e b s m. (Prim e, Typeable p, MonadPrim s m)
=> Count e
-> (MBytes p s -> m b)
-> m (Bytes p)
createBytes_ :: Count e -> (MBytes p s -> m b) -> m (Bytes p)
createBytes_ Count e
n MBytes p s -> m b
f = Count e -> m (MBytes p s)
forall (p :: Pinned) e s (m :: * -> *).
(Typeable p, Prim e, MonadPrim s m) =>
Count e -> m (MBytes p s)
allocMBytes Count e
n m (MBytes p s) -> (MBytes p s -> m (Bytes p)) -> m (Bytes p)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \MBytes p s
mb -> MBytes p s -> m b
f MBytes p s
mb m b -> m (Bytes p) -> m (Bytes p)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MBytes p s -> m (Bytes p)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Bytes p)
freezeMBytes MBytes p s
mb
{-# INLINE createBytes_ #-}
createBytesST ::
forall p e b. (Prim e, Typeable p)
=> Count e
-> (forall s . MBytes p s -> ST s b)
-> (b, Bytes p)
createBytesST :: Count e -> (forall s. MBytes p s -> ST s b) -> (b, Bytes p)
createBytesST Count e
n forall s. MBytes p s -> ST s b
f = (forall s. ST s (b, Bytes p)) -> (b, Bytes p)
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (b, Bytes p)) -> (b, Bytes p))
-> (forall s. ST s (b, Bytes p)) -> (b, Bytes p)
forall a b. (a -> b) -> a -> b
$ Count e -> (MBytes p s -> ST s b) -> ST s (b, Bytes p)
forall (p :: Pinned) e b s (m :: * -> *).
(Prim e, Typeable p, MonadPrim s m) =>
Count e -> (MBytes p s -> m b) -> m (b, Bytes p)
createBytes Count e
n MBytes p s -> ST s b
forall s. MBytes p s -> ST s b
f
{-# INLINE createBytesST #-}
createBytesST_ ::
forall p e b. (Prim e, Typeable p)
=> Count e
-> (forall s. MBytes p s -> ST s b)
-> Bytes p
createBytesST_ :: Count e -> (forall s. MBytes p s -> ST s b) -> Bytes p
createBytesST_ Count e
n forall s. MBytes p s -> ST s b
f = (forall s. ST s (Bytes p)) -> Bytes p
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (Bytes p)) -> Bytes p)
-> (forall s. ST s (Bytes p)) -> Bytes p
forall a b. (a -> b) -> a -> b
$ Count e -> (MBytes p s -> ST s b) -> ST s (Bytes p)
forall (p :: Pinned) e b s (m :: * -> *).
(Prim e, Typeable p, MonadPrim s m) =>
Count e -> (MBytes p s -> m b) -> m (Bytes p)
createBytes_ Count e
n MBytes p s -> ST s b
forall s. MBytes p s -> ST s b
f
{-# INLINE createBytesST_ #-}
allocZeroMBytes :: (MonadPrim s m, Prim e, Typeable p) => Count e -> m (MBytes p s)
allocZeroMBytes :: Count e -> m (MBytes p s)
allocZeroMBytes Count e
n = Count e -> m (MBytes p s)
forall (p :: Pinned) e s (m :: * -> *).
(Typeable p, Prim e, MonadPrim s m) =>
Count e -> m (MBytes p s)
allocMBytes Count e
n m (MBytes p s) -> (MBytes p s -> m (MBytes p s)) -> m (MBytes p s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \MBytes p s
mb -> MBytes p s
mb MBytes p s -> m () -> m (MBytes p s)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ MBytes p s -> Off Word8 -> Count Word8 -> Word8 -> m ()
forall s (m :: * -> *) e (p :: Pinned).
(MonadPrim s m, Prim e) =>
MBytes p s -> Off e -> Count e -> e -> m ()
setMBytes MBytes p s
mb Off Word8
0 (Count e -> Count Word8
forall e. Prim e => Count e -> Count Word8
toByteCount Count e
n) Word8
0
{-# INLINE allocZeroMBytes #-}
zeroMBytes :: MonadPrim s m => MBytes p s -> m ()
zeroMBytes :: MBytes p s -> m ()
zeroMBytes mba :: MBytes p s
mba@(MBytes MutableByteArray# s
mba#) = do
Count (I# Int#
n#) <- MBytes p s -> m (Count Word8)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Count Word8)
getByteCountMBytes MBytes p s
mba
(State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (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#
0# Int#
n# Int#
0#)
{-# INLINE zeroMBytes #-}
withCloneMBytes ::
(MonadPrim s m, Typeable p)
=> Bytes p
-> (MBytes p s -> m a)
-> m (a, Bytes p)
withCloneMBytes :: Bytes p -> (MBytes p s -> m a) -> m (a, Bytes p)
withCloneMBytes Bytes p
b MBytes p s -> m a
f = do
MBytes p s
mb <- MBytes p s -> m (MBytes p s)
forall s (m :: * -> *) (p :: Pinned).
(MonadPrim s m, Typeable p) =>
MBytes p s -> m (MBytes p s)
cloneMBytes (MBytes p s -> m (MBytes p s)) -> m (MBytes p s) -> m (MBytes p s)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bytes p -> m (MBytes p s)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
Bytes p -> m (MBytes p s)
thawBytes Bytes p
b
!a
res <- MBytes p s -> m a
f MBytes p s
mb
Bytes p
b' <- MBytes p s -> m (Bytes p)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Bytes p)
freezeMBytes MBytes p s
mb
(a, Bytes p) -> m (a, Bytes p)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
res, Bytes p
b')
{-# INLINE withCloneMBytes #-}
withCloneMBytes_ ::
(MonadPrim s m, Typeable p)
=> Bytes p
-> (MBytes p s -> m a)
-> m (Bytes p)
withCloneMBytes_ :: Bytes p -> (MBytes p s -> m a) -> m (Bytes p)
withCloneMBytes_ Bytes p
b MBytes p s -> m a
f = Bytes p -> m (MBytes p s)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
Bytes p -> m (MBytes p s)
thawBytes Bytes p
b m (MBytes p s) -> (MBytes p s -> m (MBytes p s)) -> m (MBytes p s)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MBytes p s -> m (MBytes p s)
forall s (m :: * -> *) (p :: Pinned).
(MonadPrim s m, Typeable p) =>
MBytes p s -> m (MBytes p s)
cloneMBytes m (MBytes p s) -> (MBytes p s -> m (Bytes p)) -> m (Bytes p)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \MBytes p s
mb -> MBytes p s -> m a
f MBytes p s
mb m a -> m (Bytes p) -> m (Bytes p)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MBytes p s -> m (Bytes p)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Bytes p)
freezeMBytes MBytes p s
mb
{-# INLINE withCloneMBytes_ #-}
withCloneMBytesST ::
Typeable p => Bytes p -> (forall s. MBytes p s -> ST s a) -> (a, Bytes p)
withCloneMBytesST :: Bytes p -> (forall s. MBytes p s -> ST s a) -> (a, Bytes p)
withCloneMBytesST Bytes p
b forall s. MBytes p s -> ST s a
f = (forall s. ST s (a, Bytes p)) -> (a, Bytes p)
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (a, Bytes p)) -> (a, Bytes p))
-> (forall s. ST s (a, Bytes p)) -> (a, Bytes p)
forall a b. (a -> b) -> a -> b
$ Bytes p -> (MBytes p s -> ST s a) -> ST s (a, Bytes p)
forall s (m :: * -> *) (p :: Pinned) a.
(MonadPrim s m, Typeable p) =>
Bytes p -> (MBytes p s -> m a) -> m (a, Bytes p)
withCloneMBytes Bytes p
b MBytes p s -> ST s a
forall s. MBytes p s -> ST s a
f
{-# INLINE withCloneMBytesST #-}
withCloneMBytesST_ ::
Typeable p => Bytes p -> (forall s. MBytes p s -> ST s a) -> Bytes p
withCloneMBytesST_ :: Bytes p -> (forall s. MBytes p s -> ST s a) -> Bytes p
withCloneMBytesST_ Bytes p
b forall s. MBytes p s -> ST s a
f = (forall s. ST s (Bytes p)) -> Bytes p
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (Bytes p)) -> Bytes p)
-> (forall s. ST s (Bytes p)) -> Bytes p
forall a b. (a -> b) -> a -> b
$ Bytes p -> (MBytes p s -> ST s a) -> ST s (Bytes p)
forall s (m :: * -> *) (p :: Pinned) a.
(MonadPrim s m, Typeable p) =>
Bytes p -> (MBytes p s -> m a) -> m (Bytes p)
withCloneMBytes_ Bytes p
b MBytes p s -> ST s a
forall s. MBytes p s -> ST s a
f
{-# INLINE withCloneMBytesST_ #-}
countRemBytes :: forall e p. Prim e => Bytes p -> (Count e, Count Word8)
countRemBytes :: Bytes p -> (Count e, Count Word8)
countRemBytes = Count Word8 -> (Count e, Count Word8)
forall e. Prim e => Count Word8 -> (Count e, Count Word8)
fromByteCountRem (Count Word8 -> (Count e, Count Word8))
-> (Bytes p -> Count Word8) -> Bytes p -> (Count e, Count Word8)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bytes p -> Count Word8
forall (p :: Pinned). Bytes p -> Count Word8
byteCountBytes
{-# INLINE countRemBytes #-}
getCountRemOfMBytes ::
forall e p s m. (MonadPrim s m, Prim e)
=> MBytes p s
-> m (Count e, Count Word8)
getCountRemOfMBytes :: MBytes p s -> m (Count e, Count Word8)
getCountRemOfMBytes MBytes p s
b = Count Word8 -> (Count e, Count Word8)
forall e. Prim e => Count Word8 -> (Count e, Count Word8)
fromByteCountRem (Count Word8 -> (Count e, Count Word8))
-> m (Count Word8) -> m (Count e, Count Word8)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MBytes p s -> m (Count Word8)
forall s (m :: * -> *) (p :: Pinned).
MonadPrim s m =>
MBytes p s -> m (Count Word8)
getByteCountMBytes MBytes p s
b
{-# INLINE getCountRemOfMBytes #-}
toListBytes :: Prim e => Bytes p -> [e]
toListBytes :: Bytes p -> [e]
toListBytes = Bytes p -> [e]
forall e mr. (MemRead mr, Prim e) => mr -> [e]
toListMem
{-# INLINE toListBytes #-}
toListSlackBytes :: Prim e => Bytes p -> ([e], [Word8])
toListSlackBytes :: Bytes p -> ([e], [Word8])
toListSlackBytes = Bytes p -> ([e], [Word8])
forall e mr. (MemRead mr, Prim e) => mr -> ([e], [Word8])
toListSlackMem
{-# INLINE toListSlackBytes #-}
loadListMBytes :: (Prim e, Typeable p, MonadPrim s m) => [e] -> MBytes p s -> m ([e], Count e)
loadListMBytes :: [e] -> MBytes p s -> m ([e], Count e)
loadListMBytes = [e] -> MBytes p s -> m ([e], Count e)
forall e (ma :: * -> *) (m :: * -> *) s.
(Prim e, MemAlloc ma, MonadPrim s m) =>
[e] -> ma s -> m ([e], Count e)
loadListMutMem
{-# INLINE loadListMBytes #-}
loadListMBytes_ :: (Prim e, Typeable p, MonadPrim s m) => [e] -> MBytes p s -> m ()
loadListMBytes_ :: [e] -> MBytes p s -> m ()
loadListMBytes_ = [e] -> MBytes p s -> m ()
forall e (ma :: * -> *) (m :: * -> *) s.
(Prim e, MemAlloc ma, MonadPrim s m) =>
[e] -> ma s -> m ()
loadListMutMem_
{-# INLINE loadListMBytes_ #-}
fromListZeroBytesN_ :: (Prim e, Typeable p) => Count e -> [e] -> Bytes p
fromListZeroBytesN_ :: Count e -> [e] -> Bytes p
fromListZeroBytesN_ = Count e -> [e] -> Bytes p
forall e (ma :: * -> *).
(Prim e, MemAlloc ma) =>
Count e -> [e] -> FrozenMem ma
fromListZeroMemN_
{-# INLINE fromListZeroBytesN_ #-}
fromListBytesN ::
(Prim e, Typeable p)
=> Count e
-> [e]
-> (Either [e] (Count e), Bytes p)
fromListBytesN :: Count e -> [e] -> (Either [e] (Count e), Bytes p)
fromListBytesN = Count e -> [e] -> (Either [e] (Count e), Bytes p)
forall e (ma :: * -> *).
(Prim e, MemAlloc ma) =>
Count e -> [e] -> (Either [e] (Count e), FrozenMem ma)
fromListMemN
{-# INLINE fromListBytesN #-}
fromListBytes ::
forall e p. (Prim e, Typeable p)
=> [e]
-> Bytes p
fromListBytes :: [e] -> Bytes p
fromListBytes = [e] -> Bytes p
forall e (ma :: * -> *).
(Prim e, MemAlloc ma) =>
[e] -> FrozenMem ma
fromListMem
{-# INLINE fromListBytes #-}
appendBytes ::
Typeable p
=> Bytes p1
-> Bytes p2
-> Bytes p
appendBytes :: Bytes p1 -> Bytes p2 -> Bytes p
appendBytes = Bytes p1 -> Bytes p2 -> Bytes p
forall mr1 mr2 (ma :: * -> *).
(MemRead mr1, MemRead mr2, MemAlloc ma) =>
mr1 -> mr2 -> FrozenMem ma
appendMem
{-# INLINE appendBytes #-}
concatBytes :: Typeable p => [Bytes p'] -> Bytes p
concatBytes :: [Bytes p'] -> Bytes p
concatBytes = [Bytes p'] -> Bytes p
forall mr (ma :: * -> *).
(MemRead mr, MemAlloc ma) =>
[mr] -> FrozenMem ma
concatMem
{-# INLINE concatBytes #-}
ensurePinnedBytes :: Bytes p -> Bytes 'Pin
ensurePinnedBytes :: Bytes p -> Bytes 'Pin
ensurePinnedBytes Bytes p
b = Bytes 'Pin -> Maybe (Bytes 'Pin) -> Bytes 'Pin
forall a. a -> Maybe a -> a
fromMaybe (Bytes p -> FrozenMem (MBytes 'Pin)
forall mr (ma :: * -> *).
(MemRead mr, MemAlloc ma) =>
mr -> FrozenMem ma
convertMem Bytes p
b) (Bytes p -> Maybe (Bytes 'Pin)
forall (p :: Pinned). Bytes p -> Maybe (Bytes 'Pin)
toPinnedBytes Bytes p
b)
{-# INLINE ensurePinnedBytes #-}
ensurePinnedMBytes :: MonadPrim s m => MBytes p s -> m (MBytes 'Pin s)
ensurePinnedMBytes :: MBytes p s -> m (MBytes 'Pin s)
ensurePinnedMBytes MBytes p s
mb =
case MBytes p s -> Maybe (MBytes 'Pin s)
forall (p :: Pinned) s. MBytes p s -> Maybe (MBytes 'Pin s)
toPinnedMBytes MBytes p s
mb of
Just MBytes 'Pin s
pmb -> MBytes 'Pin s -> m (MBytes 'Pin s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure MBytes 'Pin s
pmb
Maybe (MBytes 'Pin s)
Nothing -> do
Count Word8
n8 :: Count Word8 <- MBytes p s -> m (Count Word8)
forall s (m :: * -> *) e (p :: Pinned).
(MonadPrim s m, Prim e) =>
MBytes p s -> m (Count e)
getCountMBytes MBytes p s
mb
MBytes 'Pin s
pmb <- Count Word8 -> m (MBytes 'Pin s)
forall s (m :: * -> *) e.
(MonadPrim s m, Prim e) =>
Count e -> m (MBytes 'Pin s)
allocPinnedMBytes Count Word8
n8
MBytes 'Pin s
pmb MBytes 'Pin s -> m () -> m (MBytes 'Pin s)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ MBytes p s
-> Off Word8 -> MBytes 'Pin s -> Off Word8 -> Count Word8 -> m ()
forall s (m :: * -> *) e (ps :: Pinned) (pd :: Pinned).
(MonadPrim s m, Prim e) =>
MBytes ps s -> Off e -> MBytes pd s -> Off e -> Count e -> m ()
moveMBytesToMBytes MBytes p s
mb Off Word8
0 MBytes 'Pin s
pmb Off Word8
0 Count Word8
n8
{-# INLINE ensurePinnedMBytes #-}
toPinnedBytes :: Bytes p -> Maybe (Bytes 'Pin)
toPinnedBytes :: Bytes p -> Maybe (Bytes 'Pin)
toPinnedBytes (Bytes ByteArray#
b#)
| Int# -> Bool
isTrue# (ByteArray# -> Int#
isByteArrayPinned# ByteArray#
b#) = Bytes 'Pin -> Maybe (Bytes 'Pin)
forall k1. k1 -> Maybe k1
Just (ByteArray# -> Bytes 'Pin
forall (p :: Pinned). ByteArray# -> Bytes p
Bytes ByteArray#
b#)
| Bool
otherwise = Maybe (Bytes 'Pin)
forall k1. Maybe k1
Nothing
{-# INLINE toPinnedBytes #-}
toPinnedMBytes :: MBytes p s -> Maybe (MBytes 'Pin s)
toPinnedMBytes :: MBytes p s -> Maybe (MBytes 'Pin s)
toPinnedMBytes (MBytes MutableByteArray# s
mb#)
| Int# -> Bool
isTrue# (MutableByteArray# s -> Int#
forall d. MutableByteArray# d -> Int#
isMutableByteArrayPinned# MutableByteArray# s
mb#) = MBytes 'Pin s -> Maybe (MBytes 'Pin s)
forall k1. k1 -> Maybe k1
Just (MutableByteArray# s -> MBytes 'Pin s
forall (p :: Pinned) s. MutableByteArray# s -> MBytes p s
MBytes MutableByteArray# s
mb#)
| Bool
otherwise = Maybe (MBytes 'Pin s)
forall k1. Maybe k1
Nothing
{-# INLINE toPinnedMBytes #-}
casMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> e
-> e
-> m e
casMBytes :: MBytes p s -> Off e -> e -> e -> m e
casMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
expected e
new =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim ((State# s -> (# State# s, e #)) -> m e)
-> (State# s -> (# State# s, e #)) -> m e
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s
-> Int# -> e -> e -> State# s -> (# State# s, e #)
forall a s.
Atomic a =>
MutableByteArray# s
-> Int# -> a -> a -> State# s -> (# State# s, a #)
casMutableByteArray# MutableByteArray# s
mba# Int#
i# e
expected e
new
{-# INLINE casMBytes #-}
casBoolMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> e
-> e
-> m Bool
casBoolMBytes :: MBytes p s -> Off e -> e -> e -> m Bool
casBoolMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
expected e
new =
(State# s -> (# State# s, Bool #)) -> m Bool
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim ((State# s -> (# State# s, Bool #)) -> m Bool)
-> (State# s -> (# State# s, Bool #)) -> m Bool
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s
-> Int# -> e -> e -> State# s -> (# State# s, Bool #)
forall a s.
Atomic a =>
MutableByteArray# s
-> Int# -> a -> a -> State# s -> (# State# s, Bool #)
casBoolMutableByteArray# MutableByteArray# s
mba# Int#
i# e
expected e
new
{-# INLINE casBoolMBytes #-}
casBoolFetchMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> e
-> e
-> m (Bool, e)
casBoolFetchMBytes :: MBytes p s -> Off e -> e -> e -> m (Bool, e)
casBoolFetchMBytes MBytes p s
mb Off e
off e
expected e
new = do
Bool
isCasSucc <- MBytes p s -> Off e -> e -> e -> m Bool
forall s (m :: * -> *) e (p :: Pinned).
(MonadPrim s m, Atomic e) =>
MBytes p s -> Off e -> e -> e -> m Bool
casBoolMBytes MBytes p s
mb Off e
off e
expected e
new
e
actual <-
if Bool
isCasSucc
then e -> m e
forall (f :: * -> *) a. Applicative f => a -> f a
pure e
new
else MBytes p s -> Off e -> m e
forall s (m :: * -> *) e (p :: Pinned).
(MonadPrim s m, Prim e) =>
MBytes p s -> Off e -> m e
readOffMBytes MBytes p s
mb Off e
off
(Bool, e) -> m (Bool, e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool
isCasSucc, e
actual)
{-# INLINE casBoolFetchMBytes #-}
atomicReadMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> m e
atomicReadMBytes :: MBytes p s -> Off e -> m e
atomicReadMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim ((State# s -> (# State# s, e #)) -> m e)
-> (State# s -> (# State# s, e #)) -> m e
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s -> Int# -> State# s -> (# State# s, e #)
forall a s.
Atomic a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
atomicReadMutableByteArray# MutableByteArray# s
mba# Int#
i#
{-# INLINE atomicReadMBytes #-}
atomicWriteMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> e
-> m ()
atomicWriteMBytes :: MBytes p s -> Off e -> e -> m ()
atomicWriteMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
e =
(State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ ((State# s -> State# s) -> m ()) -> (State# s -> State# s) -> m ()
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s -> Int# -> e -> State# s -> State# s
forall a s.
Atomic a =>
MutableByteArray# s -> Int# -> a -> State# s -> State# s
atomicWriteMutableByteArray# MutableByteArray# s
mba# Int#
i# e
e
{-# INLINE atomicWriteMBytes #-}
atomicModifyMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> (e -> (e, b))
-> m b
atomicModifyMBytes :: MBytes p s -> Off e -> (e -> (e, b)) -> m b
atomicModifyMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e -> (e, b)
f =
(State# s -> (# State# s, b #)) -> m b
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim ((State# s -> (# State# s, b #)) -> m b)
-> (State# s -> (# State# s, b #)) -> m b
forall a b. (a -> b) -> a -> b
$
MutableByteArray# s
-> Int# -> (e -> (# e, b #)) -> State# s -> (# State# s, b #)
forall a s b.
Atomic a =>
MutableByteArray# s
-> Int# -> (a -> (# a, b #)) -> State# s -> (# State# s, b #)
atomicModifyMutableByteArray# MutableByteArray# s
mba# Int#
i# ((e -> (# e, b #)) -> State# s -> (# State# s, b #))
-> (e -> (# e, b #)) -> State# s -> (# State# s, b #)
forall a b. (a -> b) -> a -> b
$ \e
a ->
case e -> (e, b)
f e
a of
(e
a', b
b) -> (# e
a', b
b #)
{-# INLINE atomicModifyMBytes #-}
atomicModifyMBytes_ ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> (e -> e)
-> m ()
atomicModifyMBytes_ :: MBytes p s -> Off e -> (e -> e) -> m ()
atomicModifyMBytes_ (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e -> e
f =
(State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ ((State# s -> State# s) -> m ()) -> (State# s -> State# s) -> m ()
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s -> Int# -> (e -> e) -> State# s -> State# s
forall a s.
Atomic a =>
MutableByteArray# s -> Int# -> (a -> a) -> State# s -> State# s
atomicModifyMutableByteArray_# MutableByteArray# s
mba# Int#
i# e -> e
f
{-# INLINE atomicModifyMBytes_ #-}
atomicModifyFetchOldMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> (e -> e)
-> m e
atomicModifyFetchOldMBytes :: MBytes p s -> Off e -> (e -> e) -> m e
atomicModifyFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e -> e
f =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim ((State# s -> (# State# s, e #)) -> m e)
-> (State# s -> (# State# s, e #)) -> m e
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s
-> Int# -> (e -> e) -> State# s -> (# State# s, e #)
forall a s.
Atomic a =>
MutableByteArray# s
-> Int# -> (a -> a) -> State# s -> (# State# s, a #)
atomicModifyFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e -> e
f
{-# INLINE atomicModifyFetchOldMBytes #-}
atomicBoolModifyFetchOldMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> (e -> e)
-> m e
atomicBoolModifyFetchOldMBytes :: MBytes p s -> Off e -> (e -> e) -> m e
atomicBoolModifyFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e -> e
f =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim ((State# s -> (# State# s, e #)) -> m e)
-> (State# s -> (# State# s, e #)) -> m e
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s
-> Int# -> (e -> e) -> State# s -> (# State# s, e #)
forall a s.
Atomic a =>
MutableByteArray# s
-> Int# -> (a -> a) -> State# s -> (# State# s, a #)
atomicBoolModifyFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e -> e
f
{-# INLINE atomicBoolModifyFetchOldMBytes #-}
atomicModifyFetchNewMBytes ::
(MonadPrim s m, Atomic e)
=> MBytes p s
-> Off e
-> (e -> e)
-> m e
atomicModifyFetchNewMBytes :: MBytes p s -> Off e -> (e -> e) -> m e
atomicModifyFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e -> e
f =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim ((State# s -> (# State# s, e #)) -> m e)
-> (State# s -> (# State# s, e #)) -> m e
forall a b. (a -> b) -> a -> b
$ MutableByteArray# s
-> Int# -> (e -> e) -> State# s -> (# State# s, e #)
forall a s.
Atomic a =>
MutableByteArray# s
-> Int# -> (a -> a) -> State# s -> (# State# s, a #)
atomicModifyFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i# e -> e
f
{-# INLINE atomicModifyFetchNewMBytes #-}
atomicAddFetchOldMBytes ::
(MonadPrim s m, AtomicCount e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicAddFetchOldMBytes :: MBytes p s -> Off e -> e -> m e
atomicAddFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicCount a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicAddFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicAddFetchOldMBytes #-}
atomicAddFetchNewMBytes ::
(MonadPrim s m, AtomicCount e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicAddFetchNewMBytes :: MBytes p s -> Off e -> e -> m e
atomicAddFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicCount a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicAddFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicAddFetchNewMBytes #-}
atomicSubFetchOldMBytes ::
(MonadPrim s m, AtomicCount e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicSubFetchOldMBytes :: MBytes p s -> Off e -> e -> m e
atomicSubFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicCount a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicSubFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicSubFetchOldMBytes #-}
atomicSubFetchNewMBytes ::
(MonadPrim s m, AtomicCount e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicSubFetchNewMBytes :: MBytes p s -> Off e -> e -> m e
atomicSubFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicCount a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicSubFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicSubFetchNewMBytes #-}
atomicAndFetchOldMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicAndFetchOldMBytes :: MBytes p s -> Off e -> e -> m e
atomicAndFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicAndFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicAndFetchOldMBytes #-}
atomicAndFetchNewMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicAndFetchNewMBytes :: MBytes p s -> Off e -> e -> m e
atomicAndFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicAndFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicAndFetchNewMBytes #-}
atomicNandFetchOldMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicNandFetchOldMBytes :: MBytes p s -> Off e -> e -> m e
atomicNandFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicNandFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicNandFetchOldMBytes #-}
atomicNandFetchNewMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicNandFetchNewMBytes :: MBytes p s -> Off e -> e -> m e
atomicNandFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicNandFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicNandFetchNewMBytes #-}
atomicOrFetchOldMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicOrFetchOldMBytes :: MBytes p s -> Off e -> e -> m e
atomicOrFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicOrFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicOrFetchOldMBytes #-}
atomicOrFetchNewMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicOrFetchNewMBytes :: MBytes p s -> Off e -> e -> m e
atomicOrFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicOrFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicOrFetchNewMBytes #-}
atomicXorFetchOldMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicXorFetchOldMBytes :: MBytes p s -> Off e -> e -> m e
atomicXorFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicXorFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicXorFetchOldMBytes #-}
atomicXorFetchNewMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> e
-> m e
atomicXorFetchNewMBytes :: MBytes p s -> Off e -> e -> m e
atomicXorFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) e
a =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> e -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> a -> State# s -> (# State# s, a #)
atomicXorFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i# e
a)
{-# INLINE atomicXorFetchNewMBytes #-}
atomicNotFetchOldMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> m e
atomicNotFetchOldMBytes :: MBytes p s -> Off e -> m e
atomicNotFetchOldMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
atomicNotFetchOldMutableByteArray# MutableByteArray# s
mba# Int#
i#)
{-# INLINE atomicNotFetchOldMBytes #-}
atomicNotFetchNewMBytes ::
(MonadPrim s m, AtomicBits e)
=> MBytes p s
-> Off e
-> m e
atomicNotFetchNewMBytes :: MBytes p s -> Off e -> m e
atomicNotFetchNewMBytes (MBytes MutableByteArray# s
mba#) (Off (I# Int#
i#)) =
(State# s -> (# State# s, e #)) -> m e
forall s (m :: * -> *) a.
MonadPrim s m =>
(State# s -> (# State# s, a #)) -> m a
prim (MutableByteArray# s -> Int# -> State# s -> (# State# s, e #)
forall a s.
AtomicBits a =>
MutableByteArray# s -> Int# -> State# s -> (# State# s, a #)
atomicNotFetchNewMutableByteArray# MutableByteArray# s
mba# Int#
i#)
{-# INLINE atomicNotFetchNewMBytes #-}
prefetchBytes0 :: (MonadPrim s m, Prim e) => Bytes p -> Off e -> m ()
prefetchBytes0 :: Bytes p -> Off e -> m ()
prefetchBytes0 (Bytes ByteArray#
b#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (ByteArray# -> Int# -> State# s -> State# s
forall d. ByteArray# -> Int# -> State# d -> State# d
prefetchByteArray0# ByteArray#
b# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchBytes0 #-}
prefetchMBytes0 :: (MonadPrim s m, Prim e) => MBytes p s -> Off e -> m ()
prefetchMBytes0 :: MBytes p s -> Off e -> m ()
prefetchMBytes0 (MBytes MutableByteArray# s
mb#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (MutableByteArray# s -> Int# -> State# s -> State# s
forall d. MutableByteArray# d -> Int# -> State# d -> State# d
prefetchMutableByteArray0# MutableByteArray# s
mb# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchMBytes0 #-}
prefetchBytes1 :: (MonadPrim s m, Prim e) => Bytes p -> Off e -> m ()
prefetchBytes1 :: Bytes p -> Off e -> m ()
prefetchBytes1 (Bytes ByteArray#
b#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (ByteArray# -> Int# -> State# s -> State# s
forall d. ByteArray# -> Int# -> State# d -> State# d
prefetchByteArray1# ByteArray#
b# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchBytes1 #-}
prefetchMBytes1 :: (MonadPrim s m, Prim e) => MBytes p s -> Off e -> m ()
prefetchMBytes1 :: MBytes p s -> Off e -> m ()
prefetchMBytes1 (MBytes MutableByteArray# s
mb#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (MutableByteArray# s -> Int# -> State# s -> State# s
forall d. MutableByteArray# d -> Int# -> State# d -> State# d
prefetchMutableByteArray1# MutableByteArray# s
mb# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchMBytes1 #-}
prefetchBytes2 :: (MonadPrim s m, Prim e) => Bytes p -> Off e -> m ()
prefetchBytes2 :: Bytes p -> Off e -> m ()
prefetchBytes2 (Bytes ByteArray#
b#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (ByteArray# -> Int# -> State# s -> State# s
forall d. ByteArray# -> Int# -> State# d -> State# d
prefetchByteArray2# ByteArray#
b# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchBytes2 #-}
prefetchMBytes2 :: (MonadPrim s m, Prim e) => MBytes p s -> Off e -> m ()
prefetchMBytes2 :: MBytes p s -> Off e -> m ()
prefetchMBytes2 (MBytes MutableByteArray# s
mb#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (MutableByteArray# s -> Int# -> State# s -> State# s
forall d. MutableByteArray# d -> Int# -> State# d -> State# d
prefetchMutableByteArray2# MutableByteArray# s
mb# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchMBytes2 #-}
prefetchBytes3 :: (MonadPrim s m, Prim e) => Bytes p -> Off e -> m ()
prefetchBytes3 :: Bytes p -> Off e -> m ()
prefetchBytes3 (Bytes ByteArray#
b#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (ByteArray# -> Int# -> State# s -> State# s
forall d. ByteArray# -> Int# -> State# d -> State# d
prefetchByteArray3# ByteArray#
b# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchBytes3 #-}
prefetchMBytes3 :: (MonadPrim s m, Prim e) => MBytes p s -> Off e -> m ()
prefetchMBytes3 :: MBytes p s -> Off e -> m ()
prefetchMBytes3 (MBytes MutableByteArray# s
mb#) Off e
off = (State# s -> State# s) -> m ()
forall s (m :: * -> *).
MonadPrim s m =>
(State# s -> State# s) -> m ()
prim_ (MutableByteArray# s -> Int# -> State# s -> State# s
forall d. MutableByteArray# d -> Int# -> State# d -> State# d
prefetchMutableByteArray3# MutableByteArray# s
mb# (Off e -> Int#
forall e. Prim e => Off e -> Int#
unOffBytes# Off e
off))
{-# INLINE prefetchMBytes3 #-}