{-# 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,

    -- * Bit reversal
    bitReverse8,
    bitReverse16,
    bitReverse32,
    bitReverse64,

    -- * 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.Maybe

import GHC.Prim
import GHC.Base

import GHC.Bits
import GHC.Enum
import GHC.Num
import GHC.Real
import GHC.Ix
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# Word8#


-- ^ 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# Word8#
x) (W8# Word8#
y) = Int# -> Bool
isTrue# (Word8#
x Word8# -> Word8# -> Int#
`eqWord8#` Word8#
y)
neWord8 :: Word8 -> Word8 -> Bool
neWord8 (W8# Word8#
x) (W8# Word8#
y) = Int# -> Bool
isTrue# (Word8#
x Word8# -> Word8# -> Int#
`neWord8#` Word8#
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# Word8#
x) gtWord8 :: Word8 -> Word8 -> Bool
`gtWord8` (W8# Word8#
y) = Int# -> Bool
isTrue# (Word8#
x Word8# -> Word8# -> Int#
`gtWord8#` Word8#
y)
(W8# Word8#
x) geWord8 :: Word8 -> Word8 -> Bool
`geWord8` (W8# Word8#
y) = Int# -> Bool
isTrue# (Word8#
x Word8# -> Word8# -> Int#
`geWord8#` Word8#
y)
(W8# Word8#
x) ltWord8 :: Word8 -> Word8 -> Bool
`ltWord8` (W8# Word8#
y) = Int# -> Bool
isTrue# (Word8#
x Word8# -> Word8# -> Int#
`ltWord8#` Word8#
y)
(W8# Word8#
x) leWord8 :: Word8 -> Word8 -> Bool
`leWord8` (W8# Word8#
y) = Int# -> Bool
isTrue# (Word8#
x Word8# -> Word8# -> Int#
`leWord8#` Word8#
y)

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

