ghc-prim-0.11.0: GHC primitives
Maintainerghc-devs@haskell.org
Stabilityinternal
Portabilitynon-portable (GHC extensions)
Safe HaskellUnsafe
LanguageHaskell2010

GHC.Prim

Description

GHC's primitive types and operations. Use GHC.Exts from the base package instead of importing this module directly.

Synopsis

Builtin syntax

data FUN Source #

The builtin function type, written in infix form as a % m -> b. Values of this type are functions taking inputs of type a and producing outputs of type b. The multiplicity of the input is m.

Note that FUN m a b permits representation polymorphism in both a and b, so that types like Int# -> Int# can still be well-kinded.

The word size story.

Haskell98 specifies that signed integers (type Int) must contain at least 30 bits. GHC always implements Int using the primitive type Int#, whose size equals the MachDeps.h constant WORD_SIZE_IN_BITS. This is normally set based on the RTS ghcautoconf.h parameter SIZEOF_HSWORD, i.e., 32 bits on 32-bit machines, 64 bits on 64-bit machines.

GHC also implements a primitive unsigned integer type Word# which always has the same number of bits as Int#.

In addition, GHC supports families of explicit-sized integers and words at 8, 16, 32, and 64 bits, with the usual arithmetic operations, comparisons, and a range of conversions.

Finally, there are strongly deprecated primops for coercing between Addr#, the primitive type of machine addresses, and Int#. These are pretty bogus anyway, but will work on existing 32-bit and 64-bit GHC targets; they are completely bogus when tag bits are used in Int#, so are not available in this case.

Char#

Operations on 31-bit characters.

Int8#

Operations on 8-bit integers.

Word8#

Operations on 8-bit unsigned words.

Int16#

Operations on 16-bit integers.

Word16#

Operations on 16-bit unsigned words.

Int32#

Operations on 32-bit integers.

Word32#

Operations on 32-bit unsigned words.

Int64#

Operations on 64-bit signed words.

Word64#

Operations on 64-bit unsigned words.

Int#

Operations on native-size integers (32+ bits).

