{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash, UnboxedTuples #-}
{-# OPTIONS_HADDOCK not-home #-}
#include "MachDeps.h"
module GHC.Word (
Word(..), Word8(..), Word16(..), Word32(..), Word64(..),
uncheckedShiftL64#,
uncheckedShiftRL64#,
byteSwap16,
byteSwap32,
byteSwap64,
bitReverse8,
bitReverse16,
bitReverse32,
bitReverse64,
eqWord, neWord, gtWord, geWord, ltWord, leWord,
eqWord8, neWord8, gtWord8, geWord8, ltWord8, leWord8,
eqWord16, neWord16, gtWord16, geWord16, ltWord16, leWord16,
eqWord32, neWord32, gtWord32, geWord32, ltWord32, leWord32,
eqWord64, neWord64, gtWord64, geWord64, ltWord64, leWord64
) where
import Data.Bits
import Data.Maybe
#if WORD_SIZE_IN_BITS < 64
import GHC.IntWord64
#endif
import GHC.Base
import GHC.Enum
import GHC.Num
import GHC.Real
import GHC.Ix
import GHC.Show
data {-# CTYPE "HsWord8" #-} Word8 = W8# Word#
instance Eq Word8 where
== :: Word8 -> Word8 -> Bool
(==) = Word8 -> Word8 -> Bool
eqWord8
/= :: Word8 -> Word8 -> Bool
(/=) = Word8 -> Word8 -> Bool
neWord8
eqWord8, neWord8 :: Word8 -> Word8 -> Bool
eqWord8 :: Word8 -> Word8 -> Bool
eqWord8 (W8# Word#
x) (W8# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord8 :: Word8 -> Word8 -> Bool
neWord8 (W8# Word#
x) (W8# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord8 #-}
{-# INLINE [1] neWord8 #-}
instance Ord Word8 where
< :: Word8 -> Word8 -> Bool
(<) = Word8 -> Word8 -> Bool
ltWord8
<= :: Word8 -> Word8 -> Bool
(<=) = Word8 -> Word8 -> Bool
leWord8
>= :: Word8 -> Word8 -> Bool
(>=) = Word8 -> Word8 -> Bool
geWord8
> :: Word8 -> Word8 -> Bool
(>) = Word8 -> Word8 -> Bool
gtWord8
{-# INLINE [1] gtWord8 #-}
{-# INLINE [1] geWord8 #-}
{-# INLINE [1] ltWord8 #-}
{-# INLINE [1] leWord8 #-}
gtWord8, geWord8, ltWord8, leWord8 :: Word8 -> Word8 -> Bool
(W8# Word#
x) gtWord8 :: Word8 -> Word8 -> Bool
`gtWord8` (W8# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W8# Word#
x) geWord8 :: Word8 -> Word8 -> Bool
`geWord8` (W8# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W8# Word#
x) ltWord8 :: Word8 -> Word8 -> Bool
`ltWord8` (W8# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W8# Word#
x) leWord8 :: Word8 -> Word8 -> Bool
`leWord8` (W8# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)
instance Show Word8 where
showsPrec :: Int -> Word8 -> ShowS
showsPrec Int
p Word8
x = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
x :: Int)
instance Num Word8 where
(W8# Word#
x#) + :: Word8 -> Word8 -> Word8
+ (W8# Word#
y#) = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#))
(W8# Word#
x#) - :: Word8 -> Word8 -> Word8
- (W8# Word#
y#) = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#))
(W8# Word#
x#) * :: Word8 -> Word8 -> Word8
* (W8# Word#
y#) = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#))
negate :: Word8 -> Word8
negate (W8# Word#
x#) = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#))))
abs :: Word8 -> Word8
abs Word8
x = Word8
x
signum :: Word8 -> Word8
signum Word8
0 = Word8
0
signum Word8
_ = Word8
1
fromInteger :: Integer -> Word8
fromInteger Integer
i = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Integer -> Word#
integerToWord Integer
i))
instance Real Word8 where
toRational :: Word8 -> Rational
toRational Word8
x = Word8 -> Integer
forall a. Integral a => a -> Integer
toInteger Word8
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
1
instance Enum Word8 where
succ :: Word8 -> Word8
succ Word8
x
| Word8
x Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
forall a. Bounded a => a
maxBound = Word8
x Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
1
| Bool
otherwise = String -> Word8
forall a. String -> a
succError String
"Word8"
pred :: Word8 -> Word8
pred Word8
x
| Word8
x Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
forall a. Bounded a => a
minBound = Word8
x Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
1
| Bool
otherwise = String -> Word8
forall a. String -> a
predError String
"Word8"
toEnum :: Int -> Word8
toEnum i :: Int
i@(I# Int#
i#)
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
forall a. Bounded a => a
maxBound::Word8)
= Word# -> Word8
W8# (Int# -> Word#
int2Word# Int#
i#)
| Bool
otherwise = String -> Int -> (Word8, Word8) -> Word8
forall a b. Show a => String -> Int -> (a, a) -> b
toEnumError String
"Word8" Int
i (Word8
forall a. Bounded a => a
minBound::Word8, Word8
forall a. Bounded a => a
maxBound::Word8)
fromEnum :: Word8 -> Int
fromEnum (W8# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# Word#
x#)
enumFrom :: Word8 -> [Word8]
enumFrom = Word8 -> [Word8]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
enumFromThen :: Word8 -> Word8 -> [Word8]
enumFromThen = Word8 -> Word8 -> [Word8]
forall a. (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen
instance Integral Word8 where
quot :: Word8 -> Word8 -> Word8
quot (W8# Word#
x#) y :: Word8
y@(W8# Word#
y#)
| Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0 = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word8
forall a. a
divZeroError
rem :: Word8 -> Word8 -> Word8
rem (W8# Word#
x#) y :: Word8
y@(W8# Word#
y#)
| Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0 = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word8
forall a. a
divZeroError
div :: Word8 -> Word8 -> Word8
div (W8# Word#
x#) y :: Word8
y@(W8# Word#
y#)
| Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0 = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word8
forall a. a
divZeroError
mod :: Word8 -> Word8 -> Word8
mod (W8# Word#
x#) y :: Word8
y@(W8# Word#
y#)
| Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0 = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word8
forall a. a
divZeroError
quotRem :: Word8 -> Word8 -> (Word8, Word8)
quotRem (W8# Word#
x#) y :: Word8
y@(W8# Word#
y#)
| Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0 = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
(# Word#
q, Word#
r #) ->
(Word# -> Word8
W8# Word#
q, Word# -> Word8
W8# Word#
r)
| Bool
otherwise = (Word8, Word8)
forall a. a
divZeroError
divMod :: Word8 -> Word8 -> (Word8, Word8)
divMod (W8# Word#
x#) y :: Word8
y@(W8# Word#
y#)
| Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0 = (Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#), Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#))
| Bool
otherwise = (Word8, Word8)
forall a. a
divZeroError
toInteger :: Word8 -> Integer
toInteger (W8# Word#
x#) = Int# -> Integer
smallInteger (Word# -> Int#
word2Int# Word#
x#)
instance Bounded Word8 where
minBound :: Word8
minBound = Word8
0
maxBound :: Word8
maxBound = Word8
0xFF
instance Ix Word8 where
range :: (Word8, Word8) -> [Word8]
range (Word8
m,Word8
n) = [Word8
m..Word8
n]
unsafeIndex :: (Word8, Word8) -> Word8 -> Int
unsafeIndex (Word8
m,Word8
_) Word8
i = Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
i Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
m)
inRange :: (Word8, Word8) -> Word8 -> Bool
inRange (Word8
m,Word8
n) Word8
i = Word8
m Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
i Bool -> Bool -> Bool
&& Word8
i Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
n
instance Bits Word8 where
{-# INLINE shift #-}
{-# INLINE bit #-}
{-# INLINE testBit #-}
{-# INLINE popCount #-}
(W8# Word#
x#) .&. :: Word8 -> Word8 -> Word8
.&. (W8# Word#
y#) = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
(W8# Word#
x#) .|. :: Word8 -> Word8 -> Word8
.|. (W8# Word#
y#) = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`or#` Word#
y#)
(W8# Word#
x#) xor :: Word8 -> Word8 -> Word8
`xor` (W8# Word#
y#) = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
complement :: Word8 -> Word8
complement (W8# Word#
x#) = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
where !(W8# Word#
mb#) = Word8
forall a. Bounded a => a
maxBound
(W8# Word#
x#) shift :: Word8 -> Int -> Word8
`shift` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#))
| Bool
otherwise = Word# -> Word8
W8# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int# -> Int#
negateInt# Int#
i#)
(W8# Word#
x#) shiftL :: Word8 -> Int -> Word8
`shiftL` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#))
| Bool
otherwise = Word8
forall a. a
overflowError
(W8# Word#
x#) unsafeShiftL :: Word8 -> Int -> Word8
`unsafeShiftL` (I# Int#
i#) =
Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#))
(W8# Word#
x#) shiftR :: Word8 -> Int -> Word8
`shiftR` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word8
W8# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
| Bool
otherwise = Word8
forall a. a
overflowError
(W8# Word#
x#) unsafeShiftR :: Word8 -> Int -> Word8
`unsafeShiftR` (I# Int#
i#) = Word# -> Word8
W8# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
(W8# Word#
x#) rotate :: Word8 -> Int -> Word8
`rotate` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word# -> Word8
W8# Word#
x#
| Bool
otherwise = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# ((Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
(Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` (Int#
8# Int# -> Int# -> Int#
-# Int#
i'#))))
where
!i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` Word#
7##)
bitSizeMaybe :: Word8 -> Maybe Int
bitSizeMaybe Word8
i = Int -> Maybe Int
forall a. a -> Maybe a
Just (Word8 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word8
i)
bitSize :: Word8 -> Int
bitSize Word8
i = Word8 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word8
i
isSigned :: Word8 -> Bool
isSigned Word8
_ = Bool
False
popCount :: Word8 -> Int
popCount (W8# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt8# Word#
x#))
bit :: Int -> Word8
bit = Int -> Word8
forall a. (Bits a, Num a) => Int -> a
bitDefault
testBit :: Word8 -> Int -> Bool
testBit = Word8 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault
instance FiniteBits Word8 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize :: Word8 -> Int
finiteBitSize Word8
_ = Int
8
countLeadingZeros :: Word8 -> Int
countLeadingZeros (W8# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz8# Word#
x#))
countTrailingZeros :: Word8 -> Int
countTrailingZeros (W8# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz8# Word#
x#))
{-# RULES
"fromIntegral/Word8->Word8" fromIntegral = id :: Word8 -> Word8
"fromIntegral/Word8->Integer" fromIntegral = toInteger :: Word8 -> Integer
"fromIntegral/a->Word8" fromIntegral = \x -> case fromIntegral x of W# x# -> W8# (narrow8Word# x#)
"fromIntegral/Word8->a" fromIntegral = \(W8# x#) -> fromIntegral (W# x#)
#-}
{-# RULES
"properFraction/Float->(Word8,Float)"
properFraction = \x ->
case properFraction x of {
(n, y) -> ((fromIntegral :: Int -> Word8) n, y :: Float) }
"truncate/Float->Word8"
truncate = (fromIntegral :: Int -> Word8) . (truncate :: Float -> Int)
"floor/Float->Word8"
floor = (fromIntegral :: Int -> Word8) . (floor :: Float -> Int)
"ceiling/Float->Word8"
ceiling = (fromIntegral :: Int -> Word8) . (ceiling :: Float -> Int)
"round/Float->Word8"
round = (fromIntegral :: Int -> Word8) . (round :: Float -> Int)
#-}
{-# RULES
"properFraction/Double->(Word8,Double)"
properFraction = \x ->
case properFraction x of {
(n, y) -> ((fromIntegral :: Int -> Word8) n, y :: Double) }
"truncate/Double->Word8"
truncate = (fromIntegral :: Int -> Word8) . (truncate :: Double -> Int)
"floor/Double->Word8"
floor = (fromIntegral :: Int -> Word8) . (floor :: Double -> Int)
"ceiling/Double->Word8"
ceiling = (fromIntegral :: Int -> Word8) . (ceiling :: Double -> Int)
"round/Double->Word8"
round = (fromIntegral :: Int -> Word8) . (round :: Double -> Int)
#-}
data {-# CTYPE "HsWord16" #-} Word16 = W16# Word#
instance Eq Word16 where
== :: Word16 -> Word16 -> Bool
(==) = Word16 -> Word16 -> Bool
eqWord16
/= :: Word16 -> Word16 -> Bool
(/=) = Word16 -> Word16 -> Bool
neWord16
eqWord16, neWord16 :: Word16 -> Word16 -> Bool
eqWord16 :: Word16 -> Word16 -> Bool
eqWord16 (W16# Word#
x) (W16# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord16 :: Word16 -> Word16 -> Bool
neWord16 (W16# Word#
x) (W16# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord16 #-}
{-# INLINE [1] neWord16 #-}
instance Ord Word16 where
< :: Word16 -> Word16 -> Bool
(<) = Word16 -> Word16 -> Bool
ltWord16
<= :: Word16 -> Word16 -> Bool
(<=) = Word16 -> Word16 -> Bool
leWord16
>= :: Word16 -> Word16 -> Bool
(>=) = Word16 -> Word16 -> Bool
geWord16
> :: Word16 -> Word16 -> Bool
(>) = Word16 -> Word16 -> Bool
gtWord16
{-# INLINE [1] gtWord16 #-}
{-# INLINE [1] geWord16 #-}
{-# INLINE [1] ltWord16 #-}
{-# INLINE [1] leWord16 #-}
gtWord16, geWord16, ltWord16, leWord16 :: Word16 -> Word16 -> Bool
(W16# Word#
x) gtWord16 :: Word16 -> Word16 -> Bool
`gtWord16` (W16# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W16# Word#
x) geWord16 :: Word16 -> Word16 -> Bool
`geWord16` (W16# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W16# Word#
x) ltWord16 :: Word16 -> Word16 -> Bool
`ltWord16` (W16# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W16# Word#
x) leWord16 :: Word16 -> Word16 -> Bool
`leWord16` (W16# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)
instance Show Word16 where
showsPrec :: Int -> Word16 -> ShowS
showsPrec Int
p Word16
x = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
x :: Int)
instance Num Word16 where
(W16# Word#
x#) + :: Word16 -> Word16 -> Word16
+ (W16# Word#
y#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#))
(W16# Word#
x#) - :: Word16 -> Word16 -> Word16
- (W16# Word#
y#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#))
(W16# Word#
x#) * :: Word16 -> Word16 -> Word16
* (W16# Word#
y#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#))
negate :: Word16 -> Word16
negate (W16# Word#
x#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#))))
abs :: Word16 -> Word16
abs Word16
x = Word16
x
signum :: Word16 -> Word16
signum Word16
0 = Word16
0
signum Word16
_ = Word16
1
fromInteger :: Integer -> Word16
fromInteger Integer
i = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Integer -> Word#
integerToWord Integer
i))
instance Real Word16 where
toRational :: Word16 -> Rational
toRational Word16
x = Word16 -> Integer
forall a. Integral a => a -> Integer
toInteger Word16
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
1
instance Enum Word16 where
succ :: Word16 -> Word16
succ Word16
x
| Word16
x Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
forall a. Bounded a => a
maxBound = Word16
x Word16 -> Word16 -> Word16
forall a. Num a => a -> a -> a
+ Word16
1
| Bool
otherwise = String -> Word16
forall a. String -> a
succError String
"Word16"
pred :: Word16 -> Word16
pred Word16
x
| Word16
x Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
forall a. Bounded a => a
minBound = Word16
x Word16 -> Word16 -> Word16
forall a. Num a => a -> a -> a
- Word16
1
| Bool
otherwise = String -> Word16
forall a. String -> a
predError String
"Word16"
toEnum :: Int -> Word16
toEnum i :: Int
i@(I# Int#
i#)
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16
forall a. Bounded a => a
maxBound::Word16)
= Word# -> Word16
W16# (Int# -> Word#
int2Word# Int#
i#)
| Bool
otherwise = String -> Int -> (Word16, Word16) -> Word16
forall a b. Show a => String -> Int -> (a, a) -> b
toEnumError String
"Word16" Int
i (Word16
forall a. Bounded a => a
minBound::Word16, Word16
forall a. Bounded a => a
maxBound::Word16)
fromEnum :: Word16 -> Int
fromEnum (W16# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# Word#
x#)
enumFrom :: Word16 -> [Word16]
enumFrom = Word16 -> [Word16]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
enumFromThen :: Word16 -> Word16 -> [Word16]
enumFromThen = Word16 -> Word16 -> [Word16]
forall a. (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen
instance Integral Word16 where
quot :: Word16 -> Word16 -> Word16
quot (W16# Word#
x#) y :: Word16
y@(W16# Word#
y#)
| Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0 = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word16
forall a. a
divZeroError
rem :: Word16 -> Word16 -> Word16
rem (W16# Word#
x#) y :: Word16
y@(W16# Word#
y#)
| Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0 = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word16
forall a. a
divZeroError
div :: Word16 -> Word16 -> Word16
div (W16# Word#
x#) y :: Word16
y@(W16# Word#
y#)
| Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0 = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word16
forall a. a
divZeroError
mod :: Word16 -> Word16 -> Word16
mod (W16# Word#
x#) y :: Word16
y@(W16# Word#
y#)
| Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0 = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word16
forall a. a
divZeroError
quotRem :: Word16 -> Word16 -> (Word16, Word16)
quotRem (W16# Word#
x#) y :: Word16
y@(W16# Word#
y#)
| Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0 = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
(# Word#
q, Word#
r #) ->
(Word# -> Word16
W16# Word#
q, Word# -> Word16
W16# Word#
r)
| Bool
otherwise = (Word16, Word16)
forall a. a
divZeroError
divMod :: Word16 -> Word16 -> (Word16, Word16)
divMod (W16# Word#
x#) y :: Word16
y@(W16# Word#
y#)
| Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0 = (Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#), Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#))
| Bool
otherwise = (Word16, Word16)
forall a. a
divZeroError
toInteger :: Word16 -> Integer
toInteger (W16# Word#
x#) = Int# -> Integer
smallInteger (Word# -> Int#
word2Int# Word#
x#)
instance Bounded Word16 where
minBound :: Word16
minBound = Word16
0
maxBound :: Word16
maxBound = Word16
0xFFFF
instance Ix Word16 where
range :: (Word16, Word16) -> [Word16]
range (Word16
m,Word16
n) = [Word16
m..Word16
n]
unsafeIndex :: (Word16, Word16) -> Word16 -> Int
unsafeIndex (Word16
m,Word16
_) Word16
i = Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16
i Word16 -> Word16 -> Word16
forall a. Num a => a -> a -> a
- Word16
m)
inRange :: (Word16, Word16) -> Word16 -> Bool
inRange (Word16
m,Word16
n) Word16
i = Word16
m Word16 -> Word16 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word16
i Bool -> Bool -> Bool
&& Word16
i Word16 -> Word16 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word16
n
instance Bits Word16 where
{-# INLINE shift #-}
{-# INLINE bit #-}
{-# INLINE testBit #-}
{-# INLINE popCount #-}
(W16# Word#
x#) .&. :: Word16 -> Word16 -> Word16
.&. (W16# Word#
y#) = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
(W16# Word#
x#) .|. :: Word16 -> Word16 -> Word16
.|. (W16# Word#
y#) = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`or#` Word#
y#)
(W16# Word#
x#) xor :: Word16 -> Word16 -> Word16
`xor` (W16# Word#
y#) = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
complement :: Word16 -> Word16
complement (W16# Word#
x#) = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
where !(W16# Word#
mb#) = Word16
forall a. Bounded a => a
maxBound
(W16# Word#
x#) shift :: Word16 -> Int -> Word16
`shift` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#))
| Bool
otherwise = Word# -> Word16
W16# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int# -> Int#
negateInt# Int#
i#)
(W16# Word#
x#) shiftL :: Word16 -> Int -> Word16
`shiftL` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#))
| Bool
otherwise = Word16
forall a. a
overflowError
(W16# Word#
x#) unsafeShiftL :: Word16 -> Int -> Word16
`unsafeShiftL` (I# Int#
i#) =
Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#))
(W16# Word#
x#) shiftR :: Word16 -> Int -> Word16
`shiftR` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word16
W16# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
| Bool
otherwise = Word16
forall a. a
overflowError
(W16# Word#
x#) unsafeShiftR :: Word16 -> Int -> Word16
`unsafeShiftR` (I# Int#
i#) = Word# -> Word16
W16# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
(W16# Word#
x#) rotate :: Word16 -> Int -> Word16
`rotate` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word# -> Word16
W16# Word#
x#
| Bool
otherwise = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# ((Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
(Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` (Int#
16# Int# -> Int# -> Int#
-# Int#
i'#))))
where
!i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` Word#
15##)
bitSizeMaybe :: Word16 -> Maybe Int
bitSizeMaybe Word16
i = Int -> Maybe Int
forall a. a -> Maybe a
Just (Word16 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word16
i)
bitSize :: Word16 -> Int
bitSize Word16
i = Word16 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word16
i
isSigned :: Word16 -> Bool
isSigned Word16
_ = Bool
False
popCount :: Word16 -> Int
popCount (W16# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt16# Word#
x#))
bit :: Int -> Word16
bit = Int -> Word16
forall a. (Bits a, Num a) => Int -> a
bitDefault
testBit :: Word16 -> Int -> Bool
testBit = Word16 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault
instance FiniteBits Word16 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize :: Word16 -> Int
finiteBitSize Word16
_ = Int
16
countLeadingZeros :: Word16 -> Int
countLeadingZeros (W16# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz16# Word#
x#))
countTrailingZeros :: Word16 -> Int
countTrailingZeros (W16# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz16# Word#
x#))
byteSwap16 :: Word16 -> Word16
byteSwap16 :: Word16 -> Word16
byteSwap16 (W16# Word#
w#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word# -> Word#
byteSwap16# Word#
w#))
{-# RULES
"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# x#
"fromIntegral/Word16->Word16" fromIntegral = id :: Word16 -> Word16
"fromIntegral/Word16->Integer" fromIntegral = toInteger :: Word16 -> Integer
"fromIntegral/a->Word16" fromIntegral = \x -> case fromIntegral x of W# x# -> W16# (narrow16Word# x#)
"fromIntegral/Word16->a" fromIntegral = \(W16# x#) -> fromIntegral (W# x#)
#-}
{-# RULES
"properFraction/Float->(Word16,Float)"
properFraction = \x ->
case properFraction x of {
(n, y) -> ((fromIntegral :: Int -> Word16) n, y :: Float) }
"truncate/Float->Word16"
truncate = (fromIntegral :: Int -> Word16) . (truncate :: Float -> Int)
"floor/Float->Word16"
floor = (fromIntegral :: Int -> Word16) . (floor :: Float -> Int)
"ceiling/Float->Word16"
ceiling = (fromIntegral :: Int -> Word16) . (ceiling :: Float -> Int)
"round/Float->Word16"
round = (fromIntegral :: Int -> Word16) . (round :: Float -> Int)
#-}
{-# RULES
"properFraction/Double->(Word16,Double)"
properFraction = \x ->
case properFraction x of {
(n, y) -> ((fromIntegral :: Int -> Word16) n, y :: Double) }
"truncate/Double->Word16"
truncate = (fromIntegral :: Int -> Word16) . (truncate :: Double -> Int)
"floor/Double->Word16"
floor = (fromIntegral :: Int -> Word16) . (floor :: Double -> Int)
"ceiling/Double->Word16"
ceiling = (fromIntegral :: Int -> Word16) . (ceiling :: Double -> Int)
"round/Double->Word16"
round = (fromIntegral :: Int -> Word16) . (round :: Double -> Int)
#-}
#if WORD_SIZE_IN_BITS > 32
{-# RULES
"properFraction/Float->(Word32,Float)"
properFraction = \x ->
case properFraction x of {
(n, y) -> ((fromIntegral :: Int -> Word32) n, y :: Float) }
"truncate/Float->Word32"
truncate = (fromIntegral :: Int -> Word32) . (truncate :: Float -> Int)
"floor/Float->Word32"
floor = (fromIntegral :: Int -> Word32) . (floor :: Float -> Int)
"ceiling/Float->Word32"
ceiling = (fromIntegral :: Int -> Word32) . (ceiling :: Float -> Int)
"round/Float->Word32"
round = (fromIntegral :: Int -> Word32) . (round :: Float -> Int)
#-}
{-# RULES
"properFraction/Double->(Word32,Double)"
properFraction = \x ->
case properFraction x of {
(n, y) -> ((fromIntegral :: Int -> Word32) n, y :: Double) }
"truncate/Double->Word32"
truncate = (fromIntegral :: Int -> Word32) . (truncate :: Double -> Int)
"floor/Double->Word32"
floor = (fromIntegral :: Int -> Word32) . (floor :: Double -> Int)
"ceiling/Double->Word32"
ceiling = (fromIntegral :: Int -> Word32) . (ceiling :: Double -> Int)
"round/Double->Word32"
round = (fromIntegral :: Int -> Word32) . (round :: Double -> Int)
#-}
#endif
data {-# CTYPE "HsWord32" #-} Word32 = W32# Word#
instance Eq Word32 where
== :: Word32 -> Word32 -> Bool
(==) = Word32 -> Word32 -> Bool
eqWord32
/= :: Word32 -> Word32 -> Bool
(/=) = Word32 -> Word32 -> Bool
neWord32
eqWord32, neWord32 :: Word32 -> Word32 -> Bool
eqWord32 :: Word32 -> Word32 -> Bool
eqWord32 (W32# Word#
x) (W32# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord32 :: Word32 -> Word32 -> Bool
neWord32 (W32# Word#
x) (W32# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord32 #-}
{-# INLINE [1] neWord32 #-}
instance Ord Word32 where
< :: Word32 -> Word32 -> Bool
(<) = Word32 -> Word32 -> Bool
ltWord32
<= :: Word32 -> Word32 -> Bool
(<=) = Word32 -> Word32 -> Bool
leWord32
>= :: Word32 -> Word32 -> Bool
(>=) = Word32 -> Word32 -> Bool
geWord32
> :: Word32 -> Word32 -> Bool
(>) = Word32 -> Word32 -> Bool
gtWord32
{-# INLINE [1] gtWord32 #-}
{-# INLINE [1] geWord32 #-}
{-# INLINE [1] ltWord32 #-}
{-# INLINE [1] leWord32 #-}
gtWord32, geWord32, ltWord32, leWord32 :: Word32 -> Word32 -> Bool
(W32# Word#
x) gtWord32 :: Word32 -> Word32 -> Bool
`gtWord32` (W32# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W32# Word#
x) geWord32 :: Word32 -> Word32 -> Bool
`geWord32` (W32# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W32# Word#
x) ltWord32 :: Word32 -> Word32 -> Bool
`ltWord32` (W32# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W32# Word#
x) leWord32 :: Word32 -> Word32 -> Bool
`leWord32` (W32# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)
instance Num Word32 where
(W32# Word#
x#) + :: Word32 -> Word32 -> Word32
+ (W32# Word#
y#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#))
(W32# Word#
x#) - :: Word32 -> Word32 -> Word32
- (W32# Word#
y#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#))
(W32# Word#
x#) * :: Word32 -> Word32 -> Word32
* (W32# Word#
y#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#))
negate :: Word32 -> Word32
negate (W32# Word#
x#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#))))
abs :: Word32 -> Word32
abs Word32
x = Word32
x
signum :: Word32 -> Word32
signum Word32
0 = Word32
0
signum Word32
_ = Word32
1
fromInteger :: Integer -> Word32
fromInteger Integer
i = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Integer -> Word#
integerToWord Integer
i))
instance Enum Word32 where
succ :: Word32 -> Word32
succ Word32
x
| Word32
x Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
forall a. Bounded a => a
maxBound = Word32
x Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
1
| Bool
otherwise = String -> Word32
forall a. String -> a
succError String
"Word32"
pred :: Word32 -> Word32
pred Word32
x
| Word32
x Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
forall a. Bounded a => a
minBound = Word32
x Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
1
| Bool
otherwise = String -> Word32
forall a. String -> a
predError String
"Word32"
toEnum :: Int -> Word32
toEnum i :: Int
i@(I# Int#
i#)
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0
#if WORD_SIZE_IN_BITS > 32
Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
forall a. Bounded a => a
maxBound::Word32)
#endif
= Word# -> Word32
W32# (Int# -> Word#
int2Word# Int#
i#)
| Bool
otherwise = String -> Int -> (Word32, Word32) -> Word32
forall a b. Show a => String -> Int -> (a, a) -> b
toEnumError String
"Word32" Int
i (Word32
forall a. Bounded a => a
minBound::Word32, Word32
forall a. Bounded a => a
maxBound::Word32)
#if WORD_SIZE_IN_BITS == 32
fromEnum x@(W32# x#)
| x <= fromIntegral (maxBound::Int)
= I# (word2Int# x#)
| otherwise = fromEnumError "Word32" x
enumFrom = integralEnumFrom
enumFromThen = integralEnumFromThen
enumFromTo = integralEnumFromTo
enumFromThenTo = integralEnumFromThenTo
#else
fromEnum :: Word32 -> Int
fromEnum (W32# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# Word#
x#)
enumFrom :: Word32 -> [Word32]
enumFrom = Word32 -> [Word32]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
enumFromThen :: Word32 -> Word32 -> [Word32]
enumFromThen = Word32 -> Word32 -> [Word32]
forall a. (Enum a, Bounded a) => a -> a -> [a]
boundedEnumFromThen
#endif
instance Integral Word32 where
quot :: Word32 -> Word32 -> Word32
quot (W32# Word#
x#) y :: Word32
y@(W32# Word#
y#)
| Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0 = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word32
forall a. a
divZeroError
rem :: Word32 -> Word32 -> Word32
rem (W32# Word#
x#) y :: Word32
y@(W32# Word#
y#)
| Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0 = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word32
forall a. a
divZeroError
div :: Word32 -> Word32 -> Word32
div (W32# Word#
x#) y :: Word32
y@(W32# Word#
y#)
| Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0 = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word32
forall a. a
divZeroError
mod :: Word32 -> Word32 -> Word32
mod (W32# Word#
x#) y :: Word32
y@(W32# Word#
y#)
| Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0 = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word32
forall a. a
divZeroError
quotRem :: Word32 -> Word32 -> (Word32, Word32)
quotRem (W32# Word#
x#) y :: Word32
y@(W32# Word#
y#)
| Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0 = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
(# Word#
q, Word#
r #) ->
(Word# -> Word32
W32# Word#
q, Word# -> Word32
W32# Word#
r)
| Bool
otherwise = (Word32, Word32)
forall a. a
divZeroError
divMod :: Word32 -> Word32 -> (Word32, Word32)
divMod (W32# Word#
x#) y :: Word32
y@(W32# Word#
y#)
| Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0 = (Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#), Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#))
| Bool
otherwise = (Word32, Word32)
forall a. a
divZeroError
toInteger :: Word32 -> Integer
toInteger (W32# Word#
x#)
#if WORD_SIZE_IN_BITS == 32
| isTrue# (i# >=# 0#) = smallInteger i#
| otherwise = wordToInteger x#
where
!i# = word2Int# x#
#else
= Int# -> Integer
smallInteger (Word# -> Int#
word2Int# Word#
x#)
#endif
instance Bits Word32 where
{-# INLINE shift #-}
{-# INLINE bit #-}
{-# INLINE testBit #-}
{-# INLINE popCount #-}
(W32# Word#
x#) .&. :: Word32 -> Word32 -> Word32
.&. (W32# Word#
y#) = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
(W32# Word#
x#) .|. :: Word32 -> Word32 -> Word32
.|. (W32# Word#
y#) = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`or#` Word#
y#)
(W32# Word#
x#) xor :: Word32 -> Word32 -> Word32
`xor` (W32# Word#
y#) = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
complement :: Word32 -> Word32
complement (W32# Word#
x#) = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
where !(W32# Word#
mb#) = Word32
forall a. Bounded a => a
maxBound
(W32# Word#
x#) shift :: Word32 -> Int -> Word32
`shift` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#))
| Bool
otherwise = Word# -> Word32
W32# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int# -> Int#
negateInt# Int#
i#)
(W32# Word#
x#) shiftL :: Word32 -> Int -> Word32
`shiftL` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#))
| Bool
otherwise = Word32
forall a. a
overflowError
(W32# Word#
x#) unsafeShiftL :: Word32 -> Int -> Word32
`unsafeShiftL` (I# Int#
i#) =
Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#))
(W32# Word#
x#) shiftR :: Word32 -> Int -> Word32
`shiftR` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word32
W32# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
| Bool
otherwise = Word32
forall a. a
overflowError
(W32# Word#
x#) unsafeShiftR :: Word32 -> Int -> Word32
`unsafeShiftR` (I# Int#
i#) = Word# -> Word32
W32# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
(W32# Word#
x#) rotate :: Word32 -> Int -> Word32
`rotate` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word# -> Word32
W32# Word#
x#
| Bool
otherwise = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# ((Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
(Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` (Int#
32# Int# -> Int# -> Int#
-# Int#
i'#))))
where
!i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` Word#
31##)
bitSizeMaybe :: Word32 -> Maybe Int
bitSizeMaybe Word32
i = Int -> Maybe Int
forall a. a -> Maybe a
Just (Word32 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word32
i)
bitSize :: Word32 -> Int
bitSize Word32
i = Word32 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word32
i
isSigned :: Word32 -> Bool
isSigned Word32
_ = Bool
False
popCount :: Word32 -> Int
popCount (W32# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt32# Word#
x#))
bit :: Int -> Word32
bit = Int -> Word32
forall a. (Bits a, Num a) => Int -> a
bitDefault
testBit :: Word32 -> Int -> Bool
testBit = Word32 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault
instance FiniteBits Word32 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize :: Word32 -> Int
finiteBitSize Word32
_ = Int
32
countLeadingZeros :: Word32 -> Int
countLeadingZeros (W32# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz32# Word#
x#))
countTrailingZeros :: Word32 -> Int
countTrailingZeros (W32# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz32# Word#
x#))
{-# RULES
"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# x#
"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# x#
"fromIntegral/Word32->Word32" fromIntegral = id :: Word32 -> Word32
"fromIntegral/Word32->Integer" fromIntegral = toInteger :: Word32 -> Integer
"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (narrow32Word# x#)
"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# x#)
#-}
instance Show Word32 where
#if WORD_SIZE_IN_BITS < 33
showsPrec p x = showsPrec p (toInteger x)
#else
showsPrec :: Int -> Word32 -> ShowS
showsPrec Int
p Word32
x = Int -> Int -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
x :: Int)
#endif
instance Real Word32 where
toRational :: Word32 -> Rational
toRational Word32
x = Word32 -> Integer
forall a. Integral a => a -> Integer
toInteger Word32
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
1
instance Bounded Word32 where
minBound :: Word32
minBound = Word32
0
maxBound :: Word32
maxBound = Word32
0xFFFFFFFF
instance Ix Word32 where
range :: (Word32, Word32) -> [Word32]
range (Word32
m,Word32
n) = [Word32
m..Word32
n]
unsafeIndex :: (Word32, Word32) -> Word32 -> Int
unsafeIndex (Word32
m,Word32
_) Word32
i = Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32
i Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
m)
inRange :: (Word32, Word32) -> Word32 -> Bool
inRange (Word32
m,Word32
n) Word32
i = Word32
m Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word32
i Bool -> Bool -> Bool
&& Word32
i Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word32
n
byteSwap32 :: Word32 -> Word32
byteSwap32 :: Word32 -> Word32
byteSwap32 (W32# Word#
w#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word# -> Word#
byteSwap32# Word#
w#))
#if WORD_SIZE_IN_BITS < 64
data {-# CTYPE "HsWord64" #-} Word64 = W64# Word64#
instance Eq Word64 where
(==) = eqWord64
(/=) = neWord64
eqWord64, neWord64 :: Word64 -> Word64 -> Bool
eqWord64 (W64# x) (W64# y) = isTrue# (x `eqWord64#` y)
neWord64 (W64# x) (W64# y) = isTrue# (x `neWord64#` y)
{-# INLINE [1] eqWord64 #-}
{-# INLINE [1] neWord64 #-}
instance Ord Word64 where
(<) = ltWord64
(<=) = leWord64
(>=) = geWord64
(>) = gtWord64
{-# INLINE [1] gtWord64 #-}
{-# INLINE [1] geWord64 #-}
{-# INLINE [1] ltWord64 #-}
{-# INLINE [1] leWord64 #-}
gtWord64, geWord64, ltWord64, leWord64 :: Word64 -> Word64 -> Bool
(W64# x) `gtWord64` (W64# y) = isTrue# (x `gtWord64#` y)
(W64# x) `geWord64` (W64# y) = isTrue# (x `geWord64#` y)
(W64# x) `ltWord64` (W64# y) = isTrue# (x `ltWord64#` y)
(W64# x) `leWord64` (W64# y) = isTrue# (x `leWord64#` y)
instance Num Word64 where
(W64# x#) + (W64# y#) = W64# (int64ToWord64# (word64ToInt64# x# `plusInt64#` word64ToInt64# y#))
(W64# x#) - (W64# y#) = W64# (int64ToWord64# (word64ToInt64# x# `minusInt64#` word64ToInt64# y#))
(W64# x#) * (W64# y#) = W64# (int64ToWord64# (word64ToInt64# x# `timesInt64#` word64ToInt64# y#))
negate (W64# x#) = W64# (int64ToWord64# (negateInt64# (word64ToInt64# x#)))
abs x = x
signum 0 = 0
signum _ = 1
fromInteger i = W64# (integerToWord64 i)
instance Enum Word64 where
succ x
| x /= maxBound = x + 1
| otherwise = succError "Word64"
pred x
| x /= minBound = x - 1
| otherwise = predError "Word64"
toEnum i@(I# i#)
| i >= 0 = W64# (wordToWord64# (int2Word# i#))
| otherwise = toEnumError "Word64" i (minBound::Word64, maxBound::Word64)
fromEnum x@(W64# x#)
| x <= fromIntegral (maxBound::Int)
= I# (word2Int# (word64ToWord# x#))
| otherwise = fromEnumError "Word64" x
enumFrom = integralEnumFrom
enumFromThen = integralEnumFromThen
enumFromTo = integralEnumFromTo
enumFromThenTo = integralEnumFromThenTo
instance Integral Word64 where
quot (W64# x#) y@(W64# y#)
| y /= 0 = W64# (x# `quotWord64#` y#)
| otherwise = divZeroError
rem (W64# x#) y@(W64# y#)
| y /= 0 = W64# (x# `remWord64#` y#)
| otherwise = divZeroError
div (W64# x#) y@(W64# y#)
| y /= 0 = W64# (x# `quotWord64#` y#)
| otherwise = divZeroError
mod (W64# x#) y@(W64# y#)
| y /= 0 = W64# (x# `remWord64#` y#)
| otherwise = divZeroError
quotRem (W64# x#) y@(W64# y#)
| y /= 0 = (W64# (x# `quotWord64#` y#), W64# (x# `remWord64#` y#))
| otherwise = divZeroError
divMod (W64# x#) y@(W64# y#)
| y /= 0 = (W64# (x# `quotWord64#` y#), W64# (x# `remWord64#` y#))
| otherwise = divZeroError
toInteger (W64# x#) = word64ToInteger x#
instance Bits Word64 where
{-# INLINE shift #-}
{-# INLINE bit #-}
{-# INLINE testBit #-}
{-# INLINE popCount #-}
(W64# x#) .&. (W64# y#) = W64# (x# `and64#` y#)
(W64# x#) .|. (W64# y#) = W64# (x# `or64#` y#)
(W64# x#) `xor` (W64# y#) = W64# (x# `xor64#` y#)
complement (W64# x#) = W64# (not64# x#)
(W64# x#) `shift` (I# i#)
| isTrue# (i# >=# 0#) = W64# (x# `shiftL64#` i#)
| otherwise = W64# (x# `shiftRL64#` negateInt# i#)
(W64# x#) `shiftL` (I# i#)
| isTrue# (i# >=# 0#) = W64# (x# `shiftL64#` i#)
| otherwise = overflowError
(W64# x#) `unsafeShiftL` (I# i#) = W64# (x# `uncheckedShiftL64#` i#)
(W64# x#) `shiftR` (I# i#)
| isTrue# (i# >=# 0#) = W64# (x# `shiftRL64#` i#)
| otherwise = overflowError
(W64# x#) `unsafeShiftR` (I# i#) = W64# (x# `uncheckedShiftRL64#` i#)
(W64# x#) `rotate` (I# i#)
| isTrue# (i'# ==# 0#) = W64# x#
| otherwise = W64# ((x# `uncheckedShiftL64#` i'#) `or64#`
(x# `uncheckedShiftRL64#` (64# -# i'#)))
where
!i'# = word2Int# (int2Word# i# `and#` 63##)
bitSizeMaybe i = Just (finiteBitSize i)
bitSize i = finiteBitSize i
isSigned _ = False
popCount (W64# x#) = I# (word2Int# (popCnt64# x#))
bit = bitDefault
testBit = testBitDefault
shiftL64#, shiftRL64# :: Word64# -> Int# -> Word64#
a `shiftL64#` b | isTrue# (b >=# 64#) = wordToWord64# 0##
| otherwise = a `uncheckedShiftL64#` b
a `shiftRL64#` b | isTrue# (b >=# 64#) = wordToWord64# 0##
| otherwise = a `uncheckedShiftRL64#` b
{-# RULES
"fromIntegral/Int->Word64" fromIntegral = \(I# x#) -> W64# (int64ToWord64# (intToInt64# x#))
"fromIntegral/Word->Word64" fromIntegral = \(W# x#) -> W64# (wordToWord64# x#)
"fromIntegral/Word64->Int" fromIntegral = \(W64# x#) -> I# (word2Int# (word64ToWord# x#))
"fromIntegral/Word64->Word" fromIntegral = \(W64# x#) -> W# (word64ToWord# x#)
"fromIntegral/Word64->Word64" fromIntegral = id :: Word64 -> Word64
#-}
#else
data {-# CTYPE "HsWord64" #-} Word64 = W64# Word#
instance Eq Word64 where
== :: Word64 -> Word64 -> Bool
(==) = Word64 -> Word64 -> Bool
eqWord64
/= :: Word64 -> Word64 -> Bool
(/=) = Word64 -> Word64 -> Bool
neWord64
eqWord64, neWord64 :: Word64 -> Word64 -> Bool
eqWord64 :: Word64 -> Word64 -> Bool
eqWord64 (W64# Word#
x) (W64# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord64 :: Word64 -> Word64 -> Bool
neWord64 (W64# Word#
x) (W64# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord64 #-}
{-# INLINE [1] neWord64 #-}
instance Ord Word64 where
< :: Word64 -> Word64 -> Bool
(<) = Word64 -> Word64 -> Bool
ltWord64
<= :: Word64 -> Word64 -> Bool
(<=) = Word64 -> Word64 -> Bool
leWord64
>= :: Word64 -> Word64 -> Bool
(>=) = Word64 -> Word64 -> Bool
geWord64
> :: Word64 -> Word64 -> Bool
(>) = Word64 -> Word64 -> Bool
gtWord64
{-# INLINE [1] gtWord64 #-}
{-# INLINE [1] geWord64 #-}
{-# INLINE [1] ltWord64 #-}
{-# INLINE [1] leWord64 #-}
gtWord64, geWord64, ltWord64, leWord64 :: Word64 -> Word64 -> Bool
(W64# Word#
x) gtWord64 :: Word64 -> Word64 -> Bool
`gtWord64` (W64# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W64# Word#
x) geWord64 :: Word64 -> Word64 -> Bool
`geWord64` (W64# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W64# Word#
x) ltWord64 :: Word64 -> Word64 -> Bool
`ltWord64` (W64# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W64# Word#
x) leWord64 :: Word64 -> Word64 -> Bool
`leWord64` (W64# Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)
instance Num Word64 where
(W64# Word#
x#) + :: Word64 -> Word64 -> Word64
+ (W64# Word#
y#) = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#)
(W64# Word#
x#) - :: Word64 -> Word64 -> Word64
- (W64# Word#
y#) = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#)
(W64# Word#
x#) * :: Word64 -> Word64 -> Word64
* (W64# Word#
y#) = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#)
negate :: Word64 -> Word64
negate (W64# Word#
x#) = Word# -> Word64
W64# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#)))
abs :: Word64 -> Word64
abs Word64
x = Word64
x
signum :: Word64 -> Word64
signum Word64
0 = Word64
0
signum Word64
_ = Word64
1
fromInteger :: Integer -> Word64
fromInteger Integer
i = Word# -> Word64
W64# (Integer -> Word#
integerToWord Integer
i)
instance Enum Word64 where
succ :: Word64 -> Word64
succ Word64
x
| Word64
x Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
forall a. Bounded a => a
maxBound = Word64
x Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1
| Bool
otherwise = String -> Word64
forall a. String -> a
succError String
"Word64"
pred :: Word64 -> Word64
pred Word64
x
| Word64
x Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
forall a. Bounded a => a
minBound = Word64
x Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1
| Bool
otherwise = String -> Word64
forall a. String -> a
predError String
"Word64"
toEnum :: Int -> Word64
toEnum i :: Int
i@(I# Int#
i#)
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 = Word# -> Word64
W64# (Int# -> Word#
int2Word# Int#
i#)
| Bool
otherwise = String -> Int -> (Word64, Word64) -> Word64
forall a b. Show a => String -> Int -> (a, a) -> b
toEnumError String
"Word64" Int
i (Word64
forall a. Bounded a => a
minBound::Word64, Word64
forall a. Bounded a => a
maxBound::Word64)
fromEnum :: Word64 -> Int
fromEnum x :: Word64
x@(W64# Word#
x#)
| Word64
x Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
forall a. Bounded a => a
maxBound::Int)
= Int# -> Int
I# (Word# -> Int#
word2Int# Word#
x#)
| Bool
otherwise = String -> Word64 -> Int
forall a b. Show a => String -> a -> b
fromEnumError String
"Word64" Word64
x
enumFrom :: Word64 -> [Word64]
enumFrom = Word64 -> [Word64]
forall a. (Integral a, Bounded a) => a -> [a]
integralEnumFrom
enumFromThen :: Word64 -> Word64 -> [Word64]
enumFromThen = Word64 -> Word64 -> [Word64]
forall a. (Integral a, Bounded a) => a -> a -> [a]
integralEnumFromThen
enumFromTo :: Word64 -> Word64 -> [Word64]
enumFromTo = Word64 -> Word64 -> [Word64]
forall a. Integral a => a -> a -> [a]
integralEnumFromTo
enumFromThenTo :: Word64 -> Word64 -> Word64 -> [Word64]
enumFromThenTo = Word64 -> Word64 -> Word64 -> [Word64]
forall a. Integral a => a -> a -> a -> [a]
integralEnumFromThenTo
instance Integral Word64 where
quot :: Word64 -> Word64 -> Word64
quot (W64# Word#
x#) y :: Word64
y@(W64# Word#
y#)
| Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word64
forall a. a
divZeroError
rem :: Word64 -> Word64 -> Word64
rem (W64# Word#
x#) y :: Word64
y@(W64# Word#
y#)
| Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word64
forall a. a
divZeroError
div :: Word64 -> Word64 -> Word64
div (W64# Word#
x#) y :: Word64
y@(W64# Word#
y#)
| Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#)
| Bool
otherwise = Word64
forall a. a
divZeroError
mod :: Word64 -> Word64 -> Word64
mod (W64# Word#
x#) y :: Word64
y@(W64# Word#
y#)
| Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#)
| Bool
otherwise = Word64
forall a. a
divZeroError
quotRem :: Word64 -> Word64 -> (Word64, Word64)
quotRem (W64# Word#
x#) y :: Word64
y@(W64# Word#
y#)
| Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
(# Word#
q, Word#
r #) ->
(Word# -> Word64
W64# Word#
q, Word# -> Word64
W64# Word#
r)
| Bool
otherwise = (Word64, Word64)
forall a. a
divZeroError
divMod :: Word64 -> Word64 -> (Word64, Word64)
divMod (W64# Word#
x#) y :: Word64
y@(W64# Word#
y#)
| Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 = (Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`quotWord#` Word#
y#), Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`remWord#` Word#
y#))
| Bool
otherwise = (Word64, Word64)
forall a. a
divZeroError
toInteger :: Word64 -> Integer
toInteger (W64# Word#
x#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Int# -> Integer
smallInteger Int#
i#
| Bool
otherwise = Word# -> Integer
wordToInteger Word#
x#
where
!i# :: Int#
i# = Word# -> Int#
word2Int# Word#
x#
instance Bits Word64 where
{-# INLINE shift #-}
{-# INLINE bit #-}
{-# INLINE testBit #-}
{-# INLINE popCount #-}
(W64# Word#
x#) .&. :: Word64 -> Word64 -> Word64
.&. (W64# Word#
y#) = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
(W64# Word#
x#) .|. :: Word64 -> Word64 -> Word64
.|. (W64# Word#
y#) = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`or#` Word#
y#)
(W64# Word#
x#) xor :: Word64 -> Word64 -> Word64
`xor` (W64# Word#
y#) = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
complement :: Word64 -> Word64
complement (W64# Word#
x#) = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
where !(W64# Word#
mb#) = Word64
forall a. Bounded a => a
maxBound
(W64# Word#
x#) shift :: Word64 -> Int -> Word64
`shift` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#)
| Bool
otherwise = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int# -> Int#
negateInt# Int#
i#)
(W64# Word#
x#) shiftL :: Word64 -> Int -> Word64
`shiftL` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#)
| Bool
otherwise = Word64
forall a. a
overflowError
(W64# Word#
x#) unsafeShiftL :: Word64 -> Int -> Word64
`unsafeShiftL` (I# Int#
i#) = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#)
(W64# Word#
x#) shiftR :: Word64 -> Int -> Word64
`shiftR` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
| Bool
otherwise = Word64
forall a. a
overflowError
(W64# Word#
x#) unsafeShiftR :: Word64 -> Int -> Word64
`unsafeShiftR` (I# Int#
i#) = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
(W64# Word#
x#) rotate :: Word64 -> Int -> Word64
`rotate` (I# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word# -> Word64
W64# Word#
x#
| Bool
otherwise = Word# -> Word64
W64# ((Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i'#) Word# -> Word# -> Word#
`or#`
(Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` (Int#
64# Int# -> Int# -> Int#
-# Int#
i'#)))
where
!i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` Word#
63##)
bitSizeMaybe :: Word64 -> Maybe Int
bitSizeMaybe Word64
i = Int -> Maybe Int
forall a. a -> Maybe a
Just (Word64 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word64
i)
bitSize :: Word64 -> Int
bitSize Word64
i = Word64 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word64
i
isSigned :: Word64 -> Bool
isSigned Word64
_ = Bool
False
popCount :: Word64 -> Int
popCount (W64# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt64# Word#
x#))
bit :: Int -> Word64
bit = Int -> Word64
forall a. (Bits a, Num a) => Int -> a
bitDefault
testBit :: Word64 -> Int -> Bool
testBit = Word64 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault
{-# RULES
"fromIntegral/a->Word64" fromIntegral = \x -> case fromIntegral x of W# x# -> W64# x#
"fromIntegral/Word64->a" fromIntegral = \(W64# x#) -> fromIntegral (W# x#)
#-}
uncheckedShiftL64# :: Word# -> Int# -> Word#
uncheckedShiftL64# :: Word# -> Int# -> Word#
uncheckedShiftL64# = Word# -> Int# -> Word#
uncheckedShiftL#
uncheckedShiftRL64# :: Word# -> Int# -> Word#
uncheckedShiftRL64# :: Word# -> Int# -> Word#
uncheckedShiftRL64# = Word# -> Int# -> Word#
uncheckedShiftRL#
#endif
instance FiniteBits Word64 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize :: Word64 -> Int
finiteBitSize Word64
_ = Int
64
countLeadingZeros :: Word64 -> Int
countLeadingZeros (W64# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz64# Word#
x#))
countTrailingZeros :: Word64 -> Int
countTrailingZeros (W64# Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz64# Word#
x#))
instance Show Word64 where
showsPrec :: Int -> Word64 -> ShowS
showsPrec Int
p Word64
x = Int -> Integer -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
x)
instance Real Word64 where
toRational :: Word64 -> Rational
toRational Word64
x = Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
1
instance Bounded Word64 where
minBound :: Word64
minBound = Word64
0
maxBound :: Word64
maxBound = Word64
0xFFFFFFFFFFFFFFFF
instance Ix Word64 where
range :: (Word64, Word64) -> [Word64]
range (Word64
m,Word64
n) = [Word64
m..Word64
n]
unsafeIndex :: (Word64, Word64) -> Word64 -> Int
unsafeIndex (Word64
m,Word64
_) Word64
i = Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
i Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
m)
inRange :: (Word64, Word64) -> Word64 -> Bool
inRange (Word64
m,Word64
n) Word64
i = Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word64
i Bool -> Bool -> Bool
&& Word64
i Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word64
n
#if WORD_SIZE_IN_BITS < 64
byteSwap64 :: Word64 -> Word64
byteSwap64 (W64# w#) = W64# (byteSwap64# w#)
#else
byteSwap64 :: Word64 -> Word64
byteSwap64 :: Word64 -> Word64
byteSwap64 (W64# Word#
w#) = Word# -> Word64
W64# (Word# -> Word#
byteSwap# Word#
w#)
#endif
bitReverse8 :: Word8 -> Word8
bitReverse8 :: Word8 -> Word8
bitReverse8 (W8# Word#
w#) = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word# -> Word#
bitReverse8# Word#
w#))
bitReverse16 :: Word16 -> Word16
bitReverse16 :: Word16 -> Word16
bitReverse16 (W16# Word#
w#) = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word# -> Word#
bitReverse16# Word#
w#))
bitReverse32 :: Word32 -> Word32
bitReverse32 :: Word32 -> Word32
bitReverse32 (W32# Word#
w#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word# -> Word#
bitReverse32# Word#
w#))
#if WORD_SIZE_IN_BITS < 64
bitReverse64 :: Word64 -> Word64
bitReverse64 (W64# w#) = W64# (bitReverse64# w#)
#else
bitReverse64 :: Word64 -> Word64
bitReverse64 :: Word64 -> Word64
bitReverse64 (W64# Word#
w#) = Word# -> Word64
W64# (Word# -> Word#
bitReverse# Word#
w#)
#endif
{-# RULES
"fromIntegral/Natural->Word8"
fromIntegral = (fromIntegral :: Word -> Word8) . naturalToWord
"fromIntegral/Natural->Word16"
fromIntegral = (fromIntegral :: Word -> Word16) . naturalToWord
"fromIntegral/Natural->Word32"
fromIntegral = (fromIntegral :: Word -> Word32) . naturalToWord
#-}
{-# RULES
"fromIntegral/Word8->Natural"
fromIntegral = wordToNatural . (fromIntegral :: Word8 -> Word)
"fromIntegral/Word16->Natural"
fromIntegral = wordToNatural . (fromIntegral :: Word16 -> Word)
"fromIntegral/Word32->Natural"
fromIntegral = wordToNatural . (fromIntegral :: Word32 -> Word)
#-}
#if WORD_SIZE_IN_BITS == 64
{-# RULES
"fromIntegral/Natural->Word64"
fromIntegral = (fromIntegral :: Word -> Word64) . naturalToWord
"fromIntegral/Word64->Natural"
fromIntegral = wordToNatural . (fromIntegral :: Word64 -> Word)
#-}
#endif