{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedFFITypes #-}
{-# LANGUAGE NegativeLiterals #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE BinaryLiterals #-}
{-# OPTIONS_GHC -fexpose-all-unfoldings #-}
module GHC.Num.Primitives
(
Bool#
, (&&#)
, (||#)
, notB#
, testBitI#
, minI#
, maxI#
, sgnI#
, absI#
, cmpI#
, intEncodeDouble#
, popCntI#
, andNot#
, cmpW#
, bitW#
, maxW#
, minW#
, testBitW#
, shiftRW#
, plusWord3#
, plusWord12#
, quotRemWord3#
, wordFromAbsInt#
, wordLog2#
, wordLogBase#
, wordSizeInBase#
, wordIsPowerOf2#
, wordEncodeDouble#
, wordReverseBits#
, wordReverseBits32#
, wordReverseBytes#
, wordFromAddr#
, wordFromAddrLE#
, wordFromAddrBE#
, wordToAddr#
, wordToAddrLE#
, wordToAddrBE#
, wordWriteAddrLE#
, wordWriteAddrBE#
, wordFromByteArray#
, wordFromByteArrayLE#
, wordFromByteArrayBE#
, wordToMutableByteArray#
, wordToMutableByteArrayLE#
, wordToMutableByteArrayBE#
, wordWriteMutableByteArrayLE#
, wordWriteMutableByteArrayBE#
, raiseUnderflow
, raiseUnderflow_Word#
, raiseDivZero
, raiseDivZero_Word#
, unexpectedValue
, unexpectedValue_Int#
, unexpectedValue_Word#
, ioWord#
, ioInt#
, ioVoid
, ioBool
)
where
#include "MachDeps.h"
#include "WordSize.h"
#include <ghcautoconf.h>
#if (__GLASGOW_HASKELL__ < 811)
import GHC.Magic
#else
import GHC.Prim.Exception
#endif
import GHC.Prim
import GHC.Types
import GHC.Tuple ()
default ()
type Bool# = Int#
(&&#) :: Bool# -> Bool# -> Bool#
&&# :: Bool# -> Bool# -> Bool#
(&&#) = Bool# -> Bool# -> Bool#
andI#
(||#) :: Bool# -> Bool# -> Bool#
||# :: Bool# -> Bool# -> Bool#
(||#) = Bool# -> Bool# -> Bool#
orI#
notB# :: Bool# -> Bool#
notB# :: Bool# -> Bool#
notB# Bool#
x = Bool#
x Bool# -> Bool# -> Bool#
`xorI#` Bool#
1#
infixr 3 &&#
infixr 2 ||#
absI# :: Int# -> Int#
absI# :: Bool# -> Bool#
absI# Bool#
i# = (Bool#
i# Bool# -> Bool# -> Bool#
`xorI#` Bool#
nsign) Bool# -> Bool# -> Bool#
-# Bool#
nsign
where
nsign :: Bool#
nsign = Bool# -> Bool# -> Bool#
uncheckedIShiftRA# Bool#
i# (WORD_SIZE_IN_BITS# -# 1#)
sgnI# :: Int# -> Int#
sgnI# :: Bool# -> Bool#
sgnI# Bool#
x# = (Bool#
x# Bool# -> Bool# -> Bool#
># Bool#
0#) Bool# -> Bool# -> Bool#
-# (Bool#
x# Bool# -> Bool# -> Bool#
<# Bool#
0#)
popCntI# :: Int# -> Word#
popCntI# :: Bool# -> Word#
popCntI# Bool#
i = Word# -> Word#
popCnt# (Bool# -> Word#
int2Word# Bool#
i)
cmpI# :: Int# -> Int# -> Int#
cmpI# :: Bool# -> Bool# -> Bool#
cmpI# Bool#
x# Bool#
y# = (Bool#
x# Bool# -> Bool# -> Bool#
># Bool#
y#) Bool# -> Bool# -> Bool#
-# (Bool#
x# Bool# -> Bool# -> Bool#
<# Bool#
y#)
testBitI# :: Int# -> Word# -> Bool#
testBitI# :: Bool# -> Word# -> Bool#
testBitI# Bool#
x Word#
i = ((Bool# -> Bool# -> Bool#
uncheckedIShiftL# Bool#
1# (Word# -> Bool#
word2Int# Word#
i)) Bool# -> Bool# -> Bool#
`andI#` Bool#
x) Bool# -> Bool# -> Bool#
/=# Bool#
0#
minI# :: Int# -> Int# -> Int#
minI# :: Bool# -> Bool# -> Bool#
minI# Bool#
x Bool#
y | Bool# -> Bool
isTrue# (Bool#
x Bool# -> Bool# -> Bool#
<=# Bool#
y) = Bool#
x
| Bool
True = Bool#
y
maxI# :: Int# -> Int# -> Int#
maxI# :: Bool# -> Bool# -> Bool#
maxI# Bool#
x Bool#
y | Bool# -> Bool
isTrue# (Bool#
x Bool# -> Bool# -> Bool#
>=# Bool#
y) = Bool#
x
| Bool
True = Bool#
y
foreign import ccall unsafe "__int_encodeDouble"
intEncodeDouble# :: Int# -> Int# -> Double#
andNot# :: Word# -> Word# -> Word#
andNot# :: Word# -> Word# -> Word#
andNot# Word#
x Word#
y = Word#
x Word# -> Word# -> Word#
`and#` (Word# -> Word#
not# Word#
y)
cmpW# :: Word# -> Word# -> Ordering
{-# INLINE cmpW# #-}
cmpW# :: Word# -> Word# -> Ordering
cmpW# Word#
x# Word#
y#
| Bool# -> Bool
isTrue# (Word#
x# Word# -> Word# -> Bool#
`ltWord#` Word#
y#) = Ordering
LT
| Bool# -> Bool
isTrue# (Word#
x# Word# -> Word# -> Bool#
`eqWord#` Word#
y#) = Ordering
EQ
| Bool
True = Ordering
GT
wordFromAbsInt# :: Int# -> Word#
wordFromAbsInt# :: Bool# -> Word#
wordFromAbsInt# Bool#
i
| Bool# -> Bool
isTrue# (Bool#
i Bool# -> Bool# -> Bool#
>=# Bool#
0#) = Bool# -> Word#
int2Word# Bool#
i
| Bool
True = Bool# -> Word#
int2Word# (Bool# -> Bool#
negateInt# Bool#
i)
minW# :: Word# -> Word# -> Word#
minW# :: Word# -> Word# -> Word#
minW# Word#
x# Word#
y# | Bool# -> Bool
isTrue# (Word#
x# Word# -> Word# -> Bool#
`leWord#` Word#
y#) = Word#
x#
| Bool
True = Word#
y#
maxW# :: Word# -> Word# -> Word#
maxW# :: Word# -> Word# -> Word#
maxW# Word#
x# Word#
y# | Bool# -> Bool
isTrue# (Word#
x# Word# -> Word# -> Bool#
`gtWord#` Word#
y#) = Word#
x#
| Bool
True = Word#
y#
bitW# :: Int# -> Word#
bitW# :: Bool# -> Word#
bitW# Bool#
k = Word#
1## Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
k
testBitW# :: Word# -> Word# -> Bool#
testBitW# :: Word# -> Word# -> Bool#
testBitW# Word#
w Word#
k = Word#
w Word# -> Word# -> Word#
`and#` (Word#
1## Word# -> Bool# -> Word#
`uncheckedShiftL#` Word# -> Bool#
word2Int# Word#
k) Word# -> Word# -> Bool#
`neWord#` Word#
0##
shiftRW# :: Word# -> Word# -> Word#
shiftRW# :: Word# -> Word# -> Word#
shiftRW# Word#
a Word#
b
| Bool# -> Bool
isTrue# (Word#
b Word# -> Word# -> Bool#
`geWord#` WORD_SIZE_IN_BITS##) = 0##
| Bool
True = Word#
a Word# -> Bool# -> Word#
`uncheckedShiftRL#` (Word# -> Bool#
word2Int# Word#
b)
plusWord12# :: Word# -> (# Word#,Word# #) -> (# Word#,Word# #)
{-# INLINABLE plusWord12# #-}
plusWord12# :: Word# -> (# Word#, Word# #) -> (# Word#, Word# #)
plusWord12# Word#
a0 (# Word#
b1,Word#
b0 #) = (# Word#
m1, Word#
m0 #)
where
!(# Word#
t, Word#
m0 #) = Word# -> Word# -> (# Word#, Word# #)
plusWord2# Word#
a0 Word#
b0
!m1 :: Word#
m1 = Word# -> Word# -> Word#
plusWord# Word#
t Word#
b1
plusWord3# :: Word# -> Word# -> Word# -> (# Word#, Word# #)
{-# INLINABLE plusWord3# #-}
plusWord3# :: Word# -> Word# -> Word# -> (# Word#, Word# #)
plusWord3# Word#
a Word#
b Word#
c = (# Word#
r1, Word#
r0 #)
where
!(# Word#
t1, Word#
t0 #) = Word# -> Word# -> (# Word#, Word# #)
plusWord2# Word#
a Word#
b
!(# Word#
t2, Word#
r0 #) = Word# -> Word# -> (# Word#, Word# #)
plusWord2# Word#
t0 Word#
c
!r1 :: Word#
r1 = Word# -> Word# -> Word#
plusWord# Word#
t1 Word#
t2
quotRemWord3# :: (# Word#,Word# #) -> Word# -> (# (# Word#,Word# #),Word# #)
quotRemWord3# :: (# Word#, Word# #) -> Word# -> (# (# Word#, Word# #), Word# #)
quotRemWord3# (# Word#
a1,Word#
a0 #) Word#
b0 = (# (# Word#
q1, Word#
q0 #), Word#
r0 #)
where
!(# Word#
q1, Word#
r' #) = Word# -> Word# -> (# Word#, Word# #)
quotRemWord# Word#
a1 Word#
b0
!(# Word#
q0, Word#
r0 #) = Word# -> Word# -> Word# -> (# Word#, Word# #)
quotRemWord2# Word#
r' Word#
a0 Word#
b0
foreign import ccall unsafe "__word_encodeDouble"
wordEncodeDouble# :: Word# -> Int# -> Double#
wordLog2# :: Word# -> Word#
wordLog2# :: Word# -> Word#
wordLog2# Word#
w = (WORD_SIZE_IN_BITS## `minusWord#` 1##) `minusWord#` (clz# w)
wordLogBase# :: Word# -> Word# -> Word#
wordLogBase# :: Word# -> Word# -> Word#
wordLogBase# Word#
base Word#
a
| Bool# -> Bool
isTrue# (Word#
base Word# -> Word# -> Bool#
`leWord#` Word#
1##)
= (# #) -> Word#
unexpectedValue_Word# (# #)
| Word#
2## <- Word#
base
= Word# -> Word#
wordLog2# Word#
a
| Bool
True
= case Word# -> (# Word#, Word# #)
go Word#
base of (# Word#
_, Word#
e' #) -> Word#
e'
where
goSqr :: Word# -> (# Word#, Word# #)
goSqr Word#
pw = case Word# -> Word# -> (# Word#, Word# #)
timesWord2# Word#
pw Word#
pw of
(# Word#
0##, Word#
l #) -> Word# -> (# Word#, Word# #)
go Word#
l
(# Word#
_ , Word#
_ #) -> (# Word#
a, Word#
0## #)
go :: Word# -> (# Word#, Word# #)
go Word#
pw = if Bool# -> Bool
isTrue# (Word#
a Word# -> Word# -> Bool#
`ltWord#` Word#
pw)
then (# Word#
a, Word#
0## #)
else case Word# -> (# Word#, Word# #)
goSqr Word#
pw of
(# Word#
q, Word#
e #) -> if Bool# -> Bool
isTrue# (Word#
q Word# -> Word# -> Bool#
`ltWord#` Word#
pw)
then (# Word#
q, Word#
2## Word# -> Word# -> Word#
`timesWord#` Word#
e #)
else (# Word#
q Word# -> Word# -> Word#
`quotWord#` Word#
pw
, Word#
2## Word# -> Word# -> Word#
`timesWord#` Word#
e Word# -> Word# -> Word#
`plusWord#` Word#
1## #)
wordSizeInBase# :: Word# -> Word# -> Word#
wordSizeInBase# :: Word# -> Word# -> Word#
wordSizeInBase# Word#
_ Word#
0## = Word#
0##
wordSizeInBase# Word#
base Word#
w = Word#
1## Word# -> Word# -> Word#
`plusWord#` Word# -> Word# -> Word#
wordLogBase# Word#
base Word#
w
wordIsPowerOf2# :: Word# -> (# (# #) | Word# #)
wordIsPowerOf2# :: Word# -> (# (# #) | Word# #)
wordIsPowerOf2# Word#
w
| Bool# -> Bool
isTrue# (Word# -> Word#
popCnt# Word#
w Word# -> Word# -> Bool#
`neWord#` Word#
1##) = (# (# #) | #)
| Bool
True = (# | Word# -> Word#
ctz# Word#
w #)
wordReverseBytes# :: Word# -> Word#
wordReverseBytes# :: Word# -> Word#
wordReverseBytes# Word#
x0 = Word#
r
where
#if WORD_SIZE_IN_BITS == 64
x1 :: Word#
x1 = ((Word#
x0 Word# -> Word# -> Word#
`and#` Word#
0x00FF00FF00FF00FF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
8#) Word# -> Word# -> Word#
`or#` ((Word#
x0 Word# -> Word# -> Word#
`and#` Word#
0xFF00FF00FF00FF00##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
8#)
x2 :: Word#
x2 = ((Word#
x1 Word# -> Word# -> Word#
`and#` Word#
0x0000FFFF0000FFFF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
16#) Word# -> Word# -> Word#
`or#` ((Word#
x1 Word# -> Word# -> Word#
`and#` Word#
0xFFFF0000FFFF0000##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
16#)
r :: Word#
r = ((Word#
x2 Word# -> Word# -> Word#
`and#` Word#
0x00000000FFFFFFFF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
32#) Word# -> Word# -> Word#
`or#` ((Word#
x2 Word# -> Word# -> Word#
`and#` Word#
0xFFFFFFFF00000000##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
32#)
#else
x1 = ((x0 `and#` 0x00FF00FF##) `uncheckedShiftL#` 8#) `or#` ((x0 `and#` 0xFF00FF00##) `uncheckedShiftRL#` 8#)
r = ((x1 `and#` 0x0000FFFF##) `uncheckedShiftL#` 16#) `or#` ((x1 `and#` 0xFFFF0000##) `uncheckedShiftRL#` 16#)
#endif
wordReverseBits# :: Word# -> Word#
wordReverseBits# :: Word# -> Word#
wordReverseBits# Word#
x0 = Word#
r
where
#if WORD_SIZE_IN_BITS == 64
x1 :: Word#
x1 = ((Word#
x0 Word# -> Word# -> Word#
`and#` Word#
0x5555555555555555##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
1#) Word# -> Word# -> Word#
`or#` ((Word#
x0 Word# -> Word# -> Word#
`and#` Word#
0xAAAAAAAAAAAAAAAA##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
1#)
x2 :: Word#
x2 = ((Word#
x1 Word# -> Word# -> Word#
`and#` Word#
0x3333333333333333##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
2#) Word# -> Word# -> Word#
`or#` ((Word#
x1 Word# -> Word# -> Word#
`and#` Word#
0xCCCCCCCCCCCCCCCC##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
2#)
x3 :: Word#
x3 = ((Word#
x2 Word# -> Word# -> Word#
`and#` Word#
0x0F0F0F0F0F0F0F0F##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
4#) Word# -> Word# -> Word#
`or#` ((Word#
x2 Word# -> Word# -> Word#
`and#` Word#
0xF0F0F0F0F0F0F0F0##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
4#)
x4 :: Word#
x4 = ((Word#
x3 Word# -> Word# -> Word#
`and#` Word#
0x00FF00FF00FF00FF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
8#) Word# -> Word# -> Word#
`or#` ((Word#
x3 Word# -> Word# -> Word#
`and#` Word#
0xFF00FF00FF00FF00##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
8#)
x5 :: Word#
x5 = ((Word#
x4 Word# -> Word# -> Word#
`and#` Word#
0x0000FFFF0000FFFF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
16#) Word# -> Word# -> Word#
`or#` ((Word#
x4 Word# -> Word# -> Word#
`and#` Word#
0xFFFF0000FFFF0000##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
16#)
r :: Word#
r = ((Word#
x5 Word# -> Word# -> Word#
`and#` Word#
0x00000000FFFFFFFF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
32#) Word# -> Word# -> Word#
`or#` ((Word#
x5 Word# -> Word# -> Word#
`and#` Word#
0xFFFFFFFF00000000##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
32#)
#else
x1 = ((x0 `and#` 0x55555555##) `uncheckedShiftL#` 1#) `or#` ((x0 `and#` 0xAAAAAAAA##) `uncheckedShiftRL#` 1#)
x2 = ((x1 `and#` 0x33333333##) `uncheckedShiftL#` 2#) `or#` ((x1 `and#` 0xCCCCCCCC##) `uncheckedShiftRL#` 2#)
x3 = ((x2 `and#` 0x0F0F0F0F##) `uncheckedShiftL#` 4#) `or#` ((x2 `and#` 0xF0F0F0F0##) `uncheckedShiftRL#` 4#)
x4 = ((x3 `and#` 0x00FF00FF##) `uncheckedShiftL#` 8#) `or#` ((x3 `and#` 0xFF00FF00##) `uncheckedShiftRL#` 8#)
r = ((x4 `and#` 0x0000FFFF##) `uncheckedShiftL#` 16#) `or#` ((x4 `and#` 0xFFFF0000##) `uncheckedShiftRL#` 16#)
#endif
wordReverseBits32# :: Word# -> Word#
#if WORD_SIZE_IN_BITS == 64
wordReverseBits32# :: Word# -> Word#
wordReverseBits32# Word#
x0 = Word#
r
where
x1 :: Word#
x1 = ((Word#
x0 Word# -> Word# -> Word#
`and#` Word#
0x5555555555555555##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
1#) Word# -> Word# -> Word#
`or#` ((Word#
x0 Word# -> Word# -> Word#
`and#` Word#
0xAAAAAAAAAAAAAAAA##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
1#)
x2 :: Word#
x2 = ((Word#
x1 Word# -> Word# -> Word#
`and#` Word#
0x3333333333333333##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
2#) Word# -> Word# -> Word#
`or#` ((Word#
x1 Word# -> Word# -> Word#
`and#` Word#
0xCCCCCCCCCCCCCCCC##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
2#)
x3 :: Word#
x3 = ((Word#
x2 Word# -> Word# -> Word#
`and#` Word#
0x0F0F0F0F0F0F0F0F##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
4#) Word# -> Word# -> Word#
`or#` ((Word#
x2 Word# -> Word# -> Word#
`and#` Word#
0xF0F0F0F0F0F0F0F0##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
4#)
x4 :: Word#
x4 = ((Word#
x3 Word# -> Word# -> Word#
`and#` Word#
0x00FF00FF00FF00FF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
8#) Word# -> Word# -> Word#
`or#` ((Word#
x3 Word# -> Word# -> Word#
`and#` Word#
0xFF00FF00FF00FF00##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
8#)
r :: Word#
r = ((Word#
x4 Word# -> Word# -> Word#
`and#` Word#
0x0000FFFF0000FFFF##) Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
16#) Word# -> Word# -> Word#
`or#` ((Word#
x4 Word# -> Word# -> Word#
`and#` Word#
0xFFFF0000FFFF0000##) Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
16#)
#else
wordReverseBits32# x0 = wordReverseBits# x0
#endif
wordToAddrLE# :: Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordToAddrLE# :: forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordToAddrLE# Word#
x Addr#
addr = forall {d}. Word# -> Bool# -> State# d -> (# State# d, Word# #)
go Word#
x Bool#
0#
where
go :: Word# -> Bool# -> State# d -> (# State# d, Word# #)
go Word#
w Bool#
c State# d
s
| Word#
0## <- Word#
w
= (# State# d
s, Bool# -> Word#
int2Word# Bool#
c #)
| Bool
True
= case forall d. Addr# -> Bool# -> Word8# -> State# d -> State# d
writeWord8OffAddr# Addr#
addr Bool#
c (Word# -> Word8#
wordToWord8# Word#
w) State# d
s of
State# d
s' -> Word# -> Bool# -> State# d -> (# State# d, Word# #)
go (Word#
w Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
8#) (Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#) State# d
s'
wordToAddrBE# :: Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordToAddrBE# :: forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordToAddrBE# Word#
w Addr#
addr = forall {d}. Bool# -> Bool# -> State# d -> (# State# d, Word# #)
go Bool#
0# (WORD_SIZE_IN_BITS# -# clz)
where
!clz :: Bool#
clz = Word# -> Bool#
word2Int# (Word# -> Word#
clz# Word#
w Word# -> Word# -> Word#
`and#` (Word# -> Word#
not# Word#
0b0111##))
go :: Bool# -> Bool# -> State# d -> (# State# d, Word# #)
go Bool#
c Bool#
sh State# d
s
| Bool#
0# <- Bool#
sh
= (# State# d
s, Bool# -> Word#
int2Word# Bool#
c #)
| Bool
True
, Word8#
w' <- Word# -> Word8#
wordToWord8# (Word#
w Word# -> Bool# -> Word#
`uncheckedShiftRL#` (Bool#
sh Bool# -> Bool# -> Bool#
-# Bool#
8#))
= case forall d. Addr# -> Bool# -> Word8# -> State# d -> State# d
writeWord8OffAddr# Addr#
addr Bool#
c Word8#
w' State# d
s of
State# d
s' -> Bool# -> Bool# -> State# d -> (# State# d, Word# #)
go (Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#) (Bool#
sh Bool# -> Bool# -> Bool#
-# Bool#
8#) State# d
s'
wordToAddr# :: Word# -> Addr# -> Bool# -> State# s -> (# State# s, Word# #)
wordToAddr# :: forall s.
Word# -> Addr# -> Bool# -> State# s -> (# State# s, Word# #)
wordToAddr# Word#
a Addr#
addr Bool#
0# State# s
s = forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordToAddrLE# Word#
a Addr#
addr State# s
s
wordToAddr# Word#
a Addr#
addr Bool#
_ State# s
s = forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordToAddrBE# Word#
a Addr#
addr State# s
s
wordFromAddrLE# :: Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordFromAddrLE# :: forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordFromAddrLE# Word#
n Addr#
addr State# s
s
| WORD_SIZE_IN_BYTES## <- n
= case forall d. Addr# -> Bool# -> State# d -> (# State# d, Word# #)
readWordOffAddr# Addr#
addr Bool#
0# State# s
s of
#if defined(WORDS_BIGENDIAN)
(# s', w #) -> (# s', wordReverseBytes# w #)
#else
(# State# s
s', Word#
w #) -> (# State# s
s', Word#
w #)
#endif
wordFromAddrLE# Word#
n Addr#
addr State# s
s0 = forall {d}. Word# -> Bool# -> State# d -> (# State# d, Word# #)
go Word#
0## Bool#
0# State# s
s0
where
go :: Word# -> Bool# -> State# d -> (# State# d, Word# #)
go Word#
w Bool#
c State# d
s
| Bool# -> Bool
isTrue# (Bool#
c Bool# -> Bool# -> Bool#
==# Word# -> Bool#
word2Int# Word#
n)
= (# State# d
s, Word#
w #)
| Bool
True
= case forall d. Addr# -> Bool# -> State# d -> (# State# d, Word8# #)
readWord8OffAddr# Addr#
addr Bool#
c State# d
s of
(# State# d
s', Word8#
b #) -> Word# -> Bool# -> State# d -> (# State# d, Word# #)
go (Word#
w Word# -> Word# -> Word#
`or#` (Word8# -> Word#
word8ToWord# Word8#
b Word# -> Bool# -> Word#
`uncheckedShiftL#` (Bool#
c Bool# -> Bool# -> Bool#
`uncheckedIShiftL#` Bool#
3#)))
(Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#)
State# d
s'
wordFromAddrBE# :: Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordFromAddrBE# :: forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordFromAddrBE# Word#
n Addr#
addr State# s
s
| WORD_SIZE_IN_BYTES## <- n
= case forall d. Addr# -> Bool# -> State# d -> (# State# d, Word# #)
readWordOffAddr# Addr#
addr Bool#
0# State# s
s of
#if defined(WORDS_BIGENDIAN)
(# s', w #) -> (# s', w #)
#else
(# State# s
s', Word#
w #) -> (# State# s
s', Word# -> Word#
wordReverseBytes# Word#
w #)
#endif
wordFromAddrBE# Word#
n Addr#
addr State# s
s0 = forall {d}. Word# -> Bool# -> State# d -> (# State# d, Word# #)
go Word#
0## Bool#
0# State# s
s0
where
go :: Word# -> Bool# -> State# d -> (# State# d, Word# #)
go Word#
w Bool#
c State# d
s
| Bool# -> Bool
isTrue# (Bool#
c Bool# -> Bool# -> Bool#
==# Word# -> Bool#
word2Int# Word#
n)
= (# State# d
s, Word#
w #)
| Bool
True
= case forall d. Addr# -> Bool# -> State# d -> (# State# d, Word8# #)
readWord8OffAddr# Addr#
addr Bool#
c State# d
s of
(# State# d
s', Word8#
b #) -> Word# -> Bool# -> State# d -> (# State# d, Word# #)
go ((Word#
w Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
8#) Word# -> Word# -> Word#
`or#` Word8# -> Word#
word8ToWord# Word8#
b)
(Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#)
State# d
s'
wordFromAddr# :: Word# -> Addr# -> Bool# -> State# s -> (# State# s, Word# #)
wordFromAddr# :: forall s.
Word# -> Addr# -> Bool# -> State# s -> (# State# s, Word# #)
wordFromAddr# Word#
a Addr#
addr Bool#
0# State# s
s = forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordFromAddrLE# Word#
a Addr#
addr State# s
s
wordFromAddr# Word#
a Addr#
addr Bool#
_ State# s
s = forall s. Word# -> Addr# -> State# s -> (# State# s, Word# #)
wordFromAddrBE# Word#
a Addr#
addr State# s
s
wordWriteAddrLE# :: Word# -> Addr# -> State# s -> State# s
wordWriteAddrLE# :: forall s. Word# -> Addr# -> State# s -> State# s
wordWriteAddrLE# Word#
w Addr#
addr = forall d. Addr# -> Bool# -> Word# -> State# d -> State# d
writeWordOffAddr# Addr#
addr Bool#
0#
#if defined(WORDS_BIGENDIAN)
(wordReverseBytes# w)
#else
Word#
w
#endif
wordWriteAddrBE# :: Word# -> Addr# -> State# s -> State# s
wordWriteAddrBE# :: forall s. Word# -> Addr# -> State# s -> State# s
wordWriteAddrBE# Word#
w Addr#
addr = forall d. Addr# -> Bool# -> Word# -> State# d -> State# d
writeWordOffAddr# Addr#
addr Bool#
0#
#if defined(WORDS_BIGENDIAN)
w
#else
(Word# -> Word#
wordReverseBytes# Word#
w)
#endif
wordToMutableByteArrayLE# :: Word# -> MutableByteArray# s -> Word# -> State# s -> (# State# s, Word# #)
wordToMutableByteArrayLE# :: forall s.
Word#
-> MutableByteArray# s
-> Word#
-> State# s
-> (# State# s, Word# #)
wordToMutableByteArrayLE# Word#
x MutableByteArray# s
mba Word#
off = Word# -> Bool# -> State# s -> (# State# s, Word# #)
go Word#
x Bool#
0#
where
go :: Word# -> Bool# -> State# s -> (# State# s, Word# #)
go Word#
w Bool#
c State# s
s
| Word#
0## <- Word#
w
= (# State# s
s, Bool# -> Word#
int2Word# Bool#
c #)
| Bool
True
= case forall d.
MutableByteArray# d -> Bool# -> Word8# -> State# d -> State# d
writeWord8Array# MutableByteArray# s
mba (Word# -> Bool#
word2Int# Word#
off Bool# -> Bool# -> Bool#
+# Bool#
c) (Word# -> Word8#
wordToWord8# Word#
w) State# s
s of
State# s
s' -> Word# -> Bool# -> State# s -> (# State# s, Word# #)
go (Word#
w Word# -> Bool# -> Word#
`uncheckedShiftRL#` Bool#
8#) (Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#) State# s
s'
wordToMutableByteArrayBE# :: Word# -> MutableByteArray# s -> Word# -> State# s -> (# State# s, Word# #)
wordToMutableByteArrayBE# :: forall s.
Word#
-> MutableByteArray# s
-> Word#
-> State# s
-> (# State# s, Word# #)
wordToMutableByteArrayBE# Word#
w MutableByteArray# s
mba Word#
off = Bool# -> Bool# -> State# s -> (# State# s, Word# #)
go Bool#
0# (WORD_SIZE_IN_BITS# -# clz)
where
!clz :: Bool#
clz = Word# -> Bool#
word2Int# (Word# -> Word#
clz# Word#
w Word# -> Word# -> Word#
`and#` (Word# -> Word#
not# Word#
0b0111##))
go :: Bool# -> Bool# -> State# s -> (# State# s, Word# #)
go Bool#
c Bool#
sh State# s
s
| Bool#
0# <- Bool#
sh
= (# State# s
s, Bool# -> Word#
int2Word# Bool#
c #)
| Bool
True
, Word8#
w' <- Word# -> Word8#
wordToWord8# (Word#
w Word# -> Bool# -> Word#
`uncheckedShiftRL#` (Bool#
sh Bool# -> Bool# -> Bool#
-# Bool#
8#))
= case forall d.
MutableByteArray# d -> Bool# -> Word8# -> State# d -> State# d
writeWord8Array# MutableByteArray# s
mba (Word# -> Bool#
word2Int# Word#
off Bool# -> Bool# -> Bool#
+# Bool#
c) Word8#
w' State# s
s of
State# s
s' -> Bool# -> Bool# -> State# s -> (# State# s, Word# #)
go (Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#) (Bool#
sh Bool# -> Bool# -> Bool#
-# Bool#
8#) State# s
s'
wordToMutableByteArray# :: Word# -> MutableByteArray# s -> Word# -> Bool# -> State# s -> (# State# s, Word# #)
wordToMutableByteArray# :: forall s.
Word#
-> MutableByteArray# s
-> Word#
-> Bool#
-> State# s
-> (# State# s, Word# #)
wordToMutableByteArray# Word#
a MutableByteArray# s
mba Word#
off Bool#
0# State# s
s = forall s.
Word#
-> MutableByteArray# s
-> Word#
-> State# s
-> (# State# s, Word# #)
wordToMutableByteArrayLE# Word#
a MutableByteArray# s
mba Word#
off State# s
s
wordToMutableByteArray# Word#
a MutableByteArray# s
mba Word#
off Bool#
_ State# s
s = forall s.
Word#
-> MutableByteArray# s
-> Word#
-> State# s
-> (# State# s, Word# #)
wordToMutableByteArrayBE# Word#
a MutableByteArray# s
mba Word#
off State# s
s
wordWriteMutableByteArrayLE# :: Word# -> MutableByteArray# s -> Word# -> State# s -> State# s
wordWriteMutableByteArrayLE# :: forall s.
Word# -> MutableByteArray# s -> Word# -> State# s -> State# s
wordWriteMutableByteArrayLE# Word#
w MutableByteArray# s
mba Word#
off = forall d.
MutableByteArray# d -> Bool# -> Word# -> State# d -> State# d
writeWord8ArrayAsWord# MutableByteArray# s
mba (Word# -> Bool#
word2Int# Word#
off)
#if defined(WORDS_BIGENDIAN)
(wordReverseBytes# w)
#else
Word#
w
#endif
wordWriteMutableByteArrayBE# :: Word# -> MutableByteArray# s -> Word# -> State# s -> State# s
wordWriteMutableByteArrayBE# :: forall s.
Word# -> MutableByteArray# s -> Word# -> State# s -> State# s
wordWriteMutableByteArrayBE# Word#
w MutableByteArray# s
mba Word#
off = forall d.
MutableByteArray# d -> Bool# -> Word# -> State# d -> State# d
writeWord8ArrayAsWord# MutableByteArray# s
mba (Word# -> Bool#
word2Int# Word#
off)
#if defined(WORDS_BIGENDIAN)
w
#else
(Word# -> Word#
wordReverseBytes# Word#
w)
#endif
wordFromByteArrayLE# :: Word# -> ByteArray# -> Word# -> Word#
wordFromByteArrayLE# :: Word# -> ByteArray# -> Word# -> Word#
wordFromByteArrayLE# Word#
n ByteArray#
ba Word#
off =
case Word#
n of
WORD_SIZE_IN_BYTES## -> case indexWord8ArrayAsWord# ba (word2Int# off) of
#if defined(WORDS_BIGENDIAN)
w -> wordReverseBytes# w
#else
w -> w
#endif
Word#
_ -> let
go :: Word# -> Bool# -> Word#
go Word#
w Bool#
c
| Bool# -> Bool
isTrue# (Bool#
c Bool# -> Bool# -> Bool#
==# Word# -> Bool#
word2Int# Word#
n)
= Word#
w
| Bool
True
= case ByteArray# -> Bool# -> Word8#
indexWord8Array# ByteArray#
ba (Word# -> Bool#
word2Int# Word#
off Bool# -> Bool# -> Bool#
+# Bool#
c) of
Word8#
b -> Word# -> Bool# -> Word#
go (Word#
w Word# -> Word# -> Word#
`or#` (Word8# -> Word#
word8ToWord# Word8#
b Word# -> Bool# -> Word#
`uncheckedShiftL#` (Bool#
c Bool# -> Bool# -> Bool#
`uncheckedIShiftL#` Bool#
3#)))
(Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#)
in Word# -> Bool# -> Word#
go Word#
0## Bool#
0#
wordFromByteArrayBE# :: Word# -> ByteArray# -> Word# -> Word#
wordFromByteArrayBE# :: Word# -> ByteArray# -> Word# -> Word#
wordFromByteArrayBE# Word#
n ByteArray#
ba Word#
off
| WORD_SIZE_IN_BYTES## <- n
= case ByteArray# -> Bool# -> Word#
indexWord8ArrayAsWord# ByteArray#
ba (Word# -> Bool#
word2Int# Word#
off) of
#if defined(WORDS_BIGENDIAN)
w -> w
#else
Word#
w -> Word# -> Word#
wordReverseBytes# Word#
w
#endif
wordFromByteArrayBE# Word#
n ByteArray#
ba Word#
off = Word# -> Bool# -> Word#
go Word#
0## Bool#
0#
where
go :: Word# -> Bool# -> Word#
go Word#
w Bool#
c
| Bool# -> Bool
isTrue# (Bool#
c Bool# -> Bool# -> Bool#
==# Word# -> Bool#
word2Int# Word#
n)
= Word#
w
| Bool
True
= case ByteArray# -> Bool# -> Word8#
indexWord8Array# ByteArray#
ba (Word# -> Bool#
word2Int# Word#
off Bool# -> Bool# -> Bool#
+# Bool#
c) of
Word8#
b -> Word# -> Bool# -> Word#
go ((Word#
w Word# -> Bool# -> Word#
`uncheckedShiftL#` Bool#
8#) Word# -> Word# -> Word#
`or#` Word8# -> Word#
word8ToWord# Word8#
b) (Bool#
c Bool# -> Bool# -> Bool#
+# Bool#
1#)
wordFromByteArray# :: Word# -> ByteArray# -> Word# -> Bool# -> Word#
wordFromByteArray# :: Word# -> ByteArray# -> Word# -> Bool# -> Word#
wordFromByteArray# Word#
a ByteArray#
ba Word#
off Bool#
0# = Word# -> ByteArray# -> Word# -> Word#
wordFromByteArrayLE# Word#
a ByteArray#
ba Word#
off
wordFromByteArray# Word#
a ByteArray#
ba Word#
off Bool#
_ = Word# -> ByteArray# -> Word# -> Word#
wordFromByteArrayBE# Word#
a ByteArray#
ba Word#
off
ioVoid :: IO a -> State# RealWorld -> State# RealWorld
ioVoid :: forall a. IO a -> State# RealWorld -> State# RealWorld
ioVoid (IO State# RealWorld -> (# State# RealWorld, a #)
io) State# RealWorld
s = case State# RealWorld -> (# State# RealWorld, a #)
io State# RealWorld
s of
(# State# RealWorld
s', a
_ #) -> State# RealWorld
s'
ioWord# :: IO Word -> State# RealWorld -> (# State# RealWorld, Word# #)
ioWord# :: IO Word -> State# RealWorld -> (# State# RealWorld, Word# #)
ioWord# (IO State# RealWorld -> (# State# RealWorld, Word #)
io) State# RealWorld
s = case State# RealWorld -> (# State# RealWorld, Word #)
io State# RealWorld
s of
(# State# RealWorld
s', W# Word#
w #) -> (# State# RealWorld
s', Word#
w #)
ioInt# :: IO Int -> State# RealWorld -> (# State# RealWorld, Int# #)
ioInt# :: IO Int -> State# RealWorld -> (# State# RealWorld, Bool# #)
ioInt# (IO State# RealWorld -> (# State# RealWorld, Int #)
io) State# RealWorld
s = case State# RealWorld -> (# State# RealWorld, Int #)
io State# RealWorld
s of
(# State# RealWorld
s', I# Bool#
i #) -> (# State# RealWorld
s', Bool#
i #)
ioBool :: IO Bool -> State# RealWorld -> (# State# RealWorld, Bool# #)
ioBool :: IO Bool -> State# RealWorld -> (# State# RealWorld, Bool# #)
ioBool (IO State# RealWorld -> (# State# RealWorld, Bool #)
io) State# RealWorld
s = case State# RealWorld -> (# State# RealWorld, Bool #)
io State# RealWorld
s of
(# State# RealWorld
s', Bool
False #) -> (# State# RealWorld
s', Bool#
0# #)
(# State# RealWorld
s', Bool
True #) -> (# State# RealWorld
s', Bool#
1# #)
unexpectedValue_Int# :: (# #) -> Int#
unexpectedValue_Int# :: (# #) -> Bool#
unexpectedValue_Int# (# #)
_ = case forall a. a
unexpectedValue of
!Any
_ -> Bool#
0#
unexpectedValue_Word# :: (# #) -> Word#
unexpectedValue_Word# :: (# #) -> Word#
unexpectedValue_Word# (# #)
_ = case forall a. a
unexpectedValue of
!Any
_ -> Word#
0##
raiseDivZero_Word# :: (# #) -> Word#
raiseDivZero_Word# :: (# #) -> Word#
raiseDivZero_Word# (# #)
_ = case forall a. a
raiseDivZero of
!Any
_ -> Word#
0##
raiseUnderflow_Word# :: (# #) -> Word#
raiseUnderflow_Word# :: (# #) -> Word#
raiseUnderflow_Word# (# #)
_ = case forall a. a
raiseUnderflow of
!Any
_ -> Word#
0##
#if (__GLASGOW_HASKELL__ >= 811)
unexpectedValue :: a
unexpectedValue :: forall a. a
unexpectedValue = forall a. a
raiseOverflow
#else
exception :: a
{-# NOINLINE exception #-}
exception = runRW# \s ->
case atomicLoop s of
(# _, a #) -> a
where
atomicLoop s = atomically# atomicLoop s
raiseUnderflow :: a
raiseUnderflow = exception
raiseDivZero :: a
raiseDivZero = exception
unexpectedValue :: a
unexpectedValue = exception
#endif