{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash, UnboxedTuples #-}
{-# OPTIONS_HADDOCK not-home #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  GHC.Word
-- Copyright   :  (c) The University of Glasgow, 1997-2002
-- License     :  see libraries/base/LICENSE
--
-- Maintainer  :  cvs-ghc@haskell.org
-- Stability   :  internal
-- Portability :  non-portable (GHC Extensions)
--
-- Sized unsigned integral types: 'Word', 'Word8', 'Word16', 'Word32', and
-- 'Word64'.
--
-----------------------------------------------------------------------------

#include "MachDeps.h"

module GHC.Word (
    Word(..), Word8(..), Word16(..), Word32(..), Word64(..),

    -- * Shifts
    uncheckedShiftL64#,
    uncheckedShiftRL64#,

    -- * Byte swapping
    byteSwap16,
    byteSwap32,
    byteSwap64,

    -- * Equality operators
    -- | See GHC.Classes#matching_overloaded_methods_in_rules
    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.Arr
import GHC.Show

------------------------------------------------------------------------
-- type Word8
------------------------------------------------------------------------

-- Word8 is represented in the same way as Word. Operations may assume
-- and must ensure that it holds only values from its logical range.

data {-# CTYPE "HsWord8" #-} Word8 = W8# Word#
-- ^ 8-bit unsigned integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
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# x :: Word#
x) (W8# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord8 :: Word8 -> Word8 -> Bool
neWord8 (W8# x :: Word#
x) (W8# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord8 #-}
{-# INLINE [1] neWord8 #-}

-- | @since 2.01
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# x :: Word#
x) gtWord8 :: Word8 -> Word8 -> Bool
`gtWord8` (W8# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W8# x :: Word#
x) geWord8 :: Word8 -> Word8 -> Bool
`geWord8` (W8# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W8# x :: Word#
x) ltWord8 :: Word8 -> Word8 -> Bool
`ltWord8` (W8# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W8# x :: Word#
x) leWord8 :: Word8 -> Word8 -> Bool
`leWord8` (W8# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)

-- | @since 2.01
instance Show Word8 where
    showsPrec :: Int -> Word8 -> ShowS
showsPrec p :: Int
p x :: 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)

-- | @since 2.01
instance Num Word8 where
    (W8# x# :: Word#
x#) + :: Word8 -> Word8 -> Word8
+ (W8# y# :: Word#
y#)    = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#))
    (W8# x# :: Word#
x#) - :: Word8 -> Word8 -> Word8
- (W8# y# :: Word#
y#)    = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#))
    (W8# x# :: Word#
x#) * :: Word8 -> Word8 -> Word8
* (W8# y# :: Word#
y#)    = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#))
    negate :: Word8 -> Word8
negate (W8# x# :: Word#
x#)        = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#))))
    abs :: Word8 -> Word8
abs x :: Word8
x                  = Word8
x
    signum :: Word8 -> Word8
signum 0               = 0
    signum _               = 1
    fromInteger :: Integer -> Word8
fromInteger i :: Integer
i          = Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Integer -> Word#
integerToWord Integer
i))

-- | @since 2.01
instance Real Word8 where
    toRational :: Word8 -> Rational
toRational x :: Word8
x = Word8 -> Integer
forall a. Integral a => a -> Integer
toInteger Word8
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Enum Word8 where
    succ :: Word8 -> Word8
succ x :: 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
+ 1
        | Bool
otherwise     = String -> Word8
forall a. String -> a
succError "Word8"
    pred :: Word8 -> Word8
pred x :: 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
- 1
        | Bool
otherwise     = String -> Word8
forall a. String -> a
predError "Word8"
    toEnum :: Int -> Word8
toEnum i :: Int
i@(I# i# :: Int#
i#)
        | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 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 "Word8" Int
i (Word8
forall a. Bounded a => a
minBound::Word8, Word8
forall a. Bounded a => a
maxBound::Word8)
    fromEnum :: Word8 -> Int
fromEnum (W8# x# :: 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

-- | @since 2.01
instance Integral Word8 where
    quot :: Word8 -> Word8 -> Word8
quot    (W8# x# :: Word#
x#) y :: Word8
y@(W8# y# :: Word#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word8
y@(W8# y# :: Word#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word8
y@(W8# y# :: Word#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word8
y@(W8# y# :: Word#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word8
y@(W8# y# :: Word#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= 0                  = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
                                    (# q :: Word#
q, r :: 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# x# :: Word#
x#) y :: Word8
y@(W8# y# :: Word#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#)            = Int# -> Integer
smallInteger (Word# -> Int#
word2Int# Word#
x#)

-- | @since 2.01
instance Bounded Word8 where
    minBound :: Word8
minBound = 0
    maxBound :: Word8
maxBound = 0xFF

-- | @since 2.01
instance Ix Word8 where
    range :: (Word8, Word8) -> [Word8]
range (m :: Word8
m,n :: Word8
n)         = [Word8
m..Word8
n]
    unsafeIndex :: (Word8, Word8) -> Word8 -> Int
unsafeIndex (m :: Word8
m,_) i :: 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 (m :: Word8
m,n :: Word8
n) i :: 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

-- | @since 2.01
instance Bits Word8 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (W8# x# :: Word#
x#) .&. :: Word8 -> Word8 -> Word8
.&.   (W8# y# :: Word#
y#)   = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
    (W8# x# :: Word#
x#) .|. :: Word8 -> Word8 -> Word8
.|.   (W8# y# :: Word#
y#)   = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`or#`  Word#
y#)
    (W8# x# :: Word#
x#) xor :: Word8 -> Word8 -> Word8
`xor` (W8# y# :: Word#
y#)   = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
    complement :: Word8 -> Word8
complement (W8# x# :: Word#
x#)       = Word# -> Word8
W8# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
        where !(W8# mb# :: Word#
mb#) = Word8
forall a. Bounded a => a
maxBound
    (W8# x# :: Word#
x#) shift :: Word8 -> Int -> Word8
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# 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# x# :: Word#
x#) shiftL :: Word8 -> Int -> Word8
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# 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# x# :: Word#
x#) unsafeShiftL :: Word8 -> Int -> Word8
`unsafeShiftL` (I# i# :: Int#
i#) =
        Word# -> Word8
W8# (Word# -> Word#
narrow8Word# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#))
    (W8# x# :: Word#
x#) shiftR :: Word8 -> Int -> Word8
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#) = Word# -> Word8
W8# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
        | Bool
otherwise           = Word8
forall a. a
overflowError
    (W8# x# :: Word#
x#) unsafeShiftR :: Word8 -> Int -> Word8
`unsafeShiftR` (I# i# :: Int#
i#) = Word# -> Word8
W8# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
    (W8# x# :: Word#
x#) rotate :: Word8 -> Int -> Word8
`rotate`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# 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#` (8# Int# -> Int# -> Int#
-# Int#
i'#))))
        where
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 7##)
    bitSizeMaybe :: Word8 -> Maybe Int
bitSizeMaybe i :: 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 i :: Word8
i                 = Word8 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word8
i
    isSigned :: Word8 -> Bool
isSigned _                = Bool
False
    popCount :: Word8 -> Int
popCount (W8# x# :: 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

-- | @since 4.6.0.0
instance FiniteBits Word8 where
    finiteBitSize :: Word8 -> Int
finiteBitSize _ = 8
    countLeadingZeros :: Word8 -> Int
countLeadingZeros  (W8# x# :: Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz8# Word#
x#))
    countTrailingZeros :: Word8 -> Int
countTrailingZeros (W8# x# :: 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)
  #-}

------------------------------------------------------------------------
-- type Word16
------------------------------------------------------------------------

-- Word16 is represented in the same way as Word. Operations may assume
-- and must ensure that it holds only values from its logical range.

data {-# CTYPE "HsWord16" #-} Word16 = W16# Word#
-- ^ 16-bit unsigned integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
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# x :: Word#
x) (W16# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord16 :: Word16 -> Word16 -> Bool
neWord16 (W16# x :: Word#
x) (W16# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord16 #-}
{-# INLINE [1] neWord16 #-}

-- | @since 2.01
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# x :: Word#
x) gtWord16 :: Word16 -> Word16 -> Bool
`gtWord16` (W16# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W16# x :: Word#
x) geWord16 :: Word16 -> Word16 -> Bool
`geWord16` (W16# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W16# x :: Word#
x) ltWord16 :: Word16 -> Word16 -> Bool
`ltWord16` (W16# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W16# x :: Word#
x) leWord16 :: Word16 -> Word16 -> Bool
`leWord16` (W16# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)

-- | @since 2.01
instance Show Word16 where
    showsPrec :: Int -> Word16 -> ShowS
showsPrec p :: Int
p x :: 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)

-- | @since 2.01
instance Num Word16 where
    (W16# x# :: Word#
x#) + :: Word16 -> Word16 -> Word16
+ (W16# y# :: Word#
y#)  = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#))
    (W16# x# :: Word#
x#) - :: Word16 -> Word16 -> Word16
- (W16# y# :: Word#
y#)  = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#))
    (W16# x# :: Word#
x#) * :: Word16 -> Word16 -> Word16
* (W16# y# :: Word#
y#)  = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#))
    negate :: Word16 -> Word16
negate (W16# x# :: Word#
x#)       = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#))))
    abs :: Word16 -> Word16
abs x :: Word16
x                  = Word16
x
    signum :: Word16 -> Word16
signum 0               = 0
    signum _               = 1
    fromInteger :: Integer -> Word16
fromInteger i :: Integer
i          = Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Integer -> Word#
integerToWord Integer
i))

-- | @since 2.01
instance Real Word16 where
    toRational :: Word16 -> Rational
toRational x :: Word16
x = Word16 -> Integer
forall a. Integral a => a -> Integer
toInteger Word16
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Enum Word16 where
    succ :: Word16 -> Word16
succ x :: 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
+ 1
        | Bool
otherwise     = String -> Word16
forall a. String -> a
succError "Word16"
    pred :: Word16 -> Word16
pred x :: 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
- 1
        | Bool
otherwise     = String -> Word16
forall a. String -> a
predError "Word16"
    toEnum :: Int -> Word16
toEnum i :: Int
i@(I# i# :: Int#
i#)
        | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 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 "Word16" Int
i (Word16
forall a. Bounded a => a
minBound::Word16, Word16
forall a. Bounded a => a
maxBound::Word16)
    fromEnum :: Word16 -> Int
fromEnum (W16# x# :: 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

-- | @since 2.01
instance Integral Word16 where
    quot :: Word16 -> Word16 -> Word16
quot    (W16# x# :: Word#
x#) y :: Word16
y@(W16# y# :: Word#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word16
y@(W16# y# :: Word#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word16
y@(W16# y# :: Word#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word16
y@(W16# y# :: Word#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word16
y@(W16# y# :: Word#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= 0                  = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
                                    (# q :: Word#
q, r :: 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# x# :: Word#
x#) y :: Word16
y@(W16# y# :: Word#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#)             = Int# -> Integer
smallInteger (Word# -> Int#
word2Int# Word#
x#)

-- | @since 2.01
instance Bounded Word16 where
    minBound :: Word16
minBound = 0
    maxBound :: Word16
maxBound = 0xFFFF

-- | @since 2.01
instance Ix Word16 where
    range :: (Word16, Word16) -> [Word16]
range (m :: Word16
m,n :: Word16
n)         = [Word16
m..Word16
n]
    unsafeIndex :: (Word16, Word16) -> Word16 -> Int
unsafeIndex (m :: Word16
m,_) i :: 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 (m :: Word16
m,n :: Word16
n) i :: 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

-- | @since 2.01
instance Bits Word16 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (W16# x# :: Word#
x#) .&. :: Word16 -> Word16 -> Word16
.&.   (W16# y# :: Word#
y#)  = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
    (W16# x# :: Word#
x#) .|. :: Word16 -> Word16 -> Word16
.|.   (W16# y# :: Word#
y#)  = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`or#`  Word#
y#)
    (W16# x# :: Word#
x#) xor :: Word16 -> Word16 -> Word16
`xor` (W16# y# :: Word#
y#)  = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
    complement :: Word16 -> Word16
complement (W16# x# :: Word#
x#)       = Word# -> Word16
W16# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
        where !(W16# mb# :: Word#
mb#) = Word16
forall a. Bounded a => a
maxBound
    (W16# x# :: Word#
x#) shift :: Word16 -> Int -> Word16
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# 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# x# :: Word#
x#) shiftL :: Word16 -> Int -> Word16
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# 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# x# :: Word#
x#) unsafeShiftL :: Word16 -> Int -> Word16
`unsafeShiftL` (I# i# :: Int#
i#) =
        Word# -> Word16
W16# (Word# -> Word#
narrow16Word# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#))
    (W16# x# :: Word#
x#) shiftR :: Word16 -> Int -> Word16
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Word# -> Word16
W16# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
        | Bool
otherwise            = Word16
forall a. a
overflowError
    (W16# x# :: Word#
x#) unsafeShiftR :: Word16 -> Int -> Word16
`unsafeShiftR` (I# i# :: Int#
i#) = Word# -> Word16
W16# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
    (W16# x# :: Word#
x#) rotate :: Word16 -> Int -> Word16
`rotate`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# 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#` (16# Int# -> Int# -> Int#
-# Int#
i'#))))
        where
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 15##)
    bitSizeMaybe :: Word16 -> Maybe Int
bitSizeMaybe i :: 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 i :: Word16
i                 = Word16 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word16
i
    isSigned :: Word16 -> Bool
isSigned _                = Bool
False
    popCount :: Word16 -> Int
popCount (W16# x# :: 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

-- | @since 4.6.0.0
instance FiniteBits Word16 where
    finiteBitSize :: Word16 -> Int
finiteBitSize _ = 16
    countLeadingZeros :: Word16 -> Int
countLeadingZeros  (W16# x# :: Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz16# Word#
x#))
    countTrailingZeros :: Word16 -> Int
countTrailingZeros (W16# x# :: Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz16# Word#
x#))

-- | Swap bytes in 'Word16'.
--
-- @since 4.7.0.0
byteSwap16 :: Word16 -> Word16
byteSwap16 :: Word16 -> Word16
byteSwap16 (W16# w# :: 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)
  #-}

------------------------------------------------------------------------
-- type Word32
------------------------------------------------------------------------

-- Word32 is represented in the same way as Word.
#if WORD_SIZE_IN_BITS > 32
-- Operations may assume and must ensure that it holds only values
-- from its logical range.

-- We can use rewrite rules for the RealFrac methods

{-# 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#
-- ^ 32-bit unsigned integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
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# x :: Word#
x) (W32# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord32 :: Word32 -> Word32 -> Bool
neWord32 (W32# x :: Word#
x) (W32# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord32 #-}
{-# INLINE [1] neWord32 #-}

-- | @since 2.01
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# x :: Word#
x) gtWord32 :: Word32 -> Word32 -> Bool
`gtWord32` (W32# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W32# x :: Word#
x) geWord32 :: Word32 -> Word32 -> Bool
`geWord32` (W32# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W32# x :: Word#
x) ltWord32 :: Word32 -> Word32 -> Bool
`ltWord32` (W32# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W32# x :: Word#
x) leWord32 :: Word32 -> Word32 -> Bool
`leWord32` (W32# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)

-- | @since 2.01
instance Num Word32 where
    (W32# x# :: Word#
x#) + :: Word32 -> Word32 -> Word32
+ (W32# y# :: Word#
y#)  = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#))
    (W32# x# :: Word#
x#) - :: Word32 -> Word32 -> Word32
- (W32# y# :: Word#
y#)  = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#))
    (W32# x# :: Word#
x#) * :: Word32 -> Word32 -> Word32
* (W32# y# :: Word#
y#)  = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#))
    negate :: Word32 -> Word32
negate (W32# x# :: Word#
x#)       = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#))))
    abs :: Word32 -> Word32
abs x :: Word32
x                  = Word32
x
    signum :: Word32 -> Word32
signum 0               = 0
    signum _               = 1
    fromInteger :: Integer -> Word32
fromInteger i :: Integer
i          = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Integer -> Word#
integerToWord Integer
i))

-- | @since 2.01
instance Enum Word32 where
    succ :: Word32 -> Word32
succ x :: 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
+ 1
        | Bool
otherwise     = String -> Word32
forall a. String -> a
succError "Word32"
    pred :: Word32 -> Word32
pred x :: 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
- 1
        | Bool
otherwise     = String -> Word32
forall a. String -> a
predError "Word32"
    toEnum :: Int -> Word32
toEnum i :: Int
i@(I# i# :: Int#
i#)
        | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 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 "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# x# :: 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

-- | @since 2.01
instance Integral Word32 where
    quot :: Word32 -> Word32 -> Word32
quot    (W32# x# :: Word#
x#) y :: Word32
y@(W32# y# :: Word#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word32
y@(W32# y# :: Word#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word32
y@(W32# y# :: Word#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word32
y@(W32# y# :: Word#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word32
y@(W32# y# :: Word#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= 0                  = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
                                    (# q :: Word#
q, r :: 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# x# :: Word#
x#) y :: Word32
y@(W32# y# :: Word#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: 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

-- | @since 2.01
instance Bits Word32 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (W32# x# :: Word#
x#) .&. :: Word32 -> Word32 -> Word32
.&.   (W32# y# :: Word#
y#)  = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
    (W32# x# :: Word#
x#) .|. :: Word32 -> Word32 -> Word32
.|.   (W32# y# :: Word#
y#)  = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`or#`  Word#
y#)
    (W32# x# :: Word#
x#) xor :: Word32 -> Word32 -> Word32
`xor` (W32# y# :: Word#
y#)  = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
    complement :: Word32 -> Word32
complement (W32# x# :: Word#
x#)       = Word# -> Word32
W32# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
        where !(W32# mb# :: Word#
mb#) = Word32
forall a. Bounded a => a
maxBound
    (W32# x# :: Word#
x#) shift :: Word32 -> Int -> Word32
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# 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# x# :: Word#
x#) shiftL :: Word32 -> Int -> Word32
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# 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# x# :: Word#
x#) unsafeShiftL :: Word32 -> Int -> Word32
`unsafeShiftL` (I# i# :: Int#
i#) =
        Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#))
    (W32# x# :: Word#
x#) shiftR :: Word32 -> Int -> Word32
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Word# -> Word32
W32# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
        | Bool
otherwise            = Word32
forall a. a
overflowError
    (W32# x# :: Word#
x#) unsafeShiftR :: Word32 -> Int -> Word32
`unsafeShiftR` (I# i# :: Int#
i#) = Word# -> Word32
W32# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
    (W32# x# :: Word#
x#) rotate :: Word32 -> Int -> Word32
`rotate`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# 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#` (32# Int# -> Int# -> Int#
-# Int#
i'#))))
        where
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 31##)
    bitSizeMaybe :: Word32 -> Maybe Int
bitSizeMaybe i :: 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 i :: Word32
i                 = Word32 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word32
i
    isSigned :: Word32 -> Bool
isSigned _                = Bool
False
    popCount :: Word32 -> Int
popCount (W32# x# :: 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

-- | @since 4.6.0.0
instance FiniteBits Word32 where
    finiteBitSize :: Word32 -> Int
finiteBitSize _ = 32
    countLeadingZeros :: Word32 -> Int
countLeadingZeros  (W32# x# :: Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz32# Word#
x#))
    countTrailingZeros :: Word32 -> Int
countTrailingZeros (W32# x# :: 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#)
  #-}

-- | @since 2.01
instance Show Word32 where
#if WORD_SIZE_IN_BITS < 33
    showsPrec p x = showsPrec p (toInteger x)
#else
    showsPrec :: Int -> Word32 -> ShowS
showsPrec p :: Int
p x :: 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


-- | @since 2.01
instance Real Word32 where
    toRational :: Word32 -> Rational
toRational x :: Word32
x = Word32 -> Integer
forall a. Integral a => a -> Integer
toInteger Word32
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Bounded Word32 where
    minBound :: Word32
minBound = 0
    maxBound :: Word32
maxBound = 0xFFFFFFFF

-- | @since 2.01
instance Ix Word32 where
    range :: (Word32, Word32) -> [Word32]
range (m :: Word32
m,n :: Word32
n)         = [Word32
m..Word32
n]
    unsafeIndex :: (Word32, Word32) -> Word32 -> Int
unsafeIndex (m :: Word32
m,_) i :: 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 (m :: Word32
m,n :: Word32
n) i :: 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

-- | Reverse order of bytes in 'Word32'.
--
-- @since 4.7.0.0
byteSwap32 :: Word32 -> Word32
byteSwap32 :: Word32 -> Word32
byteSwap32 (W32# w# :: Word#
w#) = Word# -> Word32
W32# (Word# -> Word#
narrow32Word# (Word# -> Word#
byteSwap32# Word#
w#))

------------------------------------------------------------------------
-- type Word64
------------------------------------------------------------------------

#if WORD_SIZE_IN_BITS < 64

data {-# CTYPE "HsWord64" #-} Word64 = W64# Word64#
-- ^ 64-bit unsigned integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
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 #-}

-- | @since 2.01
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)

-- | @since 2.01
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)

-- | @since 2.01
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

-- | @since 2.01
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#

-- | @since 2.01
instance Bits Word64 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (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

-- give the 64-bit shift operations the same treatment as the 32-bit
-- ones (see GHC.Base), namely we wrap them in tests to catch the
-- cases when we're shifting more than 64 bits to avoid unspecified
-- behaviour in the C shift operations.

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

-- Word64 is represented in the same way as Word.
-- Operations may assume and must ensure that it holds only values
-- from its logical range.

data {-# CTYPE "HsWord64" #-} Word64 = W64# Word#
-- ^ 64-bit unsigned integer type

-- See GHC.Classes#matching_overloaded_methods_in_rules
-- | @since 2.01
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# x :: Word#
x) (W64# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`eqWord#` Word#
y)
neWord64 :: Word64 -> Word64 -> Bool
neWord64 (W64# x :: Word#
x) (W64# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`neWord#` Word#
y)
{-# INLINE [1] eqWord64 #-}
{-# INLINE [1] neWord64 #-}

-- | @since 2.01
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# x :: Word#
x) gtWord64 :: Word64 -> Word64 -> Bool
`gtWord64` (W64# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`gtWord#` Word#
y)
(W64# x :: Word#
x) geWord64 :: Word64 -> Word64 -> Bool
`geWord64` (W64# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`geWord#` Word#
y)
(W64# x :: Word#
x) ltWord64 :: Word64 -> Word64 -> Bool
`ltWord64` (W64# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`ltWord#` Word#
y)
(W64# x :: Word#
x) leWord64 :: Word64 -> Word64 -> Bool
`leWord64` (W64# y :: Word#
y) = Int# -> Bool
isTrue# (Word#
x Word# -> Word# -> Int#
`leWord#` Word#
y)

-- | @since 2.01
instance Num Word64 where
    (W64# x# :: Word#
x#) + :: Word64 -> Word64 -> Word64
+ (W64# y# :: Word#
y#)  = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`plusWord#` Word#
y#)
    (W64# x# :: Word#
x#) - :: Word64 -> Word64 -> Word64
- (W64# y# :: Word#
y#)  = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`minusWord#` Word#
y#)
    (W64# x# :: Word#
x#) * :: Word64 -> Word64 -> Word64
* (W64# y# :: Word#
y#)  = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`timesWord#` Word#
y#)
    negate :: Word64 -> Word64
negate (W64# x# :: Word#
x#)       = Word# -> Word64
W64# (Int# -> Word#
int2Word# (Int# -> Int#
negateInt# (Word# -> Int#
word2Int# Word#
x#)))
    abs :: Word64 -> Word64
abs x :: Word64
x                  = Word64
x
    signum :: Word64 -> Word64
signum 0               = 0
    signum _               = 1
    fromInteger :: Integer -> Word64
fromInteger i :: Integer
i          = Word# -> Word64
W64# (Integer -> Word#
integerToWord Integer
i)

-- | @since 2.01
instance Enum Word64 where
    succ :: Word64 -> Word64
succ x :: 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
+ 1
        | Bool
otherwise     = String -> Word64
forall a. String -> a
succError "Word64"
    pred :: Word64 -> Word64
pred x :: 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
- 1
        | Bool
otherwise     = String -> Word64
forall a. String -> a
predError "Word64"
    toEnum :: Int -> Word64
toEnum i :: Int
i@(I# i# :: Int#
i#)
        | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 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 "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# x# :: 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 "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

-- | @since 2.01
instance Integral Word64 where
    quot :: Word64 -> Word64 -> Word64
quot    (W64# x# :: Word#
x#) y :: Word64
y@(W64# y# :: Word#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word64
y@(W64# y# :: Word#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word64
y@(W64# y# :: Word#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word64
y@(W64# y# :: Word#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#) y :: Word64
y@(W64# y# :: Word#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= 0                  = case Word#
x# Word# -> Word# -> (# Word#, Word# #)
`quotRemWord#` Word#
y# of
                                    (# q :: Word#
q, r :: 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# x# :: Word#
x#) y :: Word64
y@(W64# y# :: Word#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= 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# x# :: Word#
x#)
        | Int# -> Bool
isTrue# (Int#
i# 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#

-- | @since 2.01
instance Bits Word64 where
    {-# INLINE shift #-}
    {-# INLINE bit #-}
    {-# INLINE testBit #-}

    (W64# x# :: Word#
x#) .&. :: Word64 -> Word64 -> Word64
.&.   (W64# y# :: Word#
y#)  = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`and#` Word#
y#)
    (W64# x# :: Word#
x#) .|. :: Word64 -> Word64 -> Word64
.|.   (W64# y# :: Word#
y#)  = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`or#`  Word#
y#)
    (W64# x# :: Word#
x#) xor :: Word64 -> Word64 -> Word64
`xor` (W64# y# :: Word#
y#)  = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
y#)
    complement :: Word64 -> Word64
complement (W64# x# :: Word#
x#)       = Word# -> Word64
W64# (Word#
x# Word# -> Word# -> Word#
`xor#` Word#
mb#)
        where !(W64# mb# :: Word#
mb#) = Word64
forall a. Bounded a => a
maxBound
    (W64# x# :: Word#
x#) shift :: Word64 -> Int -> Word64
`shift` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# 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# x# :: Word#
x#) shiftL :: Word64 -> Int -> Word64
`shiftL`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`shiftL#` Int#
i#)
        | Bool
otherwise            = Word64
forall a. a
overflowError
    (W64# x# :: Word#
x#) unsafeShiftL :: Word64 -> Int -> Word64
`unsafeShiftL` (I# i# :: Int#
i#) = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
i#)
    (W64# x# :: Word#
x#) shiftR :: Word64 -> Int -> Word64
`shiftR`       (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# 0#)  = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`shiftRL#` Int#
i#)
        | Bool
otherwise            = Word64
forall a. a
overflowError
    (W64# x# :: Word#
x#) unsafeShiftR :: Word64 -> Int -> Word64
`unsafeShiftR` (I# i# :: Int#
i#) = Word# -> Word64
W64# (Word#
x# Word# -> Int# -> Word#
`uncheckedShiftRL#` Int#
i#)
    (W64# x# :: Word#
x#) rotate :: Word64 -> Int -> Word64
`rotate` (I# i# :: Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# 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#` (64# Int# -> Int# -> Int#
-# Int#
i'#)))
        where
        !i'# :: Int#
i'# = Word# -> Int#
word2Int# (Int# -> Word#
int2Word# Int#
i# Word# -> Word# -> Word#
`and#` 63##)
    bitSizeMaybe :: Word64 -> Maybe Int
bitSizeMaybe i :: 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 i :: Word64
i                 = Word64 -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize Word64
i
    isSigned :: Word64 -> Bool
isSigned _                = Bool
False
    popCount :: Word64 -> Int
popCount (W64# x# :: 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

-- | @since 4.6.0.0
instance FiniteBits Word64 where
    finiteBitSize :: Word64 -> Int
finiteBitSize _ = 64
    countLeadingZeros :: Word64 -> Int
countLeadingZeros  (W64# x# :: Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz64# Word#
x#))
    countTrailingZeros :: Word64 -> Int
countTrailingZeros (W64# x# :: Word#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz64# Word#
x#))

-- | @since 2.01
instance Show Word64 where
    showsPrec :: Int -> Word64 -> ShowS
showsPrec p :: Int
p x :: 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)

-- | @since 2.01
instance Real Word64 where
    toRational :: Word64 -> Rational
toRational x :: Word64
x = Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
x Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% 1

-- | @since 2.01
instance Bounded Word64 where
    minBound :: Word64
minBound = 0
    maxBound :: Word64
maxBound = 0xFFFFFFFFFFFFFFFF

-- | @since 2.01
instance Ix Word64 where
    range :: (Word64, Word64) -> [Word64]
range (m :: Word64
m,n :: Word64
n)         = [Word64
m..Word64
n]
    unsafeIndex :: (Word64, Word64) -> Word64 -> Int
unsafeIndex (m :: Word64
m,_) i :: 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 (m :: Word64
m,n :: Word64
n) i :: 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

-- | Reverse order of bytes in 'Word64'.
--
-- @since 4.7.0.0
#if WORD_SIZE_IN_BITS < 64
byteSwap64 :: Word64 -> Word64
byteSwap64 (W64# w#) = W64# (byteSwap64# w#)
#else
byteSwap64 :: Word64 -> Word64
byteSwap64 :: Word64 -> Word64
byteSwap64 (W64# w# :: Word#
w#) = Word# -> Word64
W64# (Word# -> Word#
byteSwap# 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
-- these RULES are valid for Word==Word64
{-# RULES
"fromIntegral/Natural->Word64"
    fromIntegral = (fromIntegral :: Word -> Word64) . naturalToWord
"fromIntegral/Word64->Natural"
    fromIntegral = wordToNatural . (fromIntegral :: Word64 -> Word)
  #-}
#endif