{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
module GHC.Num.WordArray where
import GHC.Prim
import GHC.Magic
import GHC.Types
import GHC.Num.Primitives
#include "MachDeps.h"
#include "WordSize.h"
default ()
type WordArray#        = ByteArray#
type MutableWordArray# = MutableByteArray#
data WordArray          = WordArray WordArray#
data MutableWordArray s = MutableWordArray (MutableWordArray# s)
wordsToBytes# :: Int# -> Int#
wordsToBytes# :: Int# -> Int#
wordsToBytes# Int#
i = Int#
i Int# -> Int# -> Int#
`uncheckedIShiftL#` WORD_SIZE_BYTES_SHIFT#
bytesToWords# :: Int# -> Int#
bytesToWords# :: Int# -> Int#
bytesToWords# Int#
i = Int#
i Int# -> Int# -> Int#
`uncheckedIShiftRL#` WORD_SIZE_BYTES_SHIFT#
withNewWordArray#
   :: Int#  
   -> (MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld)
   -> WordArray#
withNewWordArray# :: Int#
-> (MutableWordArray# RealWorld
    -> State# RealWorld -> State# RealWorld)
-> WordArray#
withNewWordArray# Int#
sz MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
act = case (State# RealWorld -> (# State# RealWorld, WordArray# #))
-> (# State# RealWorld, WordArray# #)
forall o. (State# RealWorld -> o) -> o
runRW# State# RealWorld -> (# State# RealWorld, WordArray# #)
io of (# State# RealWorld
_, WordArray#
a #) -> WordArray#
a
   where
      io :: State# RealWorld -> (# State# RealWorld, WordArray# #)
io State# RealWorld
s =
         case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableWordArray# RealWorld #)
forall s. Int# -> State# s -> (# State# s, MutableWordArray# s #)
newWordArray# Int#
sz State# RealWorld
s of { (# State# RealWorld
s, MutableWordArray# RealWorld
mwa #) ->
         case MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
act MutableWordArray# RealWorld
mwa State# RealWorld
s          of { State# RealWorld
s ->
         MutableWordArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, WordArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, WordArray# #)
unsafeFreezeByteArray# MutableWordArray# RealWorld
mwa State# RealWorld
s
         }}
withNewWordArray2#
   :: Int# 
   -> Int# 
   -> (MutableWordArray# RealWorld
      -> MutableWordArray# RealWorld
      -> State# RealWorld
      -> State# RealWorld)
   -> (# WordArray#, WordArray# #)
withNewWordArray2# :: Int#
-> Int#
-> (MutableWordArray# RealWorld
    -> MutableWordArray# RealWorld
    -> State# RealWorld
    -> State# RealWorld)
-> (# WordArray#, WordArray# #)
withNewWordArray2# Int#
sz1 Int#
sz2 MutableWordArray# RealWorld
-> MutableWordArray# RealWorld
-> State# RealWorld
-> State# RealWorld
act = case (State# RealWorld
 -> (# State# RealWorld, (# WordArray#, WordArray# #) #))
-> (# State# RealWorld, (# WordArray#, WordArray# #) #)
forall o. (State# RealWorld -> o) -> o
runRW# State# RealWorld
-> (# State# RealWorld, (# WordArray#, WordArray# #) #)
io of (# State# RealWorld
_, (# WordArray#, WordArray# #)
a #) -> (# WordArray#, WordArray# #)
a
   where
      io :: State# RealWorld
-> (# State# RealWorld, (# WordArray#, WordArray# #) #)
io State# RealWorld
s =
         case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableWordArray# RealWorld #)
forall s. Int# -> State# s -> (# State# s, MutableWordArray# s #)
newWordArray# Int#
sz1 State# RealWorld
s of { (# State# RealWorld
s, MutableWordArray# RealWorld
mwa1 #) ->
         case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableWordArray# RealWorld #)
forall s. Int# -> State# s -> (# State# s, MutableWordArray# s #)
newWordArray# Int#
sz2 State# RealWorld
s of { (# State# RealWorld
s, MutableWordArray# RealWorld
mwa2 #) ->
         case MutableWordArray# RealWorld
-> MutableWordArray# RealWorld
-> State# RealWorld
-> State# RealWorld
act MutableWordArray# RealWorld
mwa1 MutableWordArray# RealWorld
mwa2 State# RealWorld
s     of { State# RealWorld
s ->
         case MutableWordArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, WordArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, WordArray# #)
unsafeFreezeByteArray# MutableWordArray# RealWorld
mwa1 State# RealWorld
s of { (# State# RealWorld
s, WordArray#
wa1 #) ->
         case MutableWordArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, WordArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, WordArray# #)
unsafeFreezeByteArray# MutableWordArray# RealWorld
mwa2 State# RealWorld
s of { (# State# RealWorld
s, WordArray#
wa2 #) ->
            (# State# RealWorld
s, (# WordArray#
wa1, WordArray#
wa2 #) #)
         }}}}}
newWordArray# :: Int# -> State# s -> (# State# s, MutableWordArray# s #)
newWordArray# :: forall s. Int# -> State# s -> (# State# s, MutableWordArray# s #)
newWordArray# Int#
sz State# s
s = Int# -> State# s -> (# State# s, MutableByteArray# s #)
forall s. Int# -> State# s -> (# State# s, MutableWordArray# s #)
newByteArray# (Int# -> Int#
wordsToBytes# Int#
sz) State# s
s
withNewWordArrayTrimmed#
   :: Int#  
   -> (MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld)
   -> WordArray#
withNewWordArrayTrimmed# :: Int#
-> (MutableWordArray# RealWorld
    -> State# RealWorld -> State# RealWorld)
-> WordArray#
withNewWordArrayTrimmed# Int#
sz MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
act = Int#
-> (MutableWordArray# RealWorld
    -> State# RealWorld -> State# RealWorld)
-> WordArray#
withNewWordArray# Int#
sz \MutableWordArray# RealWorld
mwa State# RealWorld
s ->
   case MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
act MutableWordArray# RealWorld
mwa State# RealWorld
s of
      State# RealWorld
s' -> MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
forall s. MutableByteArray# s -> State# s -> State# s
mwaTrimZeroes# MutableWordArray# RealWorld
mwa State# RealWorld
s'
withNewWordArray2Trimmed#
   :: Int#  
   -> Int#  
   -> (MutableWordArray# RealWorld
      -> MutableWordArray# RealWorld
      -> State# RealWorld
      -> State# RealWorld)
   -> (# WordArray#, WordArray# #)
withNewWordArray2Trimmed# :: Int#
-> Int#
-> (MutableWordArray# RealWorld
    -> MutableWordArray# RealWorld
    -> State# RealWorld
    -> State# RealWorld)
-> (# WordArray#, WordArray# #)
withNewWordArray2Trimmed# Int#
sz1 Int#
sz2 MutableWordArray# RealWorld
-> MutableWordArray# RealWorld
-> State# RealWorld
-> State# RealWorld
act = Int#
-> Int#
-> (MutableWordArray# RealWorld
    -> MutableWordArray# RealWorld
    -> State# RealWorld
    -> State# RealWorld)
-> (# WordArray#, WordArray# #)
withNewWordArray2# Int#
sz1 Int#
sz2 \MutableWordArray# RealWorld
mwa1 MutableWordArray# RealWorld
mwa2 State# RealWorld
s ->
   case MutableWordArray# RealWorld
-> MutableWordArray# RealWorld
-> State# RealWorld
-> State# RealWorld
act MutableWordArray# RealWorld
mwa1 MutableWordArray# RealWorld
mwa2 State# RealWorld
s of
      State# RealWorld
s' -> case MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
forall s. MutableByteArray# s -> State# s -> State# s
mwaTrimZeroes# MutableWordArray# RealWorld
mwa1 State# RealWorld
s' of
         State# RealWorld
s'' -> MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
forall s. MutableByteArray# s -> State# s -> State# s
mwaTrimZeroes# MutableWordArray# RealWorld
mwa2 State# RealWorld
s''
withNewWordArrayTrimmedMaybe#
   :: Int#  
   -> (MutableWordArray# RealWorld -> State# RealWorld -> (# State# RealWorld, Bool# #))
   -> (# (# #) | WordArray# #)
withNewWordArrayTrimmedMaybe# :: Int#
-> (MutableWordArray# RealWorld
    -> State# RealWorld -> (# State# RealWorld, Int# #))
-> (# (# #) | WordArray# #)
withNewWordArrayTrimmedMaybe# Int#
sz MutableWordArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, Int# #)
act = case (State# RealWorld
 -> (# State# RealWorld, (# (# #) | WordArray# #) #))
-> (# State# RealWorld, (# (# #) | WordArray# #) #)
forall o. (State# RealWorld -> o) -> o
runRW# State# RealWorld
-> (# State# RealWorld, (# (# #) | WordArray# #) #)
io of (# State# RealWorld
_, (# (# #) | WordArray# #)
a #) -> (# (# #) | WordArray# #)
a
   where
      io :: State# RealWorld
-> (# State# RealWorld, (# (# #) | WordArray# #) #)
io State# RealWorld
s =
         case Int#
-> State# RealWorld
-> (# State# RealWorld, MutableWordArray# RealWorld #)
forall s. Int# -> State# s -> (# State# s, MutableWordArray# s #)
newWordArray# Int#
sz State# RealWorld
s of
            (# State# RealWorld
s, MutableWordArray# RealWorld
mwa #) -> case MutableWordArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, Int# #)
act MutableWordArray# RealWorld
mwa State# RealWorld
s of
               (# State# RealWorld
s, Int#
0# #) -> (# State# RealWorld
s, (# (# #) | #) #)
               (# State# RealWorld
s, Int#
_  #) -> case MutableWordArray# RealWorld -> State# RealWorld -> State# RealWorld
forall s. MutableByteArray# s -> State# s -> State# s
mwaTrimZeroes# MutableWordArray# RealWorld
mwa State# RealWorld
s of
                  State# RealWorld
s -> case MutableWordArray# RealWorld
-> State# RealWorld -> (# State# RealWorld, WordArray# #)
forall d.
MutableByteArray# d -> State# d -> (# State# d, WordArray# #)
unsafeFreezeByteArray# MutableWordArray# RealWorld
mwa State# RealWorld
s of
                     (# State# RealWorld
s, WordArray#
ba #) -> (# State# RealWorld
s, (# | WordArray#
ba #) #)
wordArrayFromWord2# :: Word# -> Word# -> WordArray#
wordArrayFromWord2# :: Word# -> Word# -> WordArray#
wordArrayFromWord2# Word#
h Word#
l   =
   Int#
-> (MutableWordArray# RealWorld
    -> State# RealWorld -> State# RealWorld)
-> WordArray#
withNewWordArray# Int#
2# \MutableWordArray# RealWorld
mwa State# RealWorld
s ->
      case MutableWordArray# RealWorld
-> Int# -> Word# -> State# RealWorld -> State# RealWorld
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# RealWorld
mwa Int#
0# Word#
l State# RealWorld
s of
         State# RealWorld
s -> MutableWordArray# RealWorld
-> Int# -> Word# -> State# RealWorld -> State# RealWorld
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# RealWorld
mwa Int#
1# Word#
h State# RealWorld
s
wordArrayFromWord# :: Word# -> WordArray#
wordArrayFromWord# :: Word# -> WordArray#
wordArrayFromWord# Word#
w   =
   Int#
-> (MutableWordArray# RealWorld
    -> State# RealWorld -> State# RealWorld)
-> WordArray#
withNewWordArray# Int#
1# \MutableWordArray# RealWorld
mwa State# RealWorld
s ->
      MutableWordArray# RealWorld
-> Int# -> Word# -> State# RealWorld -> State# RealWorld
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# RealWorld
mwa Int#
0# Word#
w State# RealWorld
s
wordArraySize# :: WordArray# -> Int#
wordArraySize# :: WordArray# -> Int#
wordArraySize# WordArray#
ba = Int# -> Int#
bytesToWords# (WordArray# -> Int#
sizeofByteArray# WordArray#
ba)
mwaSize# :: MutableWordArray# s-> State# s -> (# State# s, Int# #)
mwaSize# :: forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableWordArray# s
mba State# s
s = case MutableWordArray# s -> State# s -> (# State# s, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
getSizeofMutableByteArray# MutableWordArray# s
mba State# s
s of
   (# State# s
s2, Int#
sz #) -> (# State# s
s2, Int# -> Int#
bytesToWords# Int#
sz #)
wordArrayLast# :: WordArray# -> Word#
wordArrayLast# :: WordArray# -> Word#
wordArrayLast# WordArray#
a = WordArray# -> Int# -> Word#
indexWordArray# WordArray#
a (WordArray# -> Int#
wordArraySize# WordArray#
a Int# -> Int# -> Int#
-# Int#
1#)
mwaArrayCopy# :: MutableByteArray# s -> Int# -> WordArray# -> Int# -> Int# -> State# s -> State# s
mwaArrayCopy# :: forall s.
MutableByteArray# s
-> Int# -> WordArray# -> Int# -> Int# -> State# s -> State# s
mwaArrayCopy# MutableByteArray# s
dst Int#
dstIdx WordArray#
src Int#
srcIdx Int#
n State# s
s
   | Int# -> Bool
isTrue# (Int#
n Int# -> Int# -> Int#
<=# Int#
0#) = State# s
s
   | Bool
True = WordArray#
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
forall d.
WordArray#
-> Int#
-> MutableByteArray# d
-> Int#
-> Int#
-> State# d
-> State# d
copyByteArray#
               WordArray#
src (Int# -> Int#
wordsToBytes# Int#
srcIdx)
               MutableByteArray# s
dst (Int# -> Int#
wordsToBytes# Int#
dstIdx)
               (Int# -> Int#
wordsToBytes# Int#
n) State# s
s
mwaShrink# :: MutableByteArray# s -> Int# -> State# s -> State# s
mwaShrink# :: forall s. MutableByteArray# s -> Int# -> State# s -> State# s
mwaShrink# MutableByteArray# s
_mwa Int#
0# State# s
s = State# s
s
mwaShrink# MutableByteArray# s
mwa  Int#
i  State# s
s =
   case MutableByteArray# s -> State# s -> (# State# s, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableByteArray# s
mwa State# s
s of
      (# State# s
s, Int#
n #) -> MutableByteArray# s -> Int# -> State# s -> State# s
forall s. MutableByteArray# s -> Int# -> State# s -> State# s
shrinkMutableByteArray# MutableByteArray# s
mwa (Int# -> Int#
wordsToBytes# (Int#
n Int# -> Int# -> Int#
-# Int#
i)) State# s
s
mwaSetSize# :: MutableByteArray# s -> Int# -> State# s -> State# s
mwaSetSize# :: forall s. MutableByteArray# s -> Int# -> State# s -> State# s
mwaSetSize# MutableByteArray# s
mwa Int#
n State# s
s = MutableByteArray# s -> Int# -> State# s -> State# s
forall s. MutableByteArray# s -> Int# -> State# s -> State# s
shrinkMutableByteArray# MutableByteArray# s
mwa (Int# -> Int#
wordsToBytes# Int#
n) State# s
s
mwaInitCopyShrink# :: MutableByteArray# s -> WordArray# -> State# s -> State# s
mwaInitCopyShrink# :: forall s. MutableByteArray# s -> WordArray# -> State# s -> State# s
mwaInitCopyShrink# MutableByteArray# s
mwa WordArray#
wa State# s
s =
   case MutableByteArray# s
-> Int# -> WordArray# -> Int# -> Int# -> State# s -> State# s
forall s.
MutableByteArray# s
-> Int# -> WordArray# -> Int# -> Int# -> State# s -> State# s
mwaArrayCopy# MutableByteArray# s
mwa Int#
0# WordArray#
wa Int#
0# (WordArray# -> Int#
wordArraySize# WordArray#
wa) State# s
s of
      State# s
s -> MutableByteArray# s -> Int# -> State# s -> State# s
forall s. MutableByteArray# s -> Int# -> State# s -> State# s
mwaSetSize# MutableByteArray# s
mwa (WordArray# -> Int#
wordArraySize# WordArray#
wa) State# s
s
mwaTrimZeroes# :: MutableByteArray# s -> State# s -> State# s
mwaTrimZeroes# :: forall s. MutableByteArray# s -> State# s -> State# s
mwaTrimZeroes# MutableByteArray# s
mwa State# s
s1 =
   case MutableByteArray# s -> State# s -> (# State# s, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaClz MutableByteArray# s
mwa State# s
s1 of
      (# State# s
s2, Int#
0# #) -> State# s
s2
      (# State# s
s2, Int#
c  #) -> MutableByteArray# s -> Int# -> State# s -> State# s
forall s. MutableByteArray# s -> Int# -> State# s -> State# s
mwaShrink# MutableByteArray# s
mwa Int#
c State# s
s2
mwaClz :: MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaClz :: forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaClz MutableWordArray# s
mwa State# s
s1 = case MutableWordArray# s -> State# s -> (# State# s, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableWordArray# s
mwa State# s
s1 of
   (# State# s
s2,Int#
sz #)  -> MutableWordArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall s.
MutableWordArray# s -> Int# -> State# s -> (# State# s, Int# #)
mwaClzAt MutableWordArray# s
mwa (Int#
sz Int# -> Int# -> Int#
-# Int#
1#) State# s
s2
mwaClzAt :: MutableWordArray# s -> Int# -> State# s -> (# State# s, Int# #)
mwaClzAt :: forall s.
MutableWordArray# s -> Int# -> State# s -> (# State# s, Int# #)
mwaClzAt MutableWordArray# s
mwa = Int# -> Int# -> State# s -> (# State# s, Int# #)
go Int#
0#
   where
      go :: Int# -> Int# -> State# s -> (# State# s, Int# #)
go Int#
c Int#
i State# s
s
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
<# Int#
0#) = (# State# s
s, Int#
c #)
         | Bool
True = case MutableWordArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableWordArray# s
mwa Int#
i State# s
s of
            (# State# s
s', Word#
0## #) -> Int# -> Int# -> State# s -> (# State# s, Int# #)
go (Int#
c Int# -> Int# -> Int#
+# Int#
1#) (Int#
i Int# -> Int# -> Int#
-# Int#
1#) State# s
s'
            (# State# s
s', Word#
_   #) -> (# State# s
s', Int#
c #)
waClzAt :: WordArray# -> Int# -> Int#
waClzAt :: WordArray# -> Int# -> Int#
waClzAt WordArray#
wa = Int# -> Int# -> Int#
go Int#
0#
   where
      go :: Int# -> Int# -> Int#
go Int#
c Int#
i
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
<# Int#
0#)
         = Int#
c
         | Word#
0## <- WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wa Int#
i
         = Int# -> Int# -> Int#
go (Int#
c Int# -> Int# -> Int#
+# Int#
1#) (Int#
i Int# -> Int# -> Int#
-# Int#
1#)
         | Bool
True
         = Int#
c
wordArrayCompareMSWords :: WordArray# -> WordArray# -> Ordering
wordArrayCompareMSWords :: WordArray# -> WordArray# -> Ordering
wordArrayCompareMSWords WordArray#
wa WordArray#
wb
   | Int#
0# <- Int#
szA
   , Int#
0# <- Int#
szB
   = Ordering
EQ
   | Int#
0# <- Int#
szA
   = Ordering
LT
   | Int#
0# <- Int#
szB
   = Ordering
GT
   | Bool
True
   = Int# -> Int# -> Ordering
go (Int#
szA Int# -> Int# -> Int#
-# Int#
1#) (Int#
szB Int# -> Int# -> Int#
-# Int#
1#)
   where
      szA :: Int#
szA  = WordArray# -> Int#
wordArraySize# WordArray#
wa
      szB :: Int#
szB  = WordArray# -> Int#
wordArraySize# WordArray#
wb
      go :: Int# -> Int# -> Ordering
go Int#
i Int#
j
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
<# Int#
0#) = Ordering
EQ
         | Int# -> Bool
isTrue# (Int#
j Int# -> Int# -> Int#
<# Int#
0#) = Ordering
EQ
         | Bool
True =
            let
               a :: Word#
a = WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wa Int#
i
               b :: Word#
b = WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wb Int#
j
            in if | Int# -> Bool
isTrue# (Word#
a Word# -> Word# -> Int#
`gtWord#` Word#
b) -> Ordering
GT
                  | Int# -> Bool
isTrue# (Word#
b Word# -> Word# -> Int#
`gtWord#` Word#
a) -> Ordering
LT
                  | Bool
True                    -> Int# -> Int# -> Ordering
go (Int#
i Int# -> Int# -> Int#
-# Int#
1#) (Int#
j Int# -> Int# -> Int#
-# Int#
1#)
mwaInitArrayPlusWord :: MutableWordArray# s -> WordArray# -> Word# -> State# s -> State#s
mwaInitArrayPlusWord :: forall s.
MutableWordArray# s -> WordArray# -> Word# -> State# s -> State# s
mwaInitArrayPlusWord MutableWordArray# s
mwa WordArray#
wa = Int# -> Word# -> State# s -> State# s
go Int#
0#
   where
      sz :: Int#
sz = WordArray# -> Int#
wordArraySize# WordArray#
wa
      go :: Int# -> Word# -> State# s -> State# s
go Int#
i Word#
carry State# s
s
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
># Int#
sz)  = State# s
s
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
==# Int#
sz) = MutableWordArray# s -> Word# -> Int# -> State# s -> State# s
forall s.
MutableWordArray# s -> Word# -> Int# -> State# s -> State# s
mwaWriteOrShrink MutableWordArray# s
mwa Word#
carry Int#
i State# s
s
         | Word#
0## <- Word#
carry       = 
                                case MutableWordArray# s
-> Int# -> WordArray# -> Int# -> Int# -> State# s -> State# s
forall s.
MutableByteArray# s
-> Int# -> WordArray# -> Int# -> Int# -> State# s -> State# s
mwaArrayCopy# MutableWordArray# s
mwa Int#
i WordArray#
wa Int#
i (Int#
sz Int# -> Int# -> Int#
-# Int#
i) State# s
s of
                                    State# s
s2 -> MutableWordArray# s -> Int# -> State# s -> State# s
forall s. MutableByteArray# s -> Int# -> State# s -> State# s
mwaShrink# MutableWordArray# s
mwa Int#
1# State# s
s2
         | Bool
True               = let !(# Word#
l,Int#
c #) = Word# -> Word# -> (# Word#, Int# #)
addWordC# (WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wa Int#
i) Word#
carry
                                in case MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# s
mwa Int#
i Word#
l State# s
s of
                                    State# s
s2 -> Int# -> Word# -> State# s -> State# s
go (Int#
i Int# -> Int# -> Int#
+# Int#
1#) (Int# -> Word#
int2Word# Int#
c) State# s
s2
mwaWriteOrShrink :: MutableWordArray# s -> Word# -> Int# -> State# s -> State# s
mwaWriteOrShrink :: forall s.
MutableWordArray# s -> Word# -> Int# -> State# s -> State# s
mwaWriteOrShrink MutableWordArray# s
mwa Word#
0## Int#
_i State# s
s = MutableWordArray# s -> Int# -> State# s -> State# s
forall s. MutableByteArray# s -> Int# -> State# s -> State# s
mwaShrink# MutableWordArray# s
mwa Int#
1# State# s
s
mwaWriteOrShrink MutableWordArray# s
mwa  Word#
w   Int#
i State# s
s = MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# s
mwa Int#
i Word#
w State# s
s
mwaWriteMostSignificant :: MutableWordArray# s -> Word# -> State# s -> State# s
mwaWriteMostSignificant :: forall s. MutableWordArray# s -> Word# -> State# s -> State# s
mwaWriteMostSignificant MutableWordArray# s
mwa Word#
w State# s
s =
   case MutableWordArray# s -> State# s -> (# State# s, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableWordArray# s
mwa State# s
s of
      (# State# s
s', Int#
sz #) -> MutableWordArray# s -> Word# -> Int# -> State# s -> State# s
forall s.
MutableWordArray# s -> Word# -> Int# -> State# s -> State# s
mwaWriteOrShrink MutableWordArray# s
mwa Word#
w (Int#
sz Int# -> Int# -> Int#
-# Int#
1#) State# s
s'
mwaInitArrayBinOp :: MutableWordArray# s -> WordArray# -> WordArray# -> (Word# -> Word# -> Word#) -> State# s -> State#s
mwaInitArrayBinOp :: forall s.
MutableWordArray# s
-> WordArray#
-> WordArray#
-> (Word# -> Word# -> Word#)
-> State# s
-> State# s
mwaInitArrayBinOp MutableWordArray# s
mwa WordArray#
wa WordArray#
wb Word# -> Word# -> Word#
op State# s
s = Int# -> State# s -> State# s
go Int#
0# State# s
s
   where
      !sz :: Int#
sz = Int# -> Int# -> Int#
minI# (WordArray# -> Int#
wordArraySize# WordArray#
wa) (WordArray# -> Int#
wordArraySize# WordArray#
wb)
      go :: Int# -> State# s -> State# s
go Int#
i State# s
s'
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
==# Int#
sz) = State# s
s'
         | Bool
True =
            case WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wa Int#
i Word# -> Word# -> Word#
`op` WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wb Int#
i of
               Word#
v -> case MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# s
mwa Int#
i Word#
v State# s
s' of
                  State# s
s'' -> Int# -> State# s -> State# s
go (Int#
i Int# -> Int# -> Int#
+# Int#
1#) State# s
s''
mwaWrite# :: MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# :: forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# = MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
writeWordArray#
mwaFill# :: MutableWordArray# s -> Word# -> Word# -> Word# -> State# s -> State# s
mwaFill# :: forall s.
MutableWordArray# s
-> Word# -> Word# -> Word# -> State# s -> State# s
mwaFill# MutableWordArray# s
_   Word#
_ Word#
_   Word#
0## State# s
s = State# s
s
mwaFill# MutableWordArray# s
mwa Word#
v Word#
off Word#
n   State# s
s = case MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# s
mwa (Word# -> Int#
word2Int# Word#
off) Word#
v State# s
s of
   State# s
s' -> MutableWordArray# s
-> Word# -> Word# -> Word# -> State# s -> State# s
forall s.
MutableWordArray# s
-> Word# -> Word# -> Word# -> State# s -> State# s
mwaFill# MutableWordArray# s
mwa Word#
v (Word#
off Word# -> Word# -> Word#
`plusWord#` Word#
1##) (Word#
n Word# -> Word# -> Word#
`minusWord#` Word#
1##) State# s
s'
mwaAddInplaceWord# :: MutableWordArray# d -> Int# -> Word# -> State# d -> State# d
mwaAddInplaceWord# :: forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaAddInplaceWord#   MutableWordArray# d
_ Int#
_ Word#
0## State# d
s = State# d
s
mwaAddInplaceWord# MutableWordArray# d
mwa Int#
i Word#
y   State# d
s = case MutableWordArray# d -> Int# -> State# d -> (# State# d, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableWordArray# d
mwa Int#
i State# d
s of
   (# State# d
s1, Word#
x #) -> let !(# Word#
h,Word#
l #) = Word# -> Word# -> (# Word#, Word# #)
plusWord2# Word#
x Word#
y
                  in case MutableWordArray# d -> Int# -> Word# -> State# d -> State# d
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# d
mwa Int#
i Word#
l State# d
s1 of
                        State# d
s2 -> MutableWordArray# d -> Int# -> Word# -> State# d -> State# d
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaAddInplaceWord# MutableWordArray# d
mwa (Int#
i Int# -> Int# -> Int#
+# Int#
1#) Word#
h State# d
s2
mwaSubInplaceWord#
   :: MutableWordArray# d
   -> Int#
   -> Word#
   -> State# d
   -> (# State# d, Bool# #)
mwaSubInplaceWord# :: forall d.
MutableWordArray# d
-> Int# -> Word# -> State# d -> (# State# d, Int# #)
mwaSubInplaceWord# MutableWordArray# d
mwa Int#
ii Word#
iw State# d
s1 = case MutableWordArray# d -> State# d -> (# State# d, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableWordArray# d
mwa State# d
s1 of
   (# State# d
is, Int#
sz #) ->
      let
         go :: Int# -> Word# -> State# d -> (# State# d, Int# #)
go Int#
_ Word#
0## State# d
s = (# State# d
s, Int#
1# #) 
         go Int#
i Word#
y   State# d
s
            | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
>=# Int#
sz) = (# State# d
s, Int#
0# #) 
            | Bool
True = case MutableWordArray# d -> Int# -> State# d -> (# State# d, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableWordArray# d
mwa Int#
i State# d
s of
               (# State# d
s1, Word#
x #) -> let !(# Word#
l,Int#
h #) = Word# -> Word# -> (# Word#, Int# #)
subWordC# Word#
x Word#
y
                  in case MutableWordArray# d -> Int# -> Word# -> State# d -> State# d
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaWrite# MutableWordArray# d
mwa Int#
i Word#
l State# d
s1 of
                     State# d
s2 -> Int# -> Word# -> State# d -> (# State# d, Int# #)
go (Int#
i Int# -> Int# -> Int#
+# Int#
1#) (Int# -> Word#
int2Word# Int#
h) State# d
s2
      in Int# -> Word# -> State# d -> (# State# d, Int# #)
go Int#
ii Word#
iw State# d
is
mwaTrimCompare :: Int# -> MutableWordArray# s -> WordArray# -> State# s -> (# State# s, Ordering #)
mwaTrimCompare :: forall s.
Int#
-> MutableWordArray# s
-> WordArray#
-> State# s
-> (# State# s, Ordering #)
mwaTrimCompare Int#
k MutableWordArray# s
mwa WordArray#
wb State# s
s1
   | (# State# s
s, Int#
szA #) <- MutableWordArray# s -> State# s -> (# State# s, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableWordArray# s
mwa State# s
s1
   , Int#
szB <- WordArray# -> Int#
wordArraySize# WordArray#
wb
   =
     let
      go :: Int# -> State# s -> (# State# s, Ordering #)
go Int#
i State# s
s
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
<# Int#
0#) = (# State# s
s, Ordering
EQ #)
         | Bool
True = case MutableWordArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableWordArray# s
mwa (Int#
i Int# -> Int# -> Int#
+# Int#
k) State# s
s of
            (# State# s
s2, Word#
ai #) ->
               let bi :: Word#
bi = if Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
>=# Int#
szB)
                           then Word#
0##
                           else WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wb Int#
i
               in if | Int# -> Bool
isTrue# (Word#
ai Word# -> Word# -> Int#
`gtWord#` Word#
bi) -> (# State# s
s2, Ordering
GT #)
                     | Int# -> Bool
isTrue# (Word#
bi Word# -> Word# -> Int#
`gtWord#` Word#
ai) -> (# State# s
s2, Ordering
LT #)
                     | Bool
True                      -> Int# -> State# s -> (# State# s, Ordering #)
go (Int#
i Int# -> Int# -> Int#
-# Int#
1#) State# s
s2
      szTrimA :: Int#
szTrimA = Int#
szA Int# -> Int# -> Int#
-# Int#
k
     in if | Int# -> Bool
isTrue# (Int#
szTrimA Int# -> Int# -> Int#
<# Int#
szB) -> (# State# s
s, Ordering
LT #)
           | Bool
True                     -> Int# -> State# s -> (# State# s, Ordering #)
go (Int#
szA Int# -> Int# -> Int#
-# Int#
k Int# -> Int# -> Int#
-# Int#
1#) State# s
s
mwaSubInplaceArray :: MutableWordArray# d -> Int# -> WordArray# -> State# d -> (# State# d, Bool# #)
mwaSubInplaceArray :: forall d.
MutableWordArray# d
-> Int# -> WordArray# -> State# d -> (# State# d, Int# #)
mwaSubInplaceArray MutableWordArray# d
mwa Int#
off WordArray#
wb = Int# -> State# d -> (# State# d, Int# #)
go (WordArray# -> Int#
wordArraySize# WordArray#
wb Int# -> Int# -> Int#
-# Int#
1#)
   where
      go :: Int# -> State# d -> (# State# d, Int# #)
go Int#
i State# d
s
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
<# Int#
0#) = (# State# d
s, Int#
1# #) 
         | Bool
True
         = case MutableWordArray# d
-> Int# -> Word# -> State# d -> (# State# d, Int# #)
forall d.
MutableWordArray# d
-> Int# -> Word# -> State# d -> (# State# d, Int# #)
mwaSubInplaceWord# MutableWordArray# d
mwa (Int#
off Int# -> Int# -> Int#
+# Int#
i) (WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wb Int#
i) State# d
s of
            (# State# d
s2, Int#
1# #) -> Int# -> State# d -> (# State# d, Int# #)
go (Int#
i Int# -> Int# -> Int#
-# Int#
1#) State# d
s2
            (# State# d
s2, Int#
_  #) -> (# State# d
s2, Int#
0# #) 
mwaAddInplaceArray :: MutableWordArray# d -> Int# -> WordArray# -> State# d -> State# d
mwaAddInplaceArray :: forall d.
MutableWordArray# d -> Int# -> WordArray# -> State# d -> State# d
mwaAddInplaceArray MutableWordArray# d
mwa Int#
off WordArray#
wb = Int# -> Word# -> State# d -> State# d
go Int#
0# Word#
0##
   where
      !maxi :: Int#
maxi = WordArray# -> Int#
wordArraySize# WordArray#
wb
      go :: Int# -> Word# -> State# d -> State# d
go Int#
i Word#
c State# d
s
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
==# Int#
maxi) = MutableWordArray# d -> Int# -> Word# -> State# d -> State# d
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
mwaAddInplaceWord# MutableWordArray# d
mwa (Int#
i Int# -> Int# -> Int#
+# Int#
off) Word#
c State# d
s
         | Bool
True
         = case MutableWordArray# d -> Int# -> State# d -> (# State# d, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableWordArray# d
mwa (Int#
i Int# -> Int# -> Int#
+# Int#
off) State# d
s of
            (# State# d
s, Word#
v #) -> case Word# -> Word# -> Word# -> (# Word#, Word# #)
plusWord3# Word#
v (WordArray# -> Int# -> Word#
indexWordArray# WordArray#
wb Int#
i) Word#
c of
               (# Word#
c', Word#
v' #) -> case MutableWordArray# d -> Int# -> Word# -> State# d -> State# d
forall s.
MutableWordArray# s -> Int# -> Word# -> State# s -> State# s
writeWordArray# MutableWordArray# d
mwa (Int#
i Int# -> Int# -> Int#
+# Int#
off) Word#
v' State# d
s of
                  State# d
s -> Int# -> Word# -> State# d -> State# d
go (Int#
i Int# -> Int# -> Int#
+# Int#
1#) Word#
c' State# d
s
mwaSubInplaceMutableArray :: MutableWordArray# d -> Int# -> MutableWordArray# d -> State# d -> (# State# d, Bool# #)
mwaSubInplaceMutableArray :: forall d.
MutableWordArray# d
-> Int# -> MutableWordArray# d -> State# d -> (# State# d, Int# #)
mwaSubInplaceMutableArray MutableWordArray# d
mwa Int#
off MutableWordArray# d
mwb State# d
s0 =
   case MutableWordArray# d -> State# d -> (# State# d, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableWordArray# d
mwb State# d
s0 of
      (# State# d
s1, Int#
szB #) -> Int# -> State# d -> (# State# d, Int# #)
go (Int#
szB Int# -> Int# -> Int#
-# Int#
1#) State# d
s1
   where
      go :: Int# -> State# d -> (# State# d, Int# #)
go Int#
i State# d
s
         | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
<# Int#
0#) = (# State# d
s, Int#
1# #) 
         | Bool
True
         = case MutableWordArray# d -> Int# -> State# d -> (# State# d, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableWordArray# d
mwb Int#
i State# d
s of
            (# State# d
s1, Word#
bi #) -> case MutableWordArray# d
-> Int# -> Word# -> State# d -> (# State# d, Int# #)
forall d.
MutableWordArray# d
-> Int# -> Word# -> State# d -> (# State# d, Int# #)
mwaSubInplaceWord# MutableWordArray# d
mwa (Int#
off Int# -> Int# -> Int#
+# Int#
i) Word#
bi State# d
s1 of
               (# State# d
s2, Int#
1# #) -> Int# -> State# d -> (# State# d, Int# #)
go (Int#
i Int# -> Int# -> Int#
-# Int#
1#) State# d
s2
               (# State# d
s2, Int#
_  #) -> (# State# d
s2, Int#
0# #) 
mwaSubInplaceArrayTrim :: MutableWordArray# d -> Int# -> WordArray# -> State# d -> State# d
mwaSubInplaceArrayTrim :: forall d.
MutableWordArray# d -> Int# -> WordArray# -> State# d -> State# d
mwaSubInplaceArrayTrim MutableWordArray# d
mwa Int#
off WordArray#
wb State# d
s =
   case MutableWordArray# d
-> Int# -> WordArray# -> State# d -> (# State# d, Int# #)
forall d.
MutableWordArray# d
-> Int# -> WordArray# -> State# d -> (# State# d, Int# #)
mwaSubInplaceArray MutableWordArray# d
mwa Int#
off WordArray#
wb State# d
s of
      (# State# d
s', Int#
_ #) -> MutableWordArray# d -> State# d -> State# d
forall s. MutableByteArray# s -> State# s -> State# s
mwaTrimZeroes# MutableWordArray# d
mwa State# d
s'
mwaReadOrZero :: MutableWordArray# s -> Int# -> State# s  -> (# State# s, Word# #)
mwaReadOrZero :: forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
mwaReadOrZero MutableWordArray# s
mwa Int#
i State# s
s = case MutableWordArray# s -> State# s -> (# State# s, Int# #)
forall s. MutableWordArray# s -> State# s -> (# State# s, Int# #)
mwaSize# MutableWordArray# s
mwa State# s
s of
   (# State# s
s2, Int#
sz #)
      | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
>=# Int#
sz) -> (# State# s
s2, Word#
0## #)
      | Int# -> Bool
isTrue# (Int#
i Int# -> Int# -> Int#
<# Int#
0#)  -> (# State# s
s2, Word#
0## #)
      | Bool
True               -> MutableWordArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray# MutableWordArray# s
mwa Int#
i State# s
s2
mwaRead# :: MutableWordArray# s -> Int# -> State# s -> (# State# s, Word# #)
mwaRead# :: forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
mwaRead# = MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
forall d.
MutableByteArray# d -> Int# -> State# d -> (# State# d, Word# #)
readWordArray#