-- | @since 2.01
instance Num Word8 where
    (W8# Word8#
x#) + :: Word8 -> Word8 -> Word8
+ (W8# Word8#
y#)    = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`plusWord8#` Word8#
y#)
    (W8# Word8#
x#) - :: Word8 -> Word8 -> Word8
- (W8# Word8#
y#)    = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`subWord8#` Word8#
y#)
    (W8# Word8#
x#) * :: Word8 -> Word8 -> Word8
* (W8# Word8#
y#)    = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`timesWord8#` Word8#
y#)
    negate :: Word8 -> Word8
negate (W8# Word8#
x#)        = Word8# -> Word8
W8# (Int8# -> Word8#
int8ToWord8# (Int8# -> Int8#
negateInt8# (Word8# -> Int8#
word8ToInt8# Word8#
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          = Word8# -> Word8
W8# (Word# -> Word8#
wordToWord8# (Integer -> Word#
integerToWord# Integer
i))

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

-- | @since 2.01
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)
                        = Word8# -> Word8
W8# (Word# -> Word8#
wordToWord8# (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# Word8#
x#)   = Int# -> Int
I# (Word# -> Int#
word2Int# (Word8# -> Word#
word8ToWord# Word8#
x#))
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFrom #-}
    enumFrom :: Word8 -> [Word8]
enumFrom            = Word8 -> [Word8]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromThen #-}
    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
    -- see Note [INLINE division wrappers] in GHC.Base
    {-# INLINE quot    #-}
    {-# INLINE rem     #-}
    {-# INLINE quotRem #-}
    {-# INLINE div     #-}
    {-# INLINE mod     #-}
    {-# INLINE divMod  #-}

    quot :: Word8 -> Word8 -> Word8
quot    (W8# Word8#
x#) y :: Word8
y@(W8# Word8#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0                  = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`quotWord8#` Word8#
y#)
        | Bool
otherwise               = Word8
forall a. a
divZeroError
    rem :: Word8 -> Word8 -> Word8
rem     (W8# Word8#
x#) y :: Word8
y@(W8# Word8#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0                  = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`remWord8#` Word8#
y#)
        | Bool
otherwise               = Word8
forall a. a
divZeroError
    quotRem :: Word8 -> Word8 -> (Word8, Word8)
quotRem (W8# Word8#
x#) y :: Word8
y@(W8# Word8#
y#)
        | Word8
y Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0                  = case Word8#
x# Word8# -> Word8# -> (# Word8#, Word8# #)
`quotRemWord8#` Word8#
y# of
                                      (# Word8#
q, Word8#
r #) -> (Word8# -> Word8
W8# Word8#
q, Word8# -> Word8
W8# Word8#
r)
        | Bool
otherwise               = (Word8, Word8)
forall a. a
divZeroError

    div :: Word8 -> Word8 -> Word8
div    Word8
x Word8
y = Word8 -> Word8 -> Word8
forall a. Integral a => a -> a -> a
quot Word8
x Word8
y
    mod :: Word8 -> Word8 -> Word8
mod    Word8
x Word8
y = Word8 -> Word8 -> Word8
forall a. Integral a => a -> a -> a
rem Word8
x Word8
y
    divMod :: Word8 -> Word8 -> (Word8, Word8)
divMod Word8
x Word8
y = Word8 -> Word8 -> (Word8, Word8)
forall a. Integral a => a -> a -> (a, a)
quotRem Word8
x Word8
y

    toInteger :: Word8 -> Integer
toInteger (W8# Word8#
x#)            = Int# -> Integer
IS (Word# -> Int#
word2Int# (Word8# -> Word#
word8ToWord# Word8#
x#))

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

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

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

    (W8# Word8#
x#) .&. :: Word8 -> Word8 -> Word8
.&.   (W8# Word8#
y#)   = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`andWord8#` Word8#
y#)
    (W8# Word8#
x#) .|. :: Word8 -> Word8 -> Word8
.|.   (W8# Word8#
y#)   = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`orWord8#`  Word8#
y#)
    (W8# Word8#
x#) xor :: Word8 -> Word8 -> Word8
`xor` (W8# Word8#
y#)   = Word8# -> Word8
W8# (Word8#
x# Word8# -> Word8# -> Word8#
`xorWord8#` Word8#
y#)
    complement :: Word8 -> Word8
complement (W8# Word8#
x#)       = Word8# -> Word8
W8# (Word8# -> Word8#
notWord8# Word8#
x#)
    (W8# Word8#
x#) shift :: Word8 -> Int -> Word8
`shift` (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word8# -> Word8
W8# (Word8#
x# Word8# -> Int# -> Word8#
`shiftLWord8#` Int#
i#)
        | Bool
otherwise           = Word8# -> Word8
W8# (Word8#
x# Word8# -> Int# -> Word8#
`shiftRLWord8#` Int# -> Int#
negateInt# Int#
i#)
    (W8# Word8#
x#) shiftL :: Word8 -> Int -> Word8
`shiftL`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word8# -> Word8
W8# (Word8#
x# Word8# -> Int# -> Word8#
`shiftLWord8#` Int#
i#)
        | Bool
otherwise           = Word8
forall a. a
overflowError
    (W8# Word8#
x#) unsafeShiftL :: Word8 -> Int -> Word8
`unsafeShiftL` (I# Int#
i#) =
        Word8# -> Word8
W8# (Word8#
x# Word8# -> Int# -> Word8#
`uncheckedShiftLWord8#` Int#
i#)
    (W8# Word8#
x#) shiftR :: Word8 -> Int -> Word8
`shiftR`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#) = Word8# -> Word8
W8# (Word8#
x# Word8# -> Int# -> Word8#
`shiftRLWord8#` Int#
i#)
        | Bool
otherwise           = Word8
forall a. a
overflowError
    (W8# Word8#
x#) unsafeShiftR :: Word8 -> Int -> Word8
`unsafeShiftR` (I# Int#
i#) = Word8# -> Word8
W8# (Word8#
x# Word8# -> Int# -> Word8#
`uncheckedShiftRLWord8#` Int#
i#)
    (W8# Word8#
x#) rotate :: Word8 -> Int -> Word8
`rotate`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word8# -> Word8
W8# Word8#
x#
        | Bool
otherwise  = Word8# -> Word8
W8# ((Word8#
x# Word8# -> Int# -> Word8#
`uncheckedShiftLWord8#` Int#
i'#) Word8# -> Word8# -> Word8#
`orWord8#`
                            (Word8#
x# Word8# -> Int# -> Word8#
`uncheckedShiftRLWord8#` (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# Word8#
x#)         = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt8# (Word8# -> Word#
word8ToWord# Word8#
x#)))
    bit :: Int -> Word8
bit Int
i                     = Int -> Word8
forall a. (Bits a, Num a) => Int -> a
bitDefault Int
i
    testBit :: Word8 -> Int -> Bool
testBit Word8
a Int
i               = Word8 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault Word8
a Int
i

-- | @since 4.6.0.0
instance FiniteBits Word8 where
    {-# INLINE countLeadingZeros #-}
    {-# INLINE countTrailingZeros #-}
    finiteBitSize :: Word8 -> Int
finiteBitSize Word8
_ = Int
8
    countLeadingZeros :: Word8 -> Int
countLeadingZeros  (W8# Word8#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
clz8# (Word8# -> Word#
word8ToWord# Word8#
x#)))
    countTrailingZeros :: Word8 -> Int
countTrailingZeros (W8# Word8#
x#) = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
ctz8# (Word8# -> Word#
word8ToWord# Word8#
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# Word16#
-- ^ 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# Word16#
x) (W16# Word16#
y) = Int# -> Bool
isTrue# (Word16#
x Word16# -> Word16# -> Int#
`eqWord16#` Word16#
y)
neWord16 :: Word16 -> Word16 -> Bool
neWord16 (W16# Word16#
x) (W16# Word16#
y) = Int# -> Bool
isTrue# (Word16#
x Word16# -> Word16# -> Int#
`neWord16#` Word16#
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# Word16#
x) gtWord16 :: Word16 -> Word16 -> Bool
`gtWord16` (W16# Word16#
y) = Int# -> Bool
isTrue# (Word16#
x Word16# -> Word16# -> Int#
`gtWord16#` Word16#
y)
(W16# Word16#
x) geWord16 :: Word16 -> Word16 -> Bool
`geWord16` (W16# Word16#
y) = Int# -> Bool
isTrue# (Word16#
x Word16# -> Word16# -> Int#
`geWord16#` Word16#
y)
(W16# Word16#
x) ltWord16 :: Word16 -> Word16 -> Bool
`ltWord16` (W16# Word16#
y) = Int# -> Bool
isTrue# (Word16#
x Word16# -> Word16# -> Int#
`ltWord16#` Word16#
y)
(W16# Word16#
x) leWord16 :: Word16 -> Word16 -> Bool
`leWord16` (W16# Word16#
y) = Int# -> Bool
isTrue# (Word16#
x Word16# -> Word16# -> Int#
`leWord16#` Word16#
y)

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

-- | @since 2.01
instance Num Word16 where
    (W16# Word16#
x#) + :: Word16 -> Word16 -> Word16
+ (W16# Word16#
y#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`plusWord16#` Word16#
y#)
    (W16# Word16#
x#) - :: Word16 -> Word16 -> Word16
- (W16# Word16#
y#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`subWord16#` Word16#
y#)
    (W16# Word16#
x#) * :: Word16 -> Word16 -> Word16
* (W16# Word16#
y#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`timesWord16#` Word16#
y#)
    negate :: Word16 -> Word16
negate (W16# Word16#
x#)       = Word16# -> Word16
W16# (Int16# -> Word16#
int16ToWord16# (Int16# -> Int16#
negateInt16# (Word16# -> Int16#
word16ToInt16# Word16#
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          = Word16# -> Word16
W16# (Word# -> Word16#
wordToWord16# (Integer -> Word#
integerToWord# Integer
i))

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

-- | @since 2.01
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)
                        = Word16# -> Word16
W16# (Word# -> Word16#
wordToWord16# (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# Word16#
x#)  = Int# -> Int
I# (Word# -> Int#
word2Int# (Word16# -> Word#
word16ToWord# Word16#
x#))
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFrom #-}
    enumFrom :: Word16 -> [Word16]
enumFrom            = Word16 -> [Word16]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromThen #-}
    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
    -- see Note [INLINE division wrappers] in GHC.Base
    {-# INLINE quot    #-}
    {-# INLINE rem     #-}
    {-# INLINE quotRem #-}
    {-# INLINE div     #-}
    {-# INLINE mod     #-}
    {-# INLINE divMod  #-}

    quot :: Word16 -> Word16 -> Word16
quot    (W16# Word16#
x#) y :: Word16
y@(W16# Word16#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0                    = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`quotWord16#` Word16#
y#)
        | Bool
otherwise                 = Word16
forall a. a
divZeroError
    rem :: Word16 -> Word16 -> Word16
rem     (W16# Word16#
x#) y :: Word16
y@(W16# Word16#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0                    = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`remWord16#` Word16#
y#)
        | Bool
otherwise                 = Word16
forall a. a
divZeroError
    quotRem :: Word16 -> Word16 -> (Word16, Word16)
quotRem (W16# Word16#
x#) y :: Word16
y@(W16# Word16#
y#)
        | Word16
y Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word16
0                    = case Word16#
x# Word16# -> Word16# -> (# Word16#, Word16# #)
`quotRemWord16#` Word16#
y# of
                                        (# Word16#
q, Word16#
r #) -> (Word16# -> Word16
W16# Word16#
q, Word16# -> Word16
W16# Word16#
r)
        | Bool
otherwise                 = (Word16, Word16)
forall a. a
divZeroError

    div :: Word16 -> Word16 -> Word16
div    Word16
x Word16
y = Word16 -> Word16 -> Word16
forall a. Integral a => a -> a -> a
quot Word16
x Word16
y
    mod :: Word16 -> Word16 -> Word16
mod    Word16
x Word16
y = Word16 -> Word16 -> Word16
forall a. Integral a => a -> a -> a
rem Word16
x Word16
y
    divMod :: Word16 -> Word16 -> (Word16, Word16)
divMod Word16
x Word16
y = Word16 -> Word16 -> (Word16, Word16)
forall a. Integral a => a -> a -> (a, a)
quotRem Word16
x Word16
y

    toInteger :: Word16 -> Integer
toInteger (W16# Word16#
x#)             = Int# -> Integer
IS (Word# -> Int#
word2Int# (Word16# -> Word#
word16ToWord# Word16#
x#))

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

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

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

    (W16# Word16#
x#) .&. :: Word16 -> Word16 -> Word16
.&.   (W16# Word16#
y#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`andWord16#` Word16#
y#)
    (W16# Word16#
x#) .|. :: Word16 -> Word16 -> Word16
.|.   (W16# Word16#
y#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`orWord16#`  Word16#
y#)
    (W16# Word16#
x#) xor :: Word16 -> Word16 -> Word16
`xor` (W16# Word16#
y#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Word16# -> Word16#
`xorWord16#` Word16#
y#)
    complement :: Word16 -> Word16
complement (W16# Word16#
x#)       = Word16# -> Word16
W16# (Word16# -> Word16#
notWord16# Word16#
x#)
    (W16# Word16#
x#) shift :: Word16 -> Int -> Word16
`shift` (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Int# -> Word16#
`shiftLWord16#` Int#
i#)
        | Bool
otherwise            = Word16# -> Word16
W16# (Word16#
x# Word16# -> Int# -> Word16#
`shiftRLWord16#` Int# -> Int#
negateInt# Int#
i#)
    (W16# Word16#
x#) shiftL :: Word16 -> Int -> Word16
`shiftL`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Int# -> Word16#
`shiftLWord16#` Int#
i#)
        | Bool
otherwise            = Word16
forall a. a
overflowError
    (W16# Word16#
x#) unsafeShiftL :: Word16 -> Int -> Word16
`unsafeShiftL` (I# Int#
i#) =
        Word16# -> Word16
W16# (Word16#
x# Word16# -> Int# -> Word16#
`uncheckedShiftLWord16#` Int#
i#)
    (W16# Word16#
x#) shiftR :: Word16 -> Int -> Word16
`shiftR`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word16# -> Word16
W16# (Word16#
x# Word16# -> Int# -> Word16#
`shiftRLWord16#` Int#
i#)
        | Bool
otherwise            = Word16
forall a. a
overflowError
    (W16# Word16#
x#) unsafeShiftR :: Word16 -> Int -> Word16
`unsafeShiftR` (I# Int#
i#) = Word16# -> Word16
W16# (Word16#
x# Word16# -> Int# -> Word16#
`uncheckedShiftRLWord16#` Int#
i#)
    (W16# Word16#
x#) rotate :: Word16 -> Int -> Word16
`rotate`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word16# -> Word16
W16# Word16#
x#
        | Bool
otherwise  = Word16# -> Word16
W16# ((Word16#
x# Word16# -> Int# -> Word16#
`uncheckedShiftLWord16#` Int#
i'#) Word16# -> Word16# -> Word16#
`orWord16#`
                             (Word16#
x# Word16# -> Int# -> Word16#
`uncheckedShiftRLWord16#` (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# Word16#
x#)        = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt16# (Word16# -> Word#
word16ToWord# Word16#
x#)))
    bit :: Int -> Word16
bit Int
i                     = Int -> Word16
forall a. (Bits a, Num a) => Int -> a
bitDefault Int
i
    testBit :: Word16 -> Int -> Bool
testBit Word16
a Int
i               = Word16 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault Word16
a Int
i

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

-- | Reverse order of bytes in 'Word16'.
--
-- @since 4.7.0.0
byteSwap16 :: Word16 -> Word16
byteSwap16 :: Word16 -> Word16
byteSwap16 (W16# Word16#
w#) = Word16# -> Word16
W16# (Word# -> Word16#
wordToWord16# (Word# -> Word#
byteSwap16# (Word16# -> Word#
word16ToWord# Word16#
w#)))

{-# 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# Word32#
-- ^ 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# Word32#
x) (W32# Word32#
y) = Int# -> Bool
isTrue# (Word32#
x Word32# -> Word32# -> Int#
`eqWord32#` Word32#
y)
neWord32 :: Word32 -> Word32 -> Bool
neWord32 (W32# Word32#
x) (W32# Word32#
y) = Int# -> Bool
isTrue# (Word32#
x Word32# -> Word32# -> Int#
`neWord32#` Word32#
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# Word32#
x) gtWord32 :: Word32 -> Word32 -> Bool
`gtWord32` (W32# Word32#
y) = Int# -> Bool
isTrue# (Word32#
x Word32# -> Word32# -> Int#
`gtWord32#` Word32#
y)
(W32# Word32#
x) geWord32 :: Word32 -> Word32 -> Bool
`geWord32` (W32# Word32#
y) = Int# -> Bool
isTrue# (Word32#
x Word32# -> Word32# -> Int#
`geWord32#` Word32#
y)
(W32# Word32#
x) ltWord32 :: Word32 -> Word32 -> Bool
`ltWord32` (W32# Word32#
y) = Int# -> Bool
isTrue# (Word32#
x Word32# -> Word32# -> Int#
`ltWord32#` Word32#
y)
(W32# Word32#
x) leWord32 :: Word32 -> Word32 -> Bool
`leWord32` (W32# Word32#
y) = Int# -> Bool
isTrue# (Word32#
x Word32# -> Word32# -> Int#
`leWord32#` Word32#
y)

-- | @since 2.01
instance Num Word32 where
    (W32# Word32#
x#) + :: Word32 -> Word32 -> Word32
+ (W32# Word32#
y#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`plusWord32#` Word32#
y#)
    (W32# Word32#
x#) - :: Word32 -> Word32 -> Word32
- (W32# Word32#
y#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`subWord32#` Word32#
y#)
    (W32# Word32#
x#) * :: Word32 -> Word32 -> Word32
* (W32# Word32#
y#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`timesWord32#` Word32#
y#)
    negate :: Word32 -> Word32
negate (W32# Word32#
x#)       = Word32# -> Word32
W32# (Int32# -> Word32#
int32ToWord32# (Int32# -> Int32#
negateInt32# (Word32# -> Int32#
word32ToInt32# Word32#
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          = Word32# -> Word32
W32# (Word# -> Word32#
wordToWord32# (Integer -> Word#
integerToWord# Integer
i))

-- | @since 2.01
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
                        = Word32# -> Word32
W32# (Word# -> Word32#
wordToWord32# (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# (word32ToWord# x#))
        | otherwise     = fromEnumError "Word32" x
    enumFrom            = integralEnumFrom
    enumFromThen        = integralEnumFromThen
    enumFromTo          = integralEnumFromTo
    enumFromThenTo      = integralEnumFromThenTo
#else
    fromEnum :: Word32 -> Int
fromEnum (W32# Word32#
x#)  = Int# -> Int
I# (Word# -> Int#
word2Int# (Word32# -> Word#
word32ToWord# Word32#
x#))
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFrom #-}
    enumFrom :: Word32 -> [Word32]
enumFrom            = Word32 -> [Word32]
forall a. (Enum a, Bounded a) => a -> [a]
boundedEnumFrom
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromThen #-}
    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
    -- see Note [INLINE division wrappers] in GHC.Base
    {-# INLINE quot    #-}
    {-# INLINE rem     #-}
    {-# INLINE quotRem #-}
    {-# INLINE div     #-}
    {-# INLINE mod     #-}
    {-# INLINE divMod  #-}

    quot :: Word32 -> Word32 -> Word32
quot    (W32# Word32#
x#) y :: Word32
y@(W32# Word32#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0                    = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`quotWord32#` Word32#
y#)
        | Bool
otherwise                 = Word32
forall a. a
divZeroError
    rem :: Word32 -> Word32 -> Word32
rem     (W32# Word32#
x#) y :: Word32
y@(W32# Word32#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0                    = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`remWord32#` Word32#
y#)
        | Bool
otherwise                 = Word32
forall a. a
divZeroError
    quotRem :: Word32 -> Word32 -> (Word32, Word32)
quotRem (W32# Word32#
x#) y :: Word32
y@(W32# Word32#
y#)
        | Word32
y Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word32
0                    = case Word32#
x# Word32# -> Word32# -> (# Word32#, Word32# #)
`quotRemWord32#` Word32#
y# of
                                        (# Word32#
q, Word32#
r #) -> (Word32# -> Word32
W32# Word32#
q, Word32# -> Word32
W32# Word32#
r)
        | Bool
otherwise                 = (Word32, Word32)
forall a. a
divZeroError

    div :: Word32 -> Word32 -> Word32
div    Word32
x Word32
y = Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
quot Word32
x Word32
y
    mod :: Word32 -> Word32 -> Word32
mod    Word32
x Word32
y = Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
rem Word32
x Word32
y
    divMod :: Word32 -> Word32 -> (Word32, Word32)
divMod Word32
x Word32
y = Word32 -> Word32 -> (Word32, Word32)
forall a. Integral a => a -> a -> (a, a)
quotRem Word32
x Word32
y

    toInteger :: Word32 -> Integer
toInteger (W32# Word32#
x#)             = Word# -> Integer
integerFromWord# (Word32# -> Word#
word32ToWord# Word32#
x#)

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

    (W32# Word32#
x#) .&. :: Word32 -> Word32 -> Word32
.&.   (W32# Word32#
y#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`andWord32#` Word32#
y#)
    (W32# Word32#
x#) .|. :: Word32 -> Word32 -> Word32
.|.   (W32# Word32#
y#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`orWord32#`  Word32#
y#)
    (W32# Word32#
x#) xor :: Word32 -> Word32 -> Word32
`xor` (W32# Word32#
y#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Word32# -> Word32#
`xorWord32#` Word32#
y#)
    complement :: Word32 -> Word32
complement (W32# Word32#
x#)       = Word32# -> Word32
W32# (Word32# -> Word32#
notWord32# Word32#
x#)
    (W32# Word32#
x#) shift :: Word32 -> Int -> Word32
`shift` (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Int# -> Word32#
`shiftLWord32#` Int#
i#)
        | Bool
otherwise            = Word32# -> Word32
W32# (Word32#
x# Word32# -> Int# -> Word32#
`shiftRLWord32#` Int# -> Int#
negateInt# Int#
i#)
    (W32# Word32#
x#) shiftL :: Word32 -> Int -> Word32
`shiftL`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Int# -> Word32#
`shiftLWord32#` Int#
i#)
        | Bool
otherwise            = Word32
forall a. a
overflowError
    (W32# Word32#
x#) unsafeShiftL :: Word32 -> Int -> Word32
`unsafeShiftL` (I# Int#
i#) =
        Word32# -> Word32
W32# (Word32#
x# Word32# -> Int# -> Word32#
`uncheckedShiftLWord32#` Int#
i#)
    (W32# Word32#
x#) shiftR :: Word32 -> Int -> Word32
`shiftR`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word32# -> Word32
W32# (Word32#
x# Word32# -> Int# -> Word32#
`shiftRLWord32#` Int#
i#)
        | Bool
otherwise            = Word32
forall a. a
overflowError
    (W32# Word32#
x#) unsafeShiftR :: Word32 -> Int -> Word32
`unsafeShiftR` (I# Int#
i#) = Word32# -> Word32
W32# (Word32#
x# Word32# -> Int# -> Word32#
`uncheckedShiftRLWord32#` Int#
i#)
    (W32# Word32#
x#) rotate :: Word32 -> Int -> Word32
`rotate`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word32# -> Word32
W32# Word32#
x#
        | Bool
otherwise   = Word32# -> Word32
W32# ((Word32#
x# Word32# -> Int# -> Word32#
`uncheckedShiftLWord32#` Int#
i'#) Word32# -> Word32# -> Word32#
`orWord32#`
                              (Word32#
x# Word32# -> Int# -> Word32#
`uncheckedShiftRLWord32#` (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# Word32#
x#)        = Int# -> Int
I# (Word# -> Int#
word2Int# (Word# -> Word#
popCnt32# (Word32# -> Word#
word32ToWord# Word32#
x#)))
    bit :: Int -> Word32
bit Int
i                     = Int -> Word32
forall a. (Bits a, Num a) => Int -> a
bitDefault Int
i
    testBit :: Word32 -> Int -> Bool
testBit Word32
a Int
i               = Word32 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault Word32
a Int
i

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


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

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

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

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

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

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
    == :: 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# Word64#
x) (W64# Word64#
y) = Int# -> Bool
isTrue# (Word64#
x Word64# -> Word64# -> Int#
`eqWord64#` Word64#
y)
neWord64 :: Word64 -> Word64 -> Bool
neWord64 (W64# Word64#
x) (W64# Word64#
y) = Int# -> Bool
isTrue# (Word64#
x Word64# -> Word64# -> Int#
`neWord64#` Word64#
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# Word64#
x) gtWord64 :: Word64 -> Word64 -> Bool
`gtWord64` (W64# Word64#
y) = Int# -> Bool
isTrue# (Word64#
x Word64# -> Word64# -> Int#
`gtWord64#` Word64#
y)
(W64# Word64#
x) geWord64 :: Word64 -> Word64 -> Bool
`geWord64` (W64# Word64#
y) = Int# -> Bool
isTrue# (Word64#
x Word64# -> Word64# -> Int#
`geWord64#` Word64#
y)
(W64# Word64#
x) ltWord64 :: Word64 -> Word64 -> Bool
`ltWord64` (W64# Word64#
y) = Int# -> Bool
isTrue# (Word64#
x Word64# -> Word64# -> Int#
`ltWord64#` Word64#
y)
(W64# Word64#
x) leWord64 :: Word64 -> Word64 -> Bool
`leWord64` (W64# Word64#
y) = Int# -> Bool
isTrue# (Word64#
x Word64# -> Word64# -> Int#
`leWord64#` Word64#
y)

-- | @since 2.01
instance Num Word64 where
    (W64# Word64#
x#) + :: Word64 -> Word64 -> Word64
+ (W64# Word64#
y#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`plusWord64#` Word64#
y#)
    (W64# Word64#
x#) - :: Word64 -> Word64 -> Word64
- (W64# Word64#
y#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`subWord64#` Word64#
y#)
    (W64# Word64#
x#) * :: Word64 -> Word64 -> Word64
* (W64# Word64#
y#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`timesWord64#` Word64#
y#)
    negate :: Word64 -> Word64
negate (W64# Word64#
x#)       = Word64# -> Word64
W64# (Int64# -> Word64#
int64ToWord64# (Int64# -> Int64#
negateInt64# (Word64# -> Int64#
word64ToInt64# Word64#
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          = Word64# -> Word64
W64# (Integer -> Word64#
integerToWord64# Integer
i)

-- | @since 2.01
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        = Word64# -> Word64
W64# (Word# -> Word64#
wordToWord64# (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# Word64#
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# (Word64# -> Word#
word64ToWord# Word64#
x#))
        | Bool
otherwise     = String -> Word64 -> Int
forall a b. Show a => String -> a -> b
fromEnumError String
"Word64" Word64
x
#if WORD_SIZE_IN_BITS < 64
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFrom #-}
    enumFrom            = integralEnumFrom
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromThen #-}
    enumFromThen        = integralEnumFromThen
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromTo #-}
    enumFromTo          = integralEnumFromTo
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromThenTo #-}
    enumFromThenTo      = integralEnumFromThenTo
#else
    -- use Word's Enum as it has better support for fusion. We can't use
    -- `boundedEnumFrom` and `boundedEnumFromThen` -- which use Int's Enum
    -- instance -- because Word64 isn't compatible with Int/Int64's domain.
    --
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFrom #-}
    enumFrom :: Word64 -> [Word64]
enumFrom Word64
x          = (Word -> Word64) -> [Word] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> [Word]
forall a. Enum a => a -> [a]
enumFrom (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x :: Word))
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromThen #-}
    enumFromThen :: Word64 -> Word64 -> [Word64]
enumFromThen Word64
x Word64
y    = (Word -> Word64) -> [Word] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Word -> [Word]
forall a. Enum a => a -> a -> [a]
enumFromThen (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x :: Word) (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
y))
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromTo #-}
    enumFromTo :: Word64 -> Word64 -> [Word64]
enumFromTo Word64
x Word64
y      = (Word -> Word64) -> [Word] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Word -> [Word]
forall a. Enum a => a -> a -> [a]
enumFromTo (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x :: Word) (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
y))
    -- See Note [Stable Unfolding for list producers] in GHC.Enum
    {-# INLINE enumFromThenTo #-}
    enumFromThenTo :: Word64 -> Word64 -> Word64 -> [Word64]
enumFromThenTo Word64
x Word64
y Word64
z = (Word -> Word64) -> [Word] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Word -> Word -> [Word]
forall a. Enum a => a -> a -> a -> [a]
enumFromThenTo (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x :: Word) (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
y) (Word64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
z))
#endif

-- | @since 2.01
instance Integral Word64 where
    -- see Note [INLINE division wrappers] in GHC.Base
    {-# INLINE quot    #-}
    {-# INLINE rem     #-}
    {-# INLINE quotRem #-}
    {-# INLINE div     #-}
    {-# INLINE mod     #-}
    {-# INLINE divMod  #-}

    quot :: Word64 -> Word64 -> Word64
quot    (W64# Word64#
x#) y :: Word64
y@(W64# Word64#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0                    = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`quotWord64#` Word64#
y#)
        | Bool
otherwise                 = Word64
forall a. a
divZeroError
    rem :: Word64 -> Word64 -> Word64
rem     (W64# Word64#
x#) y :: Word64
y@(W64# Word64#
y#)
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0                    = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`remWord64#` Word64#
y#)
        | Bool
otherwise                 = Word64
forall a. a
divZeroError
    quotRem :: Word64 -> Word64 -> (Word64, Word64)
quotRem (W64# Word64#
x#) y :: Word64
y@(W64# Word64#
y#)
#if WORD_SIZE_IN_BITS < 64
        | y /= 0                    = (W64# (x# `quotWord64#` y#), W64# (x# `remWord64#` y#))
#else
        -- we don't have a `quotRemWord64#` primitive yet.
        | Word64
y Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0                    = case Word# -> Word# -> (# Word#, Word# #)
quotRemWord# (Word64# -> Word#
word64ToWord# Word64#
x#) (Word64# -> Word#
word64ToWord# Word64#
y#) of
                                        (# Word#
q, Word#
r #) -> (Word64# -> Word64
W64# (Word# -> Word64#
wordToWord64# Word#
q),  Word64# -> Word64
W64# (Word# -> Word64#
wordToWord64# Word#
r))
#endif
        | Bool
otherwise                 = (Word64, Word64)
forall a. a
divZeroError

    div :: Word64 -> Word64 -> Word64
div    Word64
x Word64
y = Word64 -> Word64 -> Word64
forall a. Integral a => a -> a -> a
quot Word64
x Word64
y
    mod :: Word64 -> Word64 -> Word64
mod    Word64
x Word64
y = Word64 -> Word64 -> Word64
forall a. Integral a => a -> a -> a
rem Word64
x Word64
y
    divMod :: Word64 -> Word64 -> (Word64, Word64)
divMod Word64
x Word64
y = Word64 -> Word64 -> (Word64, Word64)
forall a. Integral a => a -> a -> (a, a)
quotRem Word64
x Word64
y

    toInteger :: Word64 -> Integer
toInteger (W64# Word64#
x#)             = Word64# -> Integer
integerFromWord64# Word64#
x#

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

    (W64# Word64#
x#) .&. :: Word64 -> Word64 -> Word64
.&.   (W64# Word64#
y#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`and64#` Word64#
y#)
    (W64# Word64#
x#) .|. :: Word64 -> Word64 -> Word64
.|.   (W64# Word64#
y#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`or64#`  Word64#
y#)
    (W64# Word64#
x#) xor :: Word64 -> Word64 -> Word64
`xor` (W64# Word64#
y#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Word64# -> Word64#
`xor64#` Word64#
y#)
    complement :: Word64 -> Word64
complement (W64# Word64#
x#)       = Word64# -> Word64
W64# (Word64# -> Word64#
not64# Word64#
x#)
    (W64# Word64#
x#) shift :: Word64 -> Int -> Word64
`shift` (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Int# -> Word64#
`shiftLWord64#` Int#
i#)
        | Bool
otherwise            = Word64# -> Word64
W64# (Word64#
x# Word64# -> Int# -> Word64#
`shiftRLWord64#` Int# -> Int#
negateInt# Int#
i#)
    (W64# Word64#
x#) shiftL :: Word64 -> Int -> Word64
`shiftL`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Int# -> Word64#
`shiftLWord64#` Int#
i#)
        | Bool
otherwise            = Word64
forall a. a
overflowError
    (W64# Word64#
x#) unsafeShiftL :: Word64 -> Int -> Word64
`unsafeShiftL` (I# Int#
i#) = Word64# -> Word64
W64# (Word64#
x# Word64# -> Int# -> Word64#
`uncheckedShiftL64#` Int#
i#)
    (W64# Word64#
x#) shiftR :: Word64 -> Int -> Word64
`shiftR`       (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
>=# Int#
0#)  = Word64# -> Word64
W64# (Word64#
x# Word64# -> Int# -> Word64#
`shiftRLWord64#` Int#
i#)
        | Bool
otherwise            = Word64
forall a. a
overflowError
    (W64# Word64#
x#) unsafeShiftR :: Word64 -> Int -> Word64
`unsafeShiftR` (I# Int#
i#) = Word64# -> Word64
W64# (Word64#
x# Word64# -> Int# -> Word64#
`uncheckedShiftRL64#` Int#
i#)
    (W64# Word64#
x#) rotate :: Word64 -> Int -> Word64
`rotate` (I# Int#
i#)
        | Int# -> Bool
isTrue# (Int#
i'# Int# -> Int# -> Int#
==# Int#
0#) = Word64# -> Word64
W64# Word64#
x#
        | Bool
otherwise            = Word64# -> Word64
W64# ((Word64#
x# Word64# -> Int# -> Word64#
`uncheckedShiftL64#` Int#
i'#) Word64# -> Word64# -> Word64#
`or64#`
                                       (Word64#
x# Word64# -> Int# -> Word64#
`uncheckedShiftRL64#` (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# Word64#
x#)        = Int# -> Int
I# (Word# -> Int#
word2Int# (Word64# -> Word#
popCnt64# Word64#
x#))
    bit :: Int -> Word64
bit Int
i                     = Int -> Word64
forall a. (Bits a, Num a) => Int -> a
bitDefault Int
i
    testBit :: Word64 -> Int -> Bool
testBit Word64
a Int
i               = Word64 -> Int -> Bool
forall a. (Bits a, Num a) => a -> Int -> Bool
testBitDefault Word64
a Int
i

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

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

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

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

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

-- | Reverse order of bytes in 'Word64'.
--
-- @since 4.7.0.0
byteSwap64 :: Word64 -> Word64
byteSwap64 :: Word64 -> Word64
byteSwap64 (W64# Word64#
w#) = Word64# -> Word64
W64# (Word64# -> Word64#
byteSwap64# Word64#
w#)

-- | Reverse the order of the bits in a 'Word8'.
--
-- @since 4.14.0.0
bitReverse8 :: Word8 -> Word8
bitReverse8 :: Word8 -> Word8
bitReverse8 (W8# Word8#
w#) = Word8# -> Word8
W8# (Word# -> Word8#
wordToWord8# (Word# -> Word#
bitReverse8# (Word8# -> Word#
word8ToWord# Word8#
w#)))

-- | Reverse the order of the bits in a 'Word16'.
--
-- @since 4.14.0.0
bitReverse16 :: Word16 -> Word16
bitReverse16 :: Word16 -> Word16
bitReverse16 (W16# Word16#
w#) = Word16# -> Word16
W16# (Word# -> Word16#
wordToWord16# (Word# -> Word#
bitReverse16# (Word16# -> Word#
word16ToWord# Word16#
w#)))

-- | Reverse the order of the bits in a 'Word32'.
--
-- @since 4.14.0.0
bitReverse32 :: Word32 -> Word32
bitReverse32 :: Word32 -> Word32
bitReverse32 (W32# Word32#
w#) = Word32# -> Word32
W32# (Word# -> Word32#
wordToWord32# (Word# -> Word#
bitReverse32# (Word32# -> Word#
word32ToWord# Word32#
w#)))

-- | Reverse the order of the bits in a 'Word64'.
--
-- @since 4.14.0.0
bitReverse64 :: Word64 -> Word64
bitReverse64 :: Word64 -> Word64
bitReverse64 (W64# Word64#
w#) = Word64# -> Word64
W64# (Word64# -> Word64#
bitReverse64# Word64#
w#)

-------------------------------------------------------------------------------

-- unchecked shift primops may be lowered into C shift operations which have
-- unspecified behaviour if the amount of bits to shift is greater or equal to the word
-- size in bits.
-- The following safe shift operations wrap unchecked primops to take this into
-- account: 0 is consistently returned when the shift amount is too big.

shiftRLWord8# :: Word8# -> Int# -> Word8#
Word8#
a shiftRLWord8# :: Word8# -> Int# -> Word8#
`shiftRLWord8#` Int#
b = Word8# -> Int# -> Word8#
uncheckedShiftRLWord8# Word8#
a Int#
b
                       Word8# -> Word8# -> Word8#
`andWord8#` Word# -> Word8#
wordToWord8# (Int# -> Word#
int2Word# (Int# -> Int# -> Int#
shift_mask Int#
8# Int#
b))

shiftRLWord16# :: Word16# -> Int# -> Word16#
Word16#
a shiftRLWord16# :: Word16# -> Int# -> Word16#
`shiftRLWord16#` Int#
b = Word16# -> Int# -> Word16#
uncheckedShiftRLWord16# Word16#
a Int#
b
                       Word16# -> Word16# -> Word16#
`andWord16#` Word# -> Word16#
wordToWord16# (Int# -> Word#
int2Word# (Int# -> Int# -> Int#
shift_mask Int#
16# Int#
b))

shiftRLWord32# :: Word32# -> Int# -> Word32#
Word32#
a shiftRLWord32# :: Word32# -> Int# -> Word32#
`shiftRLWord32#` Int#
b = Word32# -> Int# -> Word32#
uncheckedShiftRLWord32# Word32#
a Int#
b
                       Word32# -> Word32# -> Word32#
`andWord32#` Word# -> Word32#
wordToWord32# (Int# -> Word#
int2Word# (Int# -> Int# -> Int#
shift_mask Int#
32# Int#
b))

shiftRLWord64# :: Word64# -> Int# -> Word64#
Word64#
a shiftRLWord64# :: Word64# -> Int# -> Word64#
`shiftRLWord64#` Int#
b = Word64# -> Int# -> Word64#
uncheckedShiftRL64# Word64#
a Int#
b
                    Word64# -> Word64# -> Word64#
`and64#` Int64# -> Word64#
int64ToWord64# (Int# -> Int64#
intToInt64# (Int# -> Int# -> Int#
shift_mask Int#
64# Int#
b))

shiftLWord8# :: Word8# -> Int# -> Word8#
Word8#
a shiftLWord8# :: Word8# -> Int# -> Word8#
`shiftLWord8#` Int#
b = Word8# -> Int# -> Word8#
uncheckedShiftLWord8# Word8#
a Int#
b
                      Word8# -> Word8# -> Word8#
`andWord8#` Word# -> Word8#
wordToWord8# (Int# -> Word#
int2Word# (Int# -> Int# -> Int#
shift_mask Int#
8# Int#
b))

shiftLWord16# :: Word16# -> Int# -> Word16#
Word16#
a shiftLWord16# :: Word16# -> Int# -> Word16#
`shiftLWord16#` Int#
b = Word16# -> Int# -> Word16#
uncheckedShiftLWord16# Word16#
a Int#
b
                       Word16# -> Word16# -> Word16#
`andWord16#` Word# -> Word16#
wordToWord16# (Int# -> Word#
int2Word# (Int# -> Int# -> Int#
shift_mask Int#
16# Int#
b))

shiftLWord32# :: Word32# -> Int# -> Word32#
Word32#
a shiftLWord32# :: Word32# -> Int# -> Word32#
`shiftLWord32#` Int#
b = Word32# -> Int# -> Word32#
uncheckedShiftLWord32# Word32#
a Int#
b
                       Word32# -> Word32# -> Word32#
`andWord32#` Word# -> Word32#
wordToWord32# (Int# -> Word#
int2Word# (Int# -> Int# -> Int#
shift_mask Int#
32# Int#
b))

shiftLWord64# :: Word64# -> Int# -> Word64#
Word64#
a shiftLWord64# :: Word64# -> Int# -> Word64#
`shiftLWord64#` Int#
b  = Word64# -> Int# -> Word64#
uncheckedShiftL64# Word64#
a Int#
b
                    Word64# -> Word64# -> Word64#
`and64#` Int64# -> Word64#
int64ToWord64# (Int# -> Int64#
intToInt64# (Int# -> Int# -> Int#
shift_mask Int#
64# Int#
b))