module CLaSH.Bit
(Bit(..))
where
import Data.Bits
import Data.Default
import Language.Haskell.TH.Lift
data Bit = L
| H
instance Eq Bit where
(==) = eqBit
eqBit :: Bit -> Bit -> Bool
eqBit L L = True
eqBit H H = True
eqBit _ _ = False
instance Show Bit where
show H = "1"
show L = "0"
instance Default Bit where
def = L
deriveLift ''Bit
bAnd :: Bit -> Bit -> Bit
bAnd H H = H
bAnd _ _ = L
bOr :: Bit -> Bit -> Bit
bOr L L = L
bOr _ _ = H
bXor :: Bit -> Bit -> Bit
bXor L L = L
bXor H H = L
bXor _ _ = H
bNot :: Bit -> Bit
bNot L = H
bNot H = L
instance Bits Bit where
(.&.) = bAnd
(.|.) = bOr
xor = bXor
complement = bNot
bit = const H
testBit H _ = True
testBit _ _ = False
bitSizeMaybe = const (Just 1)
isSigned = const False
popCount H = 1
popCount _ = 0