{-# language DataKinds #-}
{-# language MagicHash #-}
{-# language UnboxedTuples #-}

module Basics.Int64
  ( -- Types
    T
  , T#
  , R
    -- Lifting
  , lift
  , unlift
    -- Arithmetic
  , plus
  , minus
  , plus#
  , minus#
  , times#
  , quot#
  , rem#
    -- Compare
  , gt#
  , lt#
  , gte#
  , lte#
  , eq#
  , neq#
  , gt
  , lt
  , gte
  , lte
  , eq
  , neq
    -- Array
  , read#
  , write#
  , index#
  , read
  , write
  , index
  , uninitialized#
  , initialized#
  , uninitialized
  , initialized
  , copy#
  , copyMutable#
  , set#
  , shrink#
  , shrink
    -- Constants
  , zero
  , def
  , minBound
  , maxBound
  , infimum
  , supremum
    -- Metadata
  , signed
    -- Encoding
  , shows
  ) where

import Prelude hiding (shows,maxBound,minBound,read)

import GHC.Exts
import GHC.Int
import Data.Primitive (MutableByteArray(..),ByteArray(..))
import GHC.ST (ST(ST))

import qualified Prelude
import qualified GHC.Exts as Exts

type T = Int64
type T# = Int#
type R = 'IntRep

def :: T
{-# inline def #-}
def :: T
def = T
0

zero :: T
{-# inline zero #-}
zero :: T
zero = T
0

minBound :: T
{-# inline minBound #-}
minBound :: T
minBound = Int# -> T
I64# (Int#
-9223372036854775808#)

maxBound :: T
{-# inline maxBound #-}
maxBound :: T
maxBound = Int# -> T
I64# (Int#
9223372036854775807#)

infimum :: T
{-# inline infimum #-}
infimum :: T
infimum = Int# -> T
I64# (Int#
-9223372036854775808#)

supremum :: T
{-# inline supremum #-}
supremum :: T
supremum = Int# -> T
I64# (Int#
9223372036854775807#)

signed :: Bool
{-# inline signed #-}
signed :: Bool
signed = Bool
True

lift :: T# -> T
{-# inline lift #-}
lift :: Int# -> T
lift = Int# -> T
I64#

unlift :: T -> T#
{-# inline unlift #-}
unlift :: T -> Int#
unlift (I64# Int#
i) = Int#
i

plus :: T -> T -> T
{-# inline plus #-}
plus :: T -> T -> T
plus (I64# Int#
x) (I64# Int#
y) = Int# -> T
I64# (Int#
x Int# -> Int# -> Int#
+# Int#
y)

minus :: T -> T -> T
{-# inline minus #-}
minus :: T -> T -> T
minus (I64# Int#
x) (I64# Int#
y) = Int# -> T
I64# (Int#
x Int# -> Int# -> Int#
-# Int#
y)

times# :: T# -> T# -> T#
{-# inline times# #-}
times# :: Int# -> Int# -> Int#
times# = Int# -> Int# -> Int#
(*#)

quot# :: T# -> T# -> T#
{-# inline quot# #-}
quot# :: Int# -> Int# -> Int#
quot# = Int# -> Int# -> Int#
quotInt#

rem# :: T# -> T# -> T#
{-# inline rem# #-}
rem# :: Int# -> Int# -> Int#
rem# = Int# -> Int# -> Int#
remInt#

plus# :: T# -> T# -> T#
{-# inline plus# #-}
plus# :: Int# -> Int# -> Int#
plus# = Int# -> Int# -> Int#
(+#)

minus# :: T# -> T# -> T#
{-# inline minus# #-}
minus# :: Int# -> Int# -> Int#
minus# = Int# -> Int# -> Int#
(-#)

gt# :: T# -> T# -> Int#
{-# inline gt# #-}
gt# :: Int# -> Int# -> Int#
gt# = Int# -> Int# -> Int#
(>#)

lt# :: T# -> T# -> Int#
{-# inline lt# #-}
lt# :: Int# -> Int# -> Int#
lt# = Int# -> Int# -> Int#
(<#)

gte# :: T# -> T# -> Int#
{-# inline gte# #-}
gte# :: Int# -> Int# -> Int#
gte# = Int# -> Int# -> Int#
(>=#)

lte# :: T# -> T# -> Int#
{-# inline lte# #-}
lte# :: Int# -> Int# -> Int#
lte# = Int# -> Int# -> Int#
(<=#)

eq# :: T# -> T# -> Int#
{-# inline eq# #-}
eq# :: Int# -> Int# -> Int#
eq# = Int# -> Int# -> Int#
(==#)

neq# :: T# -> T# -> Int#
{-# inline neq# #-}
neq# :: Int# -> Int# -> Int#
neq# = Int# -> Int# -> Int#
(/=#)

gt :: T -> T -> Bool
{-# inline gt #-}
gt :: T -> T -> Bool
gt = forall a. Ord a => a -> a -> Bool
(>)

lt :: T -> T -> Bool
{-# inline lt #-}
lt :: T -> T -> Bool
lt = forall a. Ord a => a -> a -> Bool
(<)

gte :: T -> T -> Bool
{-# inline gte #-}
gte :: T -> T -> Bool
gte = forall a. Ord a => a -> a -> Bool
(>=)

lte :: T -> T -> Bool
{-# inline lte #-}
lte :: T -> T -> Bool
lte = forall a. Ord a => a -> a -> Bool
(<=)

eq :: T -> T -> Bool
{-# inline eq #-}
eq :: T -> T -> Bool
eq = forall a. Eq a => a -> a -> Bool
(==)

neq :: T -> T -> Bool
{-# inline neq #-}
neq :: T -> T -> Bool
neq = forall a. Eq a => a -> a -> Bool
(/=)

index# :: ByteArray# -> Int# -> T#
{-# inline index# #-}
index# :: ByteArray# -> Int# -> Int#
index# = ByteArray# -> Int# -> Int#
indexIntArray#

read# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, T# #)
{-# inline read# #-}
read# :: forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
read# = forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
readIntArray#

write# :: MutableByteArray# s -> Int# -> T# -> State# s -> State# s
{-# inline write# #-}
write# :: forall s.
MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
write# = forall s.
MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
writeIntArray#

set# :: MutableByteArray# s -> Int# -> Int# -> T# -> State# s -> State# s
{-# inline set# #-}
set# :: forall s.
MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
set# MutableByteArray# s
marr Int#
off Int#
len Int#
x State# s
s = case Int#
len of
  Int#
0# -> State# s
s
  Int#
_ -> forall s.
MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
set# MutableByteArray# s
marr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) (Int#
len Int# -> Int# -> Int#
-# Int#
1# ) Int#
x (forall s.
MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
write# MutableByteArray# s
marr Int#
off Int#
x State# s
s)

uninitialized# :: Int# -> State# s -> (# State# s, MutableByteArray# s #)
{-# inline uninitialized# #-}
uninitialized# :: forall s. Int# -> State# s -> (# State# s, MutableByteArray# s #)
uninitialized# Int#
sz = forall s. Int# -> State# s -> (# State# s, MutableByteArray# s #)
Exts.newByteArray# (Int#
sz Int# -> Int# -> Int#
*# Int#
8# )

initialized# ::
     Int# -> T# -> State# s
  -> (# State# s, MutableByteArray# s #)
{-# inline initialized# #-}
initialized# :: forall s.
Int# -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
initialized# Int#
n Int#
e State# s
s0 = case forall s. Int# -> State# s -> (# State# s, MutableByteArray# s #)
uninitialized# Int#
n State# s
s0 of
  (# State# s
s1, MutableByteArray# s
a #) -> case forall s.
MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
set# MutableByteArray# s
a Int#
0# Int#
n Int#
e State# s
s1 of
    State# s
s2 -> (# State# s
s2, MutableByteArray# s
a #)

uninitialized :: Int -> ST s (MutableByteArray s)
{-# inline uninitialized #-}
uninitialized :: forall s. Int -> ST s (MutableByteArray s)
uninitialized (I# Int#
sz) = forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s0 -> case forall s. Int# -> State# s -> (# State# s, MutableByteArray# s #)
uninitialized# Int#
sz State# s
s0 of
  (# State# s
s1, MutableByteArray# s
a #) -> (# State# s
s1, forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
a #)

initialized :: Int -> T -> ST s (MutableByteArray s)
{-# inline initialized #-}
initialized :: forall s. Int -> T -> ST s (MutableByteArray s)
initialized (I# Int#
sz) T
e = forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s0 -> case forall s.
Int# -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
initialized# Int#
sz (T -> Int#
unlift T
e) State# s
s0 of
  (# State# s
s1, MutableByteArray# s
a #) -> (# State# s
s1, forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
a #)

shrink# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
{-# inline shrink# #-}
shrink# :: forall s.
MutableByteArray# s
-> Int# -> State# s -> (# State# s, MutableByteArray# s #)
shrink# MutableByteArray# s
m Int#
i State# s
s0 = (# forall d. MutableByteArray# d -> Int# -> State# d -> State# d
Exts.shrinkMutableByteArray# MutableByteArray# s
m (Int#
i Int# -> Int# -> Int#
*# Int#
8#) State# s
s0, MutableByteArray# s
m #)

copy# :: MutableByteArray# s -> Int# -> ByteArray# -> Int# -> Int# -> State# s -> State# s
{-# inline copy# #-}
copy# :: forall s.
MutableByteArray# s
-> Int# -> ByteArray# -> Int# -> Int# -> State# s -> State# s
copy# MutableByteArray# s
dst Int#
doff ByteArray#
src Int#
soff Int#
len =
  forall d.
ByteArray#
-> Int#
-> MutableByteArray# d
-> Int#
-> Int#
-> State# d
-> State# d
Exts.copyByteArray# ByteArray#
src (Int#
soff Int# -> Int# -> Int#
*# Int#
8#) MutableByteArray# s
dst (Int#
doff Int# -> Int# -> Int#
*# Int#
8#) (Int#
len Int# -> Int# -> Int#
*# Int#
8#)

copyMutable# :: MutableByteArray# s -> Int# -> MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
{-# inline copyMutable# #-}
copyMutable# :: forall s.
MutableByteArray# s
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
copyMutable# MutableByteArray# s
dst Int#
doff MutableByteArray# s
src Int#
soff Int#
len =
  forall s.
MutableByteArray# s
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
Exts.copyMutableByteArray# MutableByteArray# s
src (Int#
soff Int# -> Int# -> Int#
*# Int#
8#) MutableByteArray# s
dst (Int#
doff Int# -> Int# -> Int#
*# Int#
8#) (Int#
len Int# -> Int# -> Int#
*# Int#
8#)

shows :: T -> String -> String
{-# inline shows #-}
shows :: T -> String -> String
shows = forall a. Show a => a -> String -> String
Prelude.shows

index :: ByteArray -> Int -> T
{-# inline index #-}
index :: ByteArray -> Int -> T
index (ByteArray ByteArray#
x) (I# Int#
i) = Int# -> T
I64# (ByteArray# -> Int# -> Int#
indexInt64Array# ByteArray#
x Int#
i)

read :: MutableByteArray s -> Int -> ST s T
{-# inline read #-}
read :: forall s. MutableByteArray s -> Int -> ST s T
read (MutableByteArray MutableByteArray# s
x) (I# Int#
i) = forall s a. STRep s a -> ST s a
ST
  (\State# s
s0 -> case forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
readInt64Array# MutableByteArray# s
x Int#
i State# s
s0 of
    (# State# s
s1, Int#
r #) -> (# State# s
s1, Int# -> T
I64# Int#
r #)
  )

write :: MutableByteArray s -> Int -> T -> ST s ()
{-# inline write #-}
write :: forall s. MutableByteArray s -> Int -> T -> ST s ()
write (MutableByteArray MutableByteArray# s
x) (I# Int#
i) (I64# Int#
e) = forall s a. STRep s a -> ST s a
ST (\State# s
s -> (# forall s.
MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
writeInt64Array# MutableByteArray# s
x Int#
i Int#
e State# s
s, () #) )

shrink :: MutableByteArray s -> Int -> ST s (MutableByteArray s)
{-# inline shrink #-}
shrink :: forall s. MutableByteArray s -> Int -> ST s (MutableByteArray s)
shrink (MutableByteArray MutableByteArray# s
x) (I# Int#
i) = forall s a. STRep s a -> ST s a
ST
  (\State# s
s0 -> case forall s.
MutableByteArray# s
-> Int# -> State# s -> (# State# s, MutableByteArray# s #)
shrink# MutableByteArray# s
x Int#
i State# s
s0 of
    (# State# s
s1, MutableByteArray# s
r #) -> (# State# s
s1, forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
r #)
  )