(+#) :: Int# -> Int# -> Int# infixl 6 Source #

(-#) :: Int# -> Int# -> Int# infixl 6 Source #

(*#) :: Int# -> Int# -> Int# infixl 7 Source #

Low word of signed integer multiply.

timesInt2# :: Int# -> Int# -> (# Int#, Int#, Int# #) Source #

Return a triple (isHighNeeded,high,low) where high and low are respectively the high and low bits of the double-word result. isHighNeeded is a cheap way to test if the high word is a sign-extension of the low word (isHighNeeded = 0#) or not (isHighNeeded = 1#).

mulIntMayOflo# :: Int# -> Int# -> Int# Source #

Return non-zero if there is any possibility that the upper word of a signed integer multiply might contain useful information. Return zero only if you are completely sure that no overflow can occur. On a 32-bit platform, the recommended implementation is to do a 32 x 32 -> 64 signed multiply, and subtract result[63:32] from (result[31] >>signed 31). If this is zero, meaning that the upper word is merely a sign extension of the lower one, no overflow can occur.

On a 64-bit platform it is not always possible to acquire the top 64 bits of the result. Therefore, a recommended implementation is to take the absolute value of both operands, and return 0 iff bits[63:31] of them are zero, since that means that their magnitudes fit within 31 bits, so the magnitude of the product must fit into 62 bits.

If in doubt, return non-zero, but do make an effort to create the correct answer for small args, since otherwise the performance of (*) :: Integer -> Integer -> Integer will be poor.

quotInt# :: Int# -> Int# -> Int# Source #

Rounds towards zero. The behavior is undefined if the second argument is zero.

remInt# :: Int# -> Int# -> Int# Source #

Satisfies (quotInt# x y) *# y +# (remInt# x y) == x. The behavior is undefined if the second argument is zero.

quotRemInt# :: Int# -> Int# -> (# Int#, Int# #) Source #

Rounds towards zero.

andI# :: Int# -> Int# -> Int# Source #

Bitwise "and".

orI# :: Int# -> Int# -> Int# Source #

Bitwise "or".

xorI# :: Int# -> Int# -> Int# Source #

Bitwise "xor".

notI# :: Int# -> Int# Source #

Bitwise "not", also known as the binary complement.

negateInt# :: Int# -> Int# Source #

Unary negation. Since the negative Int# range extends one further than the positive range, negateInt# of the most negative number is an identity operation. This way, negateInt# is always its own inverse.

addIntC# :: Int# -> Int# -> (# Int#, Int# #) Source #

Add signed integers reporting overflow. First member of result is the sum truncated to an Int#; second member is zero if the true sum fits in an Int#, nonzero if overflow occurred (the sum is either too large or too small to fit in an Int#).

subIntC# :: Int# -> Int# -> (# Int#, Int# #) Source #

Subtract signed integers reporting overflow. First member of result is the difference truncated to an Int#; second member is zero if the true difference fits in an Int#, nonzero if overflow occurred (the difference is either too large or too small to fit in an Int#).

(>#) :: Int# -> Int# -> Int# infix 4 Source #

(>=#) :: Int# -> Int# -> Int# infix 4 Source #

(==#) :: Int# -> Int# -> Int# infix 4 Source #

(/=#) :: Int# -> Int# -> Int# infix 4 Source #

(<#) :: Int# -> Int# -> Int# infix 4 Source #

(<=#) :: Int# -> Int# -> Int# infix 4 Source #

int2Float# :: Int# -> Float# Source #

Convert an Int# to the corresponding Float# with the same integral value (up to truncation due to floating-point precision). e.g. int2Float# 1# == 1.0#

int2Double# :: Int# -> Double# Source #

Convert an Int# to the corresponding Double# with the same integral value (up to truncation due to floating-point precision). e.g. int2Double# 1# == 1.0##

word2Float# :: Word# -> Float# Source #

Convert an Word# to the corresponding Float# with the same integral value (up to truncation due to floating-point precision). e.g. word2Float# 1## == 1.0#

word2Double# :: Word# -> Double# Source #

Convert an Word# to the corresponding Double# with the same integral value (up to truncation due to floating-point precision). e.g. word2Double# 1## == 1.0##

uncheckedIShiftL# :: Int# -> Int# -> Int# Source #

Shift left. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

uncheckedIShiftRA# :: Int# -> Int# -> Int# Source #

Shift right arithmetic. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

uncheckedIShiftRL# :: Int# -> Int# -> Int# Source #

Shift right logical. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

Word#

Operations on native-sized unsigned words (32+ bits).

addWordC# :: Word# -> Word# -> (# Word#, Int# #) Source #

Add unsigned integers reporting overflow. The first element of the pair is the result. The second element is the carry flag, which is nonzero on overflow. See also plusWord2#.

subWordC# :: Word# -> Word# -> (# Word#, Int# #) Source #

Subtract unsigned integers reporting overflow. The first element of the pair is the result. The second element is the carry flag, which is nonzero on overflow.

plusWord2# :: Word# -> Word# -> (# Word#, Word# #) Source #

Add unsigned integers, with the high part (carry) in the first component of the returned pair and the low part in the second component of the pair. See also addWordC#.

quotRemWord2# :: Word# -> Word# -> Word# -> (# Word#, Word# #) Source #

Takes high word of dividend, then low word of dividend, then divisor. Requires that high word < divisor.

uncheckedShiftL# :: Word# -> Int# -> Word# Source #

Shift left logical. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

uncheckedShiftRL# :: Word# -> Int# -> Word# Source #

Shift right logical. Result undefined if shift amount is not in the range 0 to word size - 1 inclusive.

popCnt8# :: Word# -> Word# Source #

Count the number of set bits in the lower 8 bits of a word.

popCnt16# :: Word# -> Word# Source #

Count the number of set bits in the lower 16 bits of a word.

popCnt32# :: Word# -> Word# Source #

Count the number of set bits in the lower 32 bits of a word.

popCnt64# :: Word64# -> Word# Source #

Count the number of set bits in a 64-bit word.

popCnt# :: Word# -> Word# Source #

Count the number of set bits in a word.

pdep8# :: Word# -> Word# -> Word# Source #

Deposit bits to lower 8 bits of a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pdep16# :: Word# -> Word# -> Word# Source #

Deposit bits to lower 16 bits of a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pdep32# :: Word# -> Word# -> Word# Source #

Deposit bits to lower 32 bits of a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pdep64# :: Word64# -> Word64# -> Word64# Source #

Deposit bits to a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pdep# :: Word# -> Word# -> Word# Source #

Deposit bits to a word at locations specified by a mask, aka parallel bit deposit.

Software emulation:

pdep :: Word -> Word -> Word
pdep src mask = go 0 src mask
  where
    go :: Word -> Word -> Word -> Word
    go result _ 0 = result
    go result src mask = go newResult newSrc newMask
      where
        maskCtz   = countTrailingZeros mask
        newResult = if testBit src 0 then setBit result maskCtz else result
        newSrc    = src `shiftR` 1
        newMask   = clearBit mask maskCtz

Since: ghc-prim-0.5.2.0

pext8# :: Word# -> Word# -> Word# Source #

Extract bits from lower 8 bits of a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pext16# :: Word# -> Word# -> Word# Source #

Extract bits from lower 16 bits of a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pext32# :: Word# -> Word# -> Word# Source #

Extract bits from lower 32 bits of a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pext64# :: Word64# -> Word64# -> Word64# Source #

Extract bits from a word at locations specified by a mask.

Since: ghc-prim-0.5.2.0

pext# :: Word# -> Word# -> Word# Source #

Extract bits from a word at locations specified by a mask, aka parallel bit extract.

Software emulation:

pext :: Word -> Word -> Word
pext src mask = loop 0 0 0
  where
    loop i count result
      | i >= finiteBitSize (0 :: Word)
      = result
      | testBit mask i
      = loop (i + 1) (count + 1) (if testBit src i then setBit result count else result)
      | otherwise
      = loop (i + 1) count result

Since: ghc-prim-0.5.2.0

clz8# :: Word# -> Word# Source #

Count leading zeros in the lower 8 bits of a word.

clz16# :: Word# -> Word# Source #

Count leading zeros in the lower 16 bits of a word.

clz32# :: Word# -> Word# Source #

Count leading zeros in the lower 32 bits of a word.

clz64# :: Word64# -> Word# Source #

Count leading zeros in a 64-bit word.

clz# :: Word# -> Word# Source #

Count leading zeros in a word.

ctz8# :: Word# -> Word# Source #

Count trailing zeros in the lower 8 bits of a word.

ctz16# :: Word# -> Word# Source #

Count trailing zeros in the lower 16 bits of a word.

ctz32# :: Word# -> Word# Source #

Count trailing zeros in the lower 32 bits of a word.

ctz64# :: Word64# -> Word# Source #

Count trailing zeros in a 64-bit word.

ctz# :: Word# -> Word# Source #

Count trailing zeros in a word.

byteSwap16# :: Word# -> Word# Source #

Swap bytes in the lower 16 bits of a word. The higher bytes are undefined.

byteSwap32# :: Word# -> Word# Source #

Swap bytes in the lower 32 bits of a word. The higher bytes are undefined.

byteSwap64# :: Word64# -> Word64# Source #

Swap bytes in a 64 bits of a word.

byteSwap# :: Word# -> Word# Source #

Swap bytes in a word.

bitReverse8# :: Word# -> Word# Source #

Reverse the order of the bits in a 8-bit word.

bitReverse16# :: Word# -> Word# Source #

Reverse the order of the bits in a 16-bit word.

bitReverse32# :: Word# -> Word# Source #

Reverse the order of the bits in a 32-bit word.

bitReverse64# :: Word64# -> Word64# Source #

Reverse the order of the bits in a 64-bit word.

bitReverse# :: Word# -> Word# Source #

Reverse the order of the bits in a word.

Narrowings

Explicit narrowing of native-sized ints or words.

Double#

Operations on double-precision (64 bit) floating-point numbers.

(>##) :: Double# -> Double# -> Int# infix 4 Source #

(>=##) :: Double# -> Double# -> Int# infix 4 Source #

(==##) :: Double# -> Double# -> Int# infix 4 Source #

(/=##) :: Double# -> Double# -> Int# infix 4 Source #

(<##) :: Double# -> Double# -> Int# infix 4 Source #

(<=##) :: Double# -> Double# -> Int# infix 4 Source #

(+##) :: Double# -> Double# -> Double# infixl 6 Source #

(-##) :: Double# -> Double# -> Double# infixl 6 Source #

(*##) :: Double# -> Double# -> Double# infixl 7 Source #

(/##) :: Double# -> Double# -> Double# infixl 7 Source #

double2Int# :: Double# -> Int# Source #

Truncates a Double# value to the nearest Int#. Results are undefined if the truncation if truncation yields a value outside the range of Int#.

(**##) :: Double# -> Double# -> Double# Source #

Exponentiation.

decodeDouble_2Int# :: Double# -> (# Int#, Word#, Word#, Int# #) Source #

Convert to integer. First component of the result is -1 or 1, indicating the sign of the mantissa. The next two are the high and low 32 bits of the mantissa respectively, and the last is the exponent.

decodeDouble_Int64# :: Double# -> (# Int64#, Int# #) Source #

Decode Double# into mantissa and base-2 exponent.

Float#

Operations on single-precision (32-bit) floating-point numbers.

float2Int# :: Float# -> Int# Source #

Truncates a Float# value to the nearest Int#. Results are undefined if the truncation if truncation yields a value outside the range of Int#.

decodeFloat_Int# :: Float# -> (# Int#, Int# #) Source #

Convert to integers. First Int# in result is the mantissa; second is the exponent.

Fused multiply-add operations

The fused multiply-add primops fmaddFloat# and fmaddDouble# implement the operation

\[ \lambda\ x\ y\ z \rightarrow x * y + z \]

with a single floating-point rounding operation at the end, as opposed to rounding twice (which can accumulate rounding errors).

These primops can be compiled directly to a single machine instruction on architectures that support them. Currently, these are:

  1. x86 with CPUs that support the FMA3 extended instruction set (which includes most processors since 2013).
  2. PowerPC.
  3. AArch64.

This requires users pass the '-mfma' flag to GHC. Otherwise, the primop is implemented by falling back to the C standard library, which might perform software emulation (this may yield results that are not IEEE compliant on some platforms).

The additional operations fmsubFloat#/fmsubDouble#, fnmaddFloat#fnmaddDouble# and fnmsubFloat#fnmsubDouble# provide variants on fmaddFloat#/fmaddDouble# in which some signs are changed:

\[ \begin{aligned} \mathrm{fmadd}\ x\ y\ z &= \phantom{+} x * y + z \\[8pt] \mathrm{fmsub}\ x\ y\ z &= \phantom{+} x * y - z \\[8pt] \mathrm{fnmadd}\ x\ y\ z &= - x * y + z \\[8pt] \mathrm{fnmsub}\ x\ y\ z &= - x * y - z \end{aligned} \]

fmaddFloat# :: Float# -> Float# -> Float# -> Float# Source #

Fused multiply-add operation x*y+z. See GHC.Prim.

fmsubFloat# :: Float# -> Float# -> Float# -> Float# Source #

Fused multiply-subtract operation x*y-z. See GHC.Prim.

fnmaddFloat# :: Float# -> Float# -> Float# -> Float# Source #

Fused negate-multiply-add operation -x*y+z. See GHC.Prim.

fnmsubFloat# :: Float# -> Float# -> Float# -> Float# Source #

Fused negate-multiply-subtract operation -x*y-z. See GHC.Prim.

fmaddDouble# :: Double# -> Double# -> Double# -> Double# Source #

Fused multiply-add operation x*y+z. See GHC.Prim.

fmsubDouble# :: Double# -> Double# -> Double# -> Double# Source #

Fused multiply-subtract operation x*y-z. See GHC.Prim.

fnmaddDouble# :: Double# -> Double# -> Double# -> Double# Source #

Fused negate-multiply-add operation -x*y+z. See GHC.Prim.

fnmsubDouble# :: Double# -> Double# -> Double# -> Double# Source #

Fused negate-multiply-subtract operation -x*y-z. See GHC.Prim.

Arrays

Operations on Array#.

data Array# (a :: TYPE ('BoxedRep l)) :: UnliftedType Source #

newArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. Int# -> a -> State# d -> (# State# d, MutableArray# d a #) Source #

Create a new mutable array with the specified number of elements, in the specified state thread, with each element containing the specified initial value.

readArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> Int# -> State# d -> (# State# d, a #) Source #

Read from specified index of mutable array. Result is not yet evaluated.

Warning: this can fail with an unchecked exception.

writeArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> Int# -> a -> State# d -> State# d Source #

Write to specified index of mutable array.

Warning: this can fail with an unchecked exception.

sizeofArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)). Array# a -> Int# Source #

Return the number of elements in the array.

sizeofMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> Int# Source #

Return the number of elements in the array.

indexArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)). Array# a -> Int# -> (# a #) Source #

Read from the specified index of an immutable array. The result is packaged into an unboxed unary tuple; the result itself is not yet evaluated. Pattern matching on the tuple forces the indexing of the array to happen but does not evaluate the element itself. Evaluating the thunk prevents additional thunks from building up on the heap. Avoiding these thunks, in turn, reduces references to the argument array, allowing it to be garbage collected more promptly.

unsafeFreezeArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> State# d -> (# State# d, Array# a #) Source #

Make a mutable array immutable, without copying.

unsafeThawArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. Array# a -> State# d -> (# State# d, MutableArray# d a #) Source #

Make an immutable array mutable, without copying.

copyArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. Array# a -> Int# -> MutableArray# d a -> Int# -> Int# -> State# d -> State# d Source #

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. Both arrays must fully contain the specified ranges, but this is not checked. The two arrays must not be the same array in different states, but this is not checked either.

Warning: this can fail with an unchecked exception.

copyMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> Int# -> MutableArray# d a -> Int# -> Int# -> State# d -> State# d Source #

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. Both arrays must fully contain the specified ranges, but this is not checked. In the case where the source and destination are the same array the source and destination regions may overlap.

Warning: this can fail with an unchecked exception.

cloneArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)). Array# a -> Int# -> Int# -> Array# a Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

cloneMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> Int# -> Int# -> State# d -> (# State# d, MutableArray# d a #) Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

freezeArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> Int# -> Int# -> State# d -> (# State# d, Array# a #) Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

thawArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. Array# a -> Int# -> Int# -> State# d -> (# State# d, MutableArray# d a #) Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

casArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutableArray# d a -> Int# -> a -> a -> State# d -> (# State# d, Int#, a #) Source #

Given an array, an offset, the expected old value, and the new value, perform an atomic compare and swap (i.e. write the new value if the current value and the old value are the same pointer). Returns 0 if the swap succeeds and 1 if it fails. Additionally, returns the element at the offset after the operation completes. This means that on a success the new value is returned, and on a failure the actual old value (not the expected one) is returned. Implies a full memory barrier. The use of a pointer equality on a boxed value makes this function harder to use correctly than casIntArray#. All of the difficulties of using reallyUnsafePtrEquality# correctly apply to casArray# as well.

Warning: this can fail with an unchecked exception.

Small Arrays

Operations on SmallArray#. A SmallArray# works just like an Array#, but with different space use and performance characteristics (that are often useful with small arrays). The SmallArray# and SmallMutableArray# lack a `card table'. The purpose of a card table is to avoid having to scan every element of the array on each GC by keeping track of which elements have changed since the last GC and only scanning those that have changed. So the consequence of there being no card table is that the representation is somewhat smaller and the writes are somewhat faster (because the card table does not need to be updated). The disadvantage of course is that for a SmallMutableArray# the whole array has to be scanned on each GC. Thus it is best suited for use cases where the mutable array is not long lived, e.g. where a mutable array is initialised quickly and then frozen to become an immutable SmallArray#.

newSmallArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. Int# -> a -> State# d -> (# State# d, SmallMutableArray# d a #) Source #

Create a new mutable array with the specified number of elements, in the specified state thread, with each element containing the specified initial value.

shrinkSmallMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# -> State# d -> State# d Source #

Shrink mutable array to new specified size, in the specified state thread. The new size argument must be less than or equal to the current size as reported by getSizeofSmallMutableArray#.

Assuming the non-profiling RTS, for the copying garbage collector (default) this primitive compiles to an O(1) operation in C--, modifying the array in-place. For the non-moving garbage collector, however, the time is proportional to the number of elements shrinked out. Backends bypassing C-- representation (such as JavaScript) might behave differently.

Warning: this can fail with an unchecked exception.

Since: ghc-prim-0.6.1

readSmallArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# -> State# d -> (# State# d, a #) Source #

Read from specified index of mutable array. Result is not yet evaluated.

Warning: this can fail with an unchecked exception.

writeSmallArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# -> a -> State# d -> State# d Source #

Write to specified index of mutable array.

Warning: this can fail with an unchecked exception.

sizeofSmallArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)). SmallArray# a -> Int# Source #

Return the number of elements in the array.

sizeofSmallMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# Source #

Deprecated: Use getSizeofSmallMutableArray# instead

Return the number of elements in the array. Deprecated, it is unsafe in the presence of shrinkSmallMutableArray# and resizeSmallMutableArray# operations on the same small mutable array.

getSizeofSmallMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> State# d -> (# State# d, Int# #) Source #

Return the number of elements in the array, correctly accounting for the effect of shrinkSmallMutableArray# and resizeSmallMutableArray#.

Since: ghc-prim-0.6.1

indexSmallArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)). SmallArray# a -> Int# -> (# a #) Source #

Read from specified index of immutable array. Result is packaged into an unboxed singleton; the result itself is not yet evaluated.

unsafeFreezeSmallArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> State# d -> (# State# d, SmallArray# a #) Source #

Make a mutable array immutable, without copying.

unsafeThawSmallArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. SmallArray# a -> State# d -> (# State# d, SmallMutableArray# d a #) Source #

Make an immutable array mutable, without copying.

copySmallArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. SmallArray# a -> Int# -> SmallMutableArray# d a -> Int# -> Int# -> State# d -> State# d Source #

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. Both arrays must fully contain the specified ranges, but this is not checked. The two arrays must not be the same array in different states, but this is not checked either.

Warning: this can fail with an unchecked exception.

copySmallMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# -> SmallMutableArray# d a -> Int# -> Int# -> State# d -> State# d Source #

Given a source array, an offset into the source array, a destination array, an offset into the destination array, and a number of elements to copy, copy the elements from the source array to the destination array. The source and destination arrays can refer to the same array. Both arrays must fully contain the specified ranges, but this is not checked. The regions are allowed to overlap, although this is only possible when the same array is provided as both the source and the destination.

Warning: this can fail with an unchecked exception.

cloneSmallArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)). SmallArray# a -> Int# -> Int# -> SmallArray# a Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

cloneSmallMutableArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# -> Int# -> State# d -> (# State# d, SmallMutableArray# d a #) Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

freezeSmallArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# -> Int# -> State# d -> (# State# d, SmallArray# a #) Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

thawSmallArray# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. SmallArray# a -> Int# -> Int# -> State# d -> (# State# d, SmallMutableArray# d a #) Source #

Given a source array, an offset into the source array, and a number of elements to copy, create a new array with the elements from the source array. The provided array must fully contain the specified range, but this is not checked.

Warning: this can fail with an unchecked exception.

casSmallArray# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). SmallMutableArray# d a -> Int# -> a -> a -> State# d -> (# State# d, Int#, a #) Source #

Unsafe, machine-level atomic compare and swap on an element within an array. See the documentation of casArray#.

Warning: this can fail with an unchecked exception.

Byte Arrays

A ByteArray# is a region of raw memory in the garbage-collected heap, which is not scanned for pointers. There are three sets of operations for accessing byte array contents: index for reading from immutable byte arrays, and read/write for mutable byte arrays. Each set contains operations for a range of useful primitive data types. Each operation takes an offset measured in terms of the size of the primitive type being read or written.

data ByteArray# :: UnliftedType Source #

A boxed, unlifted datatype representing a region of raw memory in the garbage-collected heap, which is not scanned for pointers during garbage collection.

It is created by freezing a MutableByteArray# with unsafeFreezeByteArray#. Freezing is essentially a no-op, as MutableByteArray# and ByteArray# share the same heap structure under the hood.

The immutable and mutable variants are commonly used for scenarios requiring high-performance data structures, like Text, Primitive Vector, Unboxed Array, and ShortByteString.

Another application of fundamental importance is Integer, which is backed by ByteArray#.

The representation on the heap of a Byte Array is:

+------------+-----------------+-----------------------+
|            |                 |                       |
|   HEADER   | SIZE (in bytes) |       PAYLOAD         |
|            |                 |                       |
+------------+-----------------+-----------------------+

To obtain a pointer to actual payload (e.g., for FFI purposes) use byteArrayContents# or mutableByteArrayContents#.

Alternatively, enabling the UnliftedFFITypes extension allows to mention ByteArray# and MutableByteArray# in FFI type signatures directly.

data MutableByteArray# a :: UnliftedType Source #

A mutable ByteAray#. It can be created in three ways:

Unpinned arrays can be moved around during garbage collection, so you must not store or pass pointers to these values if there is a chance for the garbage collector to kick in. That said, even unpinned arrays can be passed to unsafe FFI calls, because no garbage collection happens during these unsafe calls (see Guaranteed Call Safety in the GHC Manual). For safe FFI calls, byte arrays must be not only pinned, but also kept alive by means of the keepAlive# function for the duration of a call (that's because garbage collection cannot move a pinned array, but is free to scrap it altogether).

newByteArray# :: Int# -> State# d -> (# State# d, MutableByteArray# d #) Source #

Create a new mutable byte array of specified size (in bytes), in the specified state thread. The size of the memory underlying the array will be rounded up to the platform's word size.

newPinnedByteArray# :: Int# -> State# d -> (# State# d, MutableByteArray# d #) Source #

Like newByteArray# but GC guarantees not to move it.

newAlignedPinnedByteArray# :: Int# -> Int# -> State# d -> (# State# d, MutableByteArray# d #) Source #

Like newPinnedByteArray# but allow specifying an arbitrary alignment, which must be a power of two.

Warning: this can fail with an unchecked exception.

isMutableByteArrayPinned# :: MutableByteArray# d -> Int# Source #

Determine whether a MutableByteArray# is guaranteed not to move during GC.

isByteArrayPinned# :: ByteArray# -> Int# Source #

Determine whether a ByteArray# is guaranteed not to move.

isByteArrayWeaklyPinned# :: ByteArray# -> Int# Source #

Similar to isByteArrayPinned#. Weakly pinned byte arrays are allowed to be copied into compact regions by the user, potentially invalidating the results of earlier calls to byteArrayContents#.

See the section `Pinned Byte Arrays` in the user guide for more information.

This function also returns true for regular pinned bytearrays.

byteArrayContents# :: ByteArray# -> Addr# Source #

Intended for use with pinned arrays; otherwise very unsafe!

mutableByteArrayContents# :: MutableByteArray# d -> Addr# Source #

Intended for use with pinned arrays; otherwise very unsafe!

shrinkMutableByteArray# :: MutableByteArray# d -> Int# -> State# d -> State# d Source #

Shrink mutable byte array to new specified size (in bytes), in the specified state thread. The new size argument must be less than or equal to the current size as reported by getSizeofMutableByteArray#.

Assuming the non-profiling RTS, this primitive compiles to an O(1) operation in C--, modifying the array in-place. Backends bypassing C-- representation (such as JavaScript) might behave differently.

Warning: this can fail with an unchecked exception.

Since: ghc-prim-0.4.0.0

resizeMutableByteArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, MutableByteArray# d #) Source #

Resize mutable byte array to new specified size (in bytes), shrinking or growing it. The returned MutableByteArray# is either the original MutableByteArray# resized in-place or, if not possible, a newly allocated (unpinned) MutableByteArray# (with the original content copied over).

To avoid undefined behaviour, the original MutableByteArray# shall not be accessed anymore after a resizeMutableByteArray# has been performed. Moreover, no reference to the old one should be kept in order to allow garbage collection of the original MutableByteArray# in case a new MutableByteArray# had to be allocated.

Since: ghc-prim-0.4.0.0

unsafeFreezeByteArray# :: MutableByteArray# d -> State# d -> (# State# d, ByteArray# #) Source #

Make a mutable byte array immutable, without copying.

unsafeThawByteArray# :: ByteArray# -> State# d -> (# State# d, MutableByteArray# d #) Source #

Make an immutable byte array mutable, without copying.

Since: ghc-prim-0.12.0.0

sizeofByteArray# :: ByteArray# -> Int# Source #

Return the size of the array in bytes.

sizeofMutableByteArray# :: MutableByteArray# d -> Int# Source #

Deprecated: Use getSizeofMutableByteArray# instead

Return the size of the array in bytes. Deprecated, it is unsafe in the presence of shrinkMutableByteArray# and resizeMutableByteArray# operations on the same mutable byte array.

getSizeofMutableByteArray# :: MutableByteArray# d -> State# d -> (# State# d, Int# #) Source #

Return the number of elements in the array, correctly accounting for the effect of shrinkMutableByteArray# and resizeMutableByteArray#.

Since: ghc-prim-0.5.0.0

indexCharArray# :: ByteArray# -> Int# -> Char# Source #

Read an 8-bit character from immutable array; offset in bytes.

indexWideCharArray# :: ByteArray# -> Int# -> Char# Source #

Read a 32-bit character from immutable array; offset in 4-byte words.

indexIntArray# :: ByteArray# -> Int# -> Int# Source #

Read a word-sized integer from immutable array; offset in machine words.

indexWordArray# :: ByteArray# -> Int# -> Word# Source #

Read a word-sized unsigned integer from immutable array; offset in machine words.

indexAddrArray# :: ByteArray# -> Int# -> Addr# Source #

Read a machine address from immutable array; offset in machine words.

indexFloatArray# :: ByteArray# -> Int# -> Float# Source #

Read a single-precision floating-point value from immutable array; offset in 4-byte words.

indexDoubleArray# :: ByteArray# -> Int# -> Double# Source #

Read a double-precision floating-point value from immutable array; offset in 8-byte words.

indexStablePtrArray# :: ByteArray# -> Int# -> StablePtr# a Source #

Read a StablePtr# value from immutable array; offset in machine words.

indexInt8Array# :: ByteArray# -> Int# -> Int8# Source #

Read an 8-bit signed integer from immutable array; offset in bytes.

indexWord8Array# :: ByteArray# -> Int# -> Word8# Source #

Read an 8-bit unsigned integer from immutable array; offset in bytes.

indexInt16Array# :: ByteArray# -> Int# -> Int16# Source #

Read a 16-bit signed integer from immutable array; offset in 2-byte words.

indexWord16Array# :: ByteArray# -> Int# -> Word16# Source #

Read a 16-bit unsigned integer from immutable array; offset in 2-byte words.

indexInt32Array# :: ByteArray# -> Int# -> Int32# Source #

Read a 32-bit signed integer from immutable array; offset in 4-byte words.

indexWord32Array# :: ByteArray# -> Int# -> Word32# Source #

Read a 32-bit unsigned integer from immutable array; offset in 4-byte words.

indexInt64Array# :: ByteArray# -> Int# -> Int64# Source #

Read a 64-bit signed integer from immutable array; offset in 8-byte words.

indexWord64Array# :: ByteArray# -> Int# -> Word64# Source #

Read a 64-bit unsigned integer from immutable array; offset in 8-byte words.

indexWord8ArrayAsChar# :: ByteArray# -> Int# -> Char# Source #

Read an 8-bit character from immutable array; offset in bytes.

indexWord8ArrayAsWideChar# :: ByteArray# -> Int# -> Char# Source #

Read a 32-bit character from immutable array; offset in bytes.

indexWord8ArrayAsInt# :: ByteArray# -> Int# -> Int# Source #

Read a word-sized integer from immutable array; offset in bytes.

indexWord8ArrayAsWord# :: ByteArray# -> Int# -> Word# Source #

Read a word-sized unsigned integer from immutable array; offset in bytes.

indexWord8ArrayAsAddr# :: ByteArray# -> Int# -> Addr# Source #

Read a machine address from immutable array; offset in bytes.

indexWord8ArrayAsFloat# :: ByteArray# -> Int# -> Float# Source #

Read a single-precision floating-point value from immutable array; offset in bytes.

indexWord8ArrayAsDouble# :: ByteArray# -> Int# -> Double# Source #

Read a double-precision floating-point value from immutable array; offset in bytes.

indexWord8ArrayAsStablePtr# :: ByteArray# -> Int# -> StablePtr# a Source #

Read a StablePtr# value from immutable array; offset in bytes.

indexWord8ArrayAsInt16# :: ByteArray# -> Int# -> Int16# Source #

Read a 16-bit signed integer from immutable array; offset in bytes.

indexWord8ArrayAsWord16# :: ByteArray# -> Int# -> Word16# Source #

Read a 16-bit unsigned integer from immutable array; offset in bytes.

indexWord8ArrayAsInt32# :: ByteArray# -> Int# -> Int32# Source #

Read a 32-bit signed integer from immutable array; offset in bytes.

indexWord8ArrayAsWord32# :: ByteArray# -> Int# -> Word32# Source #

Read a 32-bit unsigned integer from immutable array; offset in bytes.

indexWord8ArrayAsInt64# :: ByteArray# -> Int# -> Int64# Source #

Read a 64-bit signed integer from immutable array; offset in bytes.

indexWord8ArrayAsWord64# :: ByteArray# -> Int# -> Word64# Source #

Read a 64-bit unsigned integer from immutable array; offset in bytes.

readCharArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #) Source #

Read an 8-bit character from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWideCharArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #) Source #

Read a 32-bit character from mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

readIntArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #) Source #

Read a word-sized integer from mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

readWordArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #) Source #

Read a word-sized unsigned integer from mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

readAddrArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Addr# #) Source #

Read a machine address from mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

readFloatArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Float# #) Source #

Read a single-precision floating-point value from mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

readDoubleArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Double# #) Source #

Read a double-precision floating-point value from mutable array; offset in 8-byte words.

Warning: this can fail with an unchecked exception.

readStablePtrArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, StablePtr# a #) Source #

Read a StablePtr# value from mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

readInt8Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int8# #) Source #

Read an 8-bit signed integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word8# #) Source #

Read an 8-bit unsigned integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readInt16Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int16# #) Source #

Read a 16-bit signed integer from mutable array; offset in 2-byte words.

Warning: this can fail with an unchecked exception.

readWord16Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word16# #) Source #

Read a 16-bit unsigned integer from mutable array; offset in 2-byte words.

Warning: this can fail with an unchecked exception.

readInt32Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int32# #) Source #

Read a 32-bit signed integer from mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

readWord32Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word32# #) Source #

Read a 32-bit unsigned integer from mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

readInt64Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int64# #) Source #

Read a 64-bit signed integer from mutable array; offset in 8-byte words.

Warning: this can fail with an unchecked exception.

readWord64Array# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word64# #) Source #

Read a 64-bit unsigned integer from mutable array; offset in 8-byte words.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsChar# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #) Source #

Read an 8-bit character from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsWideChar# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Char# #) Source #

Read a 32-bit character from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsInt# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #) Source #

Read a word-sized integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsWord# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #) Source #

Read a word-sized unsigned integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsAddr# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Addr# #) Source #

Read a machine address from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsFloat# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Float# #) Source #

Read a single-precision floating-point value from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsDouble# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Double# #) Source #

Read a double-precision floating-point value from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsStablePtr# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, StablePtr# a #) Source #

Read a StablePtr# value from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsInt16# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int16# #) Source #

Read a 16-bit signed integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsWord16# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word16# #) Source #

Read a 16-bit unsigned integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsInt32# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int32# #) Source #

Read a 32-bit signed integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsWord32# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word32# #) Source #

Read a 32-bit unsigned integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsInt64# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int64# #) Source #

Read a 64-bit signed integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8ArrayAsWord64# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Word64# #) Source #

Read a 64-bit unsigned integer from mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeCharArray# :: MutableByteArray# d -> Int# -> Char# -> State# d -> State# d Source #

Write an 8-bit character to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWideCharArray# :: MutableByteArray# d -> Int# -> Char# -> State# d -> State# d Source #

Write a 32-bit character to mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

writeIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> State# d Source #

Write a word-sized integer to mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

writeWordArray# :: MutableByteArray# d -> Int# -> Word# -> State# d -> State# d Source #

Write a word-sized unsigned integer to mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

writeAddrArray# :: MutableByteArray# d -> Int# -> Addr# -> State# d -> State# d Source #

Write a machine address to mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

writeFloatArray# :: MutableByteArray# d -> Int# -> Float# -> State# d -> State# d Source #

Write a single-precision floating-point value to mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

writeDoubleArray# :: MutableByteArray# d -> Int# -> Double# -> State# d -> State# d Source #

Write a double-precision floating-point value to mutable array; offset in 8-byte words.

Warning: this can fail with an unchecked exception.

writeStablePtrArray# :: MutableByteArray# d -> Int# -> StablePtr# a -> State# d -> State# d Source #

Write a StablePtr# value to mutable array; offset in machine words.

Warning: this can fail with an unchecked exception.

writeInt8Array# :: MutableByteArray# d -> Int# -> Int8# -> State# d -> State# d Source #

Write an 8-bit signed integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8Array# :: MutableByteArray# d -> Int# -> Word8# -> State# d -> State# d Source #

Write an 8-bit unsigned integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeInt16Array# :: MutableByteArray# d -> Int# -> Int16# -> State# d -> State# d Source #

Write a 16-bit signed integer to mutable array; offset in 2-byte words.

Warning: this can fail with an unchecked exception.

writeWord16Array# :: MutableByteArray# d -> Int# -> Word16# -> State# d -> State# d Source #

Write a 16-bit unsigned integer to mutable array; offset in 2-byte words.

Warning: this can fail with an unchecked exception.

writeInt32Array# :: MutableByteArray# d -> Int# -> Int32# -> State# d -> State# d Source #

Write a 32-bit signed integer to mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

writeWord32Array# :: MutableByteArray# d -> Int# -> Word32# -> State# d -> State# d Source #

Write a 32-bit unsigned integer to mutable array; offset in 4-byte words.

Warning: this can fail with an unchecked exception.

writeInt64Array# :: MutableByteArray# d -> Int# -> Int64# -> State# d -> State# d Source #

Write a 64-bit signed integer to mutable array; offset in 8-byte words.

Warning: this can fail with an unchecked exception.

writeWord64Array# :: MutableByteArray# d -> Int# -> Word64# -> State# d -> State# d Source #

Write a 64-bit unsigned integer to mutable array; offset in 8-byte words.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsChar# :: MutableByteArray# d -> Int# -> Char# -> State# d -> State# d Source #

Write an 8-bit character to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsWideChar# :: MutableByteArray# d -> Int# -> Char# -> State# d -> State# d Source #

Write a 32-bit character to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsInt# :: MutableByteArray# d -> Int# -> Int# -> State# d -> State# d Source #

Write a word-sized integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsWord# :: MutableByteArray# d -> Int# -> Word# -> State# d -> State# d Source #

Write a word-sized unsigned integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsAddr# :: MutableByteArray# d -> Int# -> Addr# -> State# d -> State# d Source #

Write a machine address to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsFloat# :: MutableByteArray# d -> Int# -> Float# -> State# d -> State# d Source #

Write a single-precision floating-point value to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsDouble# :: MutableByteArray# d -> Int# -> Double# -> State# d -> State# d Source #

Write a double-precision floating-point value to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsStablePtr# :: MutableByteArray# d -> Int# -> StablePtr# a -> State# d -> State# d Source #

Write a StablePtr# value to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsInt16# :: MutableByteArray# d -> Int# -> Int16# -> State# d -> State# d Source #

Write a 16-bit signed integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsWord16# :: MutableByteArray# d -> Int# -> Word16# -> State# d -> State# d Source #

Write a 16-bit unsigned integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsInt32# :: MutableByteArray# d -> Int# -> Int32# -> State# d -> State# d Source #

Write a 32-bit signed integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsWord32# :: MutableByteArray# d -> Int# -> Word32# -> State# d -> State# d Source #

Write a 32-bit unsigned integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsInt64# :: MutableByteArray# d -> Int# -> Int64# -> State# d -> State# d Source #

Write a 64-bit signed integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8ArrayAsWord64# :: MutableByteArray# d -> Int# -> Word64# -> State# d -> State# d Source #

Write a 64-bit unsigned integer to mutable array; offset in bytes.

Warning: this can fail with an unchecked exception.

compareByteArrays# :: ByteArray# -> Int# -> ByteArray# -> Int# -> Int# -> Int# Source #

compareByteArrays# src1 src1_ofs src2 src2_ofs n compares n bytes starting at offset src1_ofs in the first ByteArray# src1 to the range of n bytes (i.e. same length) starting at offset src2_ofs of the second ByteArray# src2. Both arrays must fully contain the specified ranges, but this is not checked. Returns an Int# less than, equal to, or greater than zero if the range is found, respectively, to be byte-wise lexicographically less than, to match, or be greater than the second range.

Since: ghc-prim-0.5.2.0

copyByteArray# :: ByteArray# -> Int# -> MutableByteArray# d -> Int# -> Int# -> State# d -> State# d Source #

copyByteArray# src src_ofs dst dst_ofs len copies the range starting at offset src_ofs of length len from the ByteArray# src to the MutableByteArray# dst starting at offset dst_ofs. Both arrays must fully contain the specified ranges, but this is not checked. The two arrays must not be the same array in different states, but this is not checked either.

Warning: this can fail with an unchecked exception.

copyMutableByteArray# :: MutableByteArray# d -> Int# -> MutableByteArray# d -> Int# -> Int# -> State# d -> State# d Source #

copyMutableByteArray# src src_ofs dst dst_ofs len copies the range starting at offset src_ofs of length len from the MutableByteArray# src to the MutableByteArray# dst starting at offset dst_ofs. Both arrays must fully contain the specified ranges, but this is not checked. The regions are allowed to overlap, although this is only possible when the same array is provided as both the source and the destination.

Warning: this can fail with an unchecked exception.

copyMutableByteArrayNonOverlapping# :: MutableByteArray# d -> Int# -> MutableByteArray# d -> Int# -> Int# -> State# d -> State# d Source #

copyMutableByteArrayNonOverlapping# src src_ofs dst dst_ofs len copies the range starting at offset src_ofs of length len from the MutableByteArray# src to the MutableByteArray# dst starting at offset dst_ofs. Both arrays must fully contain the specified ranges, but this is not checked. The regions are not allowed to overlap, but this is also not checked.

Warning: this can fail with an unchecked exception.

Since: ghc-prim-0.11.0

copyByteArrayToAddr# :: ByteArray# -> Int# -> Addr# -> Int# -> State# d -> State# d Source #

Copy a range of the ByteArray# to the memory range starting at the Addr#. The ByteArray# and the memory region at Addr# must fully contain the specified ranges, but this is not checked. The Addr# must not point into the ByteArray# (e.g. if the ByteArray# were pinned), but this is not checked either.

Warning: this can fail with an unchecked exception.

copyMutableByteArrayToAddr# :: MutableByteArray# d -> Int# -> Addr# -> Int# -> State# d -> State# d Source #

Copy a range of the MutableByteArray# to the memory range starting at the Addr#. The MutableByteArray# and the memory region at Addr# must fully contain the specified ranges, but this is not checked. The Addr# must not point into the MutableByteArray# (e.g. if the MutableByteArray# were pinned), but this is not checked either.

Warning: this can fail with an unchecked exception.

copyAddrToByteArray# :: Addr# -> MutableByteArray# d -> Int# -> Int# -> State# d -> State# d Source #

Copy a memory range starting at the Addr# to the specified range in the MutableByteArray#. The memory region at Addr# and the ByteArray# must fully contain the specified ranges, but this is not checked. The Addr# must not point into the MutableByteArray# (e.g. if the MutableByteArray# were pinned), but this is not checked either.

Warning: this can fail with an unchecked exception.

copyAddrToAddr# :: Addr# -> Addr# -> Int# -> State# RealWorld -> State# RealWorld Source #

copyAddrToAddr# src dest len copies len bytes from src to dest. These two memory ranges are allowed to overlap.

Analogous to the standard C function memmove, but with a different argument order.

Warning: this can fail with an unchecked exception.

Since: ghc-prim-0.11.0

copyAddrToAddrNonOverlapping# :: Addr# -> Addr# -> Int# -> State# RealWorld -> State# RealWorld Source #

copyAddrToAddrNonOverlapping# src dest len copies len bytes from src to dest. As the name suggests, these two memory ranges must not overlap, although this pre-condition is not checked.

Analogous to the standard C function memcpy, but with a different argument order.

Warning: this can fail with an unchecked exception.

Since: ghc-prim-0.11.0

setByteArray# :: MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d Source #

setByteArray# ba off len c sets the byte range [off, off+len) of the MutableByteArray# to the byte c.

Warning: this can fail with an unchecked exception.

setAddrRange# :: Addr# -> Int# -> Int# -> State# RealWorld -> State# RealWorld Source #

setAddrRange# dest len c sets all of the bytes in [dest, dest+len) to the value c.

Analogous to the standard C function memset, but with a different argument order.

Warning: this can fail with an unchecked exception.

Since: ghc-prim-0.11.0

atomicReadIntArray# :: MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array and an offset in machine words, read an element. The index is assumed to be in bounds. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicWriteIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> State# d Source #

Given an array and an offset in machine words, write an element. The index is assumed to be in bounds. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

casIntArray# :: MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array, an offset in machine words, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

casInt8Array# :: MutableByteArray# d -> Int# -> Int8# -> Int8# -> State# d -> (# State# d, Int8# #) Source #

Given an array, an offset in bytes, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

casInt16Array# :: MutableByteArray# d -> Int# -> Int16# -> Int16# -> State# d -> (# State# d, Int16# #) Source #

Given an array, an offset in 16 bit units, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

casInt32Array# :: MutableByteArray# d -> Int# -> Int32# -> Int32# -> State# d -> (# State# d, Int32# #) Source #

Given an array, an offset in 32 bit units, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

casInt64Array# :: MutableByteArray# d -> Int# -> Int64# -> Int64# -> State# d -> (# State# d, Int64# #) Source #

Given an array, an offset in 64 bit units, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchAddIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array, and offset in machine words, and a value to add, atomically add the value to the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchSubIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array, and offset in machine words, and a value to subtract, atomically subtract the value from the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchAndIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array, and offset in machine words, and a value to AND, atomically AND the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchNandIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array, and offset in machine words, and a value to NAND, atomically NAND the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchOrIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array, and offset in machine words, and a value to OR, atomically OR the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchXorIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #) Source #

Given an array, and offset in machine words, and a value to XOR, atomically XOR the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

Addr#

 

data Addr# :: TYPE 'AddrRep Source #

An arbitrary machine address assumed to point outside the garbage-collected heap.

nullAddr# :: Addr# Source #

The null address.

minusAddr# :: Addr# -> Addr# -> Int# Source #

Result is meaningless if two Addr#s are so far apart that their difference doesn't fit in an Int#.

remAddr# :: Addr# -> Int# -> Int# Source #

Return the remainder when the Addr# arg, treated like an Int#, is divided by the Int# arg.

addr2Int# :: Addr# -> Int# Source #

Coerce directly from address to int. Users are discouraged from using this operation as it makes little sense on platforms with tagged pointers.

int2Addr# :: Int# -> Addr# Source #

Coerce directly from int to address. Users are discouraged from using this operation as it makes little sense on platforms with tagged pointers.

indexCharOffAddr# :: Addr# -> Int# -> Char# Source #

Read an 8-bit character from immutable address; offset in bytes.

indexWideCharOffAddr# :: Addr# -> Int# -> Char# Source #

Read a 32-bit character from immutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexIntOffAddr# :: Addr# -> Int# -> Int# Source #

Read a word-sized integer from immutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexWordOffAddr# :: Addr# -> Int# -> Word# Source #

Read a word-sized unsigned integer from immutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexAddrOffAddr# :: Addr# -> Int# -> Addr# Source #

Read a machine address from immutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexFloatOffAddr# :: Addr# -> Int# -> Float# Source #

Read a single-precision floating-point value from immutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexDoubleOffAddr# :: Addr# -> Int# -> Double# Source #

Read a double-precision floating-point value from immutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexStablePtrOffAddr# :: Addr# -> Int# -> StablePtr# a Source #

Read a StablePtr# value from immutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexInt8OffAddr# :: Addr# -> Int# -> Int8# Source #

Read an 8-bit signed integer from immutable address; offset in bytes.

indexWord8OffAddr# :: Addr# -> Int# -> Word8# Source #

Read an 8-bit unsigned integer from immutable address; offset in bytes.

indexInt16OffAddr# :: Addr# -> Int# -> Int16# Source #

Read a 16-bit signed integer from immutable address; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexWord16OffAddr# :: Addr# -> Int# -> Word16# Source #

Read a 16-bit unsigned integer from immutable address; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexInt32OffAddr# :: Addr# -> Int# -> Int32# Source #

Read a 32-bit signed integer from immutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexWord32OffAddr# :: Addr# -> Int# -> Word32# Source #

Read a 32-bit unsigned integer from immutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexInt64OffAddr# :: Addr# -> Int# -> Int64# Source #

Read a 64-bit signed integer from immutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexWord64OffAddr# :: Addr# -> Int# -> Word64# Source #

Read a 64-bit unsigned integer from immutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

indexWord8OffAddrAsChar# :: Addr# -> Int# -> Char# Source #

Read an 8-bit character from immutable address; offset in bytes.

indexWord8OffAddrAsWideChar# :: Addr# -> Int# -> Char# Source #

Read a 32-bit character from immutable address; offset in bytes.

indexWord8OffAddrAsInt# :: Addr# -> Int# -> Int# Source #

Read a word-sized integer from immutable address; offset in bytes.

indexWord8OffAddrAsWord# :: Addr# -> Int# -> Word# Source #

Read a word-sized unsigned integer from immutable address; offset in bytes.

indexWord8OffAddrAsAddr# :: Addr# -> Int# -> Addr# Source #

Read a machine address from immutable address; offset in bytes.

indexWord8OffAddrAsFloat# :: Addr# -> Int# -> Float# Source #

Read a single-precision floating-point value from immutable address; offset in bytes.

indexWord8OffAddrAsDouble# :: Addr# -> Int# -> Double# Source #

Read a double-precision floating-point value from immutable address; offset in bytes.

indexWord8OffAddrAsStablePtr# :: Addr# -> Int# -> StablePtr# a Source #

Read a StablePtr# value from immutable address; offset in bytes.

indexWord8OffAddrAsInt16# :: Addr# -> Int# -> Int16# Source #

Read a 16-bit signed integer from immutable address; offset in bytes.

indexWord8OffAddrAsWord16# :: Addr# -> Int# -> Word16# Source #

Read a 16-bit unsigned integer from immutable address; offset in bytes.

indexWord8OffAddrAsInt32# :: Addr# -> Int# -> Int32# Source #

Read a 32-bit signed integer from immutable address; offset in bytes.

indexWord8OffAddrAsWord32# :: Addr# -> Int# -> Word32# Source #

Read a 32-bit unsigned integer from immutable address; offset in bytes.

indexWord8OffAddrAsInt64# :: Addr# -> Int# -> Int64# Source #

Read a 64-bit signed integer from immutable address; offset in bytes.

indexWord8OffAddrAsWord64# :: Addr# -> Int# -> Word64# Source #

Read a 64-bit unsigned integer from immutable address; offset in bytes.

readCharOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Char# #) Source #

Read an 8-bit character from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWideCharOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Char# #) Source #

Read a 32-bit character from mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readIntOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Int# #) Source #

Read a word-sized integer from mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readWordOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Word# #) Source #

Read a word-sized unsigned integer from mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readAddrOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Addr# #) Source #

Read a machine address from mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readFloatOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Float# #) Source #

Read a single-precision floating-point value from mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readDoubleOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Double# #) Source #

Read a double-precision floating-point value from mutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readStablePtrOffAddr# :: Addr# -> Int# -> State# d -> (# State# d, StablePtr# a #) Source #

Read a StablePtr# value from mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readInt8OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Int8# #) Source #

Read an 8-bit signed integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Word8# #) Source #

Read an 8-bit unsigned integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readInt16OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Int16# #) Source #

Read a 16-bit signed integer from mutable address; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readWord16OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Word16# #) Source #

Read a 16-bit unsigned integer from mutable address; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readInt32OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Int32# #) Source #

Read a 32-bit signed integer from mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readWord32OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Word32# #) Source #

Read a 32-bit unsigned integer from mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readInt64OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Int64# #) Source #

Read a 64-bit signed integer from mutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readWord64OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, Word64# #) Source #

Read a 64-bit unsigned integer from mutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsChar# :: Addr# -> Int# -> State# d -> (# State# d, Char# #) Source #

Read an 8-bit character from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsWideChar# :: Addr# -> Int# -> State# d -> (# State# d, Char# #) Source #

Read a 32-bit character from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsInt# :: Addr# -> Int# -> State# d -> (# State# d, Int# #) Source #

Read a word-sized integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsWord# :: Addr# -> Int# -> State# d -> (# State# d, Word# #) Source #

Read a word-sized unsigned integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsAddr# :: Addr# -> Int# -> State# d -> (# State# d, Addr# #) Source #

Read a machine address from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsFloat# :: Addr# -> Int# -> State# d -> (# State# d, Float# #) Source #

Read a single-precision floating-point value from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsDouble# :: Addr# -> Int# -> State# d -> (# State# d, Double# #) Source #

Read a double-precision floating-point value from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsStablePtr# :: Addr# -> Int# -> State# d -> (# State# d, StablePtr# a #) Source #

Read a StablePtr# value from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsInt16# :: Addr# -> Int# -> State# d -> (# State# d, Int16# #) Source #

Read a 16-bit signed integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsWord16# :: Addr# -> Int# -> State# d -> (# State# d, Word16# #) Source #

Read a 16-bit unsigned integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsInt32# :: Addr# -> Int# -> State# d -> (# State# d, Int32# #) Source #

Read a 32-bit signed integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsWord32# :: Addr# -> Int# -> State# d -> (# State# d, Word32# #) Source #

Read a 32-bit unsigned integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsInt64# :: Addr# -> Int# -> State# d -> (# State# d, Int64# #) Source #

Read a 64-bit signed integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

readWord8OffAddrAsWord64# :: Addr# -> Int# -> State# d -> (# State# d, Word64# #) Source #

Read a 64-bit unsigned integer from mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeCharOffAddr# :: Addr# -> Int# -> Char# -> State# d -> State# d Source #

Write an 8-bit character to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWideCharOffAddr# :: Addr# -> Int# -> Char# -> State# d -> State# d Source #

Write a 32-bit character to mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeIntOffAddr# :: Addr# -> Int# -> Int# -> State# d -> State# d Source #

Write a word-sized integer to mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeWordOffAddr# :: Addr# -> Int# -> Word# -> State# d -> State# d Source #

Write a word-sized unsigned integer to mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeAddrOffAddr# :: Addr# -> Int# -> Addr# -> State# d -> State# d Source #

Write a machine address to mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeFloatOffAddr# :: Addr# -> Int# -> Float# -> State# d -> State# d Source #

Write a single-precision floating-point value to mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeDoubleOffAddr# :: Addr# -> Int# -> Double# -> State# d -> State# d Source #

Write a double-precision floating-point value to mutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeStablePtrOffAddr# :: Addr# -> Int# -> StablePtr# a -> State# d -> State# d Source #

Write a StablePtr# value to mutable address; offset in machine words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeInt8OffAddr# :: Addr# -> Int# -> Int8# -> State# d -> State# d Source #

Write an 8-bit signed integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddr# :: Addr# -> Int# -> Word8# -> State# d -> State# d Source #

Write an 8-bit unsigned integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeInt16OffAddr# :: Addr# -> Int# -> Int16# -> State# d -> State# d Source #

Write a 16-bit signed integer to mutable address; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeWord16OffAddr# :: Addr# -> Int# -> Word16# -> State# d -> State# d Source #

Write a 16-bit unsigned integer to mutable address; offset in 2-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeInt32OffAddr# :: Addr# -> Int# -> Int32# -> State# d -> State# d Source #

Write a 32-bit signed integer to mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeWord32OffAddr# :: Addr# -> Int# -> Word32# -> State# d -> State# d Source #

Write a 32-bit unsigned integer to mutable address; offset in 4-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeInt64OffAddr# :: Addr# -> Int# -> Int64# -> State# d -> State# d Source #

Write a 64-bit signed integer to mutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeWord64OffAddr# :: Addr# -> Int# -> Word64# -> State# d -> State# d Source #

Write a 64-bit unsigned integer to mutable address; offset in 8-byte words.

On some platforms, the access may fail for an insufficiently aligned Addr#.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsChar# :: Addr# -> Int# -> Char# -> State# d -> State# d Source #

Write an 8-bit character to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsWideChar# :: Addr# -> Int# -> Char# -> State# d -> State# d Source #

Write a 32-bit character to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsInt# :: Addr# -> Int# -> Int# -> State# d -> State# d Source #

Write a word-sized integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsWord# :: Addr# -> Int# -> Word# -> State# d -> State# d Source #

Write a word-sized unsigned integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsAddr# :: Addr# -> Int# -> Addr# -> State# d -> State# d Source #

Write a machine address to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsFloat# :: Addr# -> Int# -> Float# -> State# d -> State# d Source #

Write a single-precision floating-point value to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsDouble# :: Addr# -> Int# -> Double# -> State# d -> State# d Source #

Write a double-precision floating-point value to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsStablePtr# :: Addr# -> Int# -> StablePtr# a -> State# d -> State# d Source #

Write a StablePtr# value to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsInt16# :: Addr# -> Int# -> Int16# -> State# d -> State# d Source #

Write a 16-bit signed integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsWord16# :: Addr# -> Int# -> Word16# -> State# d -> State# d Source #

Write a 16-bit unsigned integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsInt32# :: Addr# -> Int# -> Int32# -> State# d -> State# d Source #

Write a 32-bit signed integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsWord32# :: Addr# -> Int# -> Word32# -> State# d -> State# d Source #

Write a 32-bit unsigned integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsInt64# :: Addr# -> Int# -> Int64# -> State# d -> State# d Source #

Write a 64-bit signed integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

writeWord8OffAddrAsWord64# :: Addr# -> Int# -> Word64# -> State# d -> State# d Source #

Write a 64-bit unsigned integer to mutable address; offset in bytes.

Warning: this can fail with an unchecked exception.

atomicExchangeAddrAddr# :: Addr# -> Addr# -> State# d -> (# State# d, Addr# #) Source #

The atomic exchange operation. Atomically exchanges the value at the first address with the Addr# given as second argument. Implies a read barrier.

Warning: this can fail with an unchecked exception.

atomicExchangeWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #) Source #

The atomic exchange operation. Atomically exchanges the value at the address with the given value. Returns the old value. Implies a read barrier.

Warning: this can fail with an unchecked exception.

atomicCasAddrAddr# :: Addr# -> Addr# -> Addr# -> State# d -> (# State# d, Addr# #) Source #

Compare and swap on a word-sized memory location.

Use as: s -> atomicCasAddrAddr# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicCasWordAddr# :: Addr# -> Word# -> Word# -> State# d -> (# State# d, Word# #) Source #

Compare and swap on a word-sized and aligned memory location.

Use as: s -> atomicCasWordAddr# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicCasWord8Addr# :: Addr# -> Word8# -> Word8# -> State# d -> (# State# d, Word8# #) Source #

Compare and swap on a 8 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr8# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicCasWord16Addr# :: Addr# -> Word16# -> Word16# -> State# d -> (# State# d, Word16# #) Source #

Compare and swap on a 16 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr16# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicCasWord32Addr# :: Addr# -> Word32# -> Word32# -> State# d -> (# State# d, Word32# #) Source #

Compare and swap on a 32 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr32# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicCasWord64Addr# :: Addr# -> Word64# -> Word64# -> State# d -> (# State# d, Word64# #) Source #

Compare and swap on a 64 bit-sized and aligned memory location.

Use as: s -> atomicCasWordAddr64# location expected desired s

This version always returns the old value read. This follows the normal protocol for CAS operations (and matches the underlying instruction on most architectures).

Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchAddWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #) Source #

Given an address, and a value to add, atomically add the value to the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchSubWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #) Source #

Given an address, and a value to subtract, atomically subtract the value from the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchAndWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #) Source #

Given an address, and a value to AND, atomically AND the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchNandWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #) Source #

Given an address, and a value to NAND, atomically NAND the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchOrWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #) Source #

Given an address, and a value to OR, atomically OR the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

fetchXorWordAddr# :: Addr# -> Word# -> State# d -> (# State# d, Word# #) Source #

Given an address, and a value to XOR, atomically XOR the value into the element. Returns the value of the element before the operation. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicReadWordAddr# :: Addr# -> State# d -> (# State# d, Word# #) Source #

Given an address, read a machine word. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

atomicWriteWordAddr# :: Addr# -> Word# -> State# d -> State# d Source #

Given an address, write a machine word. Implies a full memory barrier.

Warning: this can fail with an unchecked exception.

Mutable variables

Operations on MutVar#s.

data MutVar# a (b :: TYPE ('BoxedRep l)) :: UnliftedType Source #

A MutVar# behaves like a single-element mutable array.

newMutVar# :: forall {l :: Levity} (a :: TYPE ('BoxedRep l)) d. a -> State# d -> (# State# d, MutVar# d a #) Source #

Create MutVar# with specified initial value in specified state thread.

readMutVar# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutVar# d a -> State# d -> (# State# d, a #) Source #

Read contents of MutVar#. Result is not yet evaluated.

writeMutVar# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutVar# d a -> a -> State# d -> State# d Source #

Write contents of MutVar#.

atomicSwapMutVar# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutVar# d a -> a -> State# d -> (# State# d, a #) Source #

Atomically exchange the value of a MutVar#.

atomicModifyMutVar2# :: MutVar# d a -> (a -> c) -> State# d -> (# State# d, a, c #) Source #

Modify the contents of a MutVar#, returning the previous contents x :: a and the result of applying the given function to the previous contents f x :: c.

The data type c (not a newtype!) must be a record whose first field is of lifted type a :: Type and is not unpacked. For example, product types c ~ Solo a or c ~ (a, b) work well. If the record type is both monomorphic and strict in its first field, it's recommended to mark the latter {-# NOUNPACK #-} explicitly.

Under the hood atomicModifyMutVar2# atomically replaces a pointer to an old x :: a with a pointer to a selector thunk fst r, where fst is a selector for the first field of the record and r is a function application thunk r = f x.

atomicModifyIORef2Native from atomic-modify-general package makes an effort to reflect restrictions on c faithfully, providing a well-typed high-level wrapper.

atomicModifyMutVar_# :: MutVar# d a -> (a -> a) -> State# d -> (# State# d, a, a #) Source #

Modify the contents of a MutVar#, returning the previous contents and the result of applying the given function to the previous contents.

casMutVar# :: forall {l :: Levity} d (a :: TYPE ('BoxedRep l)). MutVar# d a -> a -> a -> State# d -> (# State# d, Int#, a #) Source #

Compare-and-swap: perform a pointer equality test between the first value passed to this function and the value stored inside the Mu