module Data.DoubleWord.Base
( DoubleWord(..)
) where
import Data.Bits (Bits(..))
import Data.Int
import Data.Word
import Data.BinaryWord
class BinaryWord w ⇒ DoubleWord w where
type LoWord w
type HiWord w
loWord ∷ w → LoWord w
hiWord ∷ w → HiWord w
fromHiAndLo ∷ HiWord w → LoWord w → w
extendLo ∷ LoWord w → w
signExtendLo ∷ SignedWord (LoWord w) → w
instance DoubleWord Word16 where
type LoWord Word16 = Word8
type HiWord Word16 = Word8
loWord w = fromIntegral w
hiWord w = fromIntegral $ shiftR w 8
fromHiAndLo hi lo = shiftL (fromIntegral hi) 8 .|. fromIntegral lo
extendLo = fromIntegral
signExtendLo = fromIntegral
instance DoubleWord Word32 where
type LoWord Word32 = Word16
type HiWord Word32 = Word16
loWord w = fromIntegral w
hiWord w = fromIntegral $ shiftR w 16
fromHiAndLo hi lo = shiftL (fromIntegral hi) 16 .|. fromIntegral lo
extendLo = fromIntegral
signExtendLo = fromIntegral
instance DoubleWord Word64 where
type LoWord Word64 = Word32
type HiWord Word64 = Word32
loWord w = fromIntegral w
hiWord w = fromIntegral $ shiftR w 32
fromHiAndLo hi lo = shiftL (fromIntegral hi) 32 .|. fromIntegral lo
extendLo = fromIntegral
signExtendLo = fromIntegral
instance DoubleWord Int16 where
type LoWord Int16 = Word8
type HiWord Int16 = Int8
loWord w = fromIntegral w
hiWord w = fromIntegral $ shiftR w 8
fromHiAndLo hi lo = shiftL (fromIntegral hi) 8 .|. fromIntegral lo
extendLo = fromIntegral
signExtendLo = fromIntegral
instance DoubleWord Int32 where
type LoWord Int32 = Word16
type HiWord Int32 = Int16
loWord w = fromIntegral w
hiWord w = fromIntegral $ shiftR w 16
fromHiAndLo hi lo = shiftL (fromIntegral hi) 16 .|. fromIntegral lo
extendLo = fromIntegral
signExtendLo = fromIntegral
instance DoubleWord Int64 where
type LoWord Int64 = Word32
type HiWord Int64 = Int32
loWord w = fromIntegral w
hiWord w = fromIntegral $ shiftR w 32
fromHiAndLo hi lo = shiftL (fromIntegral hi) 32 .|. fromIntegral lo
extendLo = fromIntegral
signExtendLo = fromIntegral