Copyright | (C) 2013-2016 University of Twente 2016-2017 Myrtle Software Ltd |
---|---|
License | BSD2 (see the file LICENSE) |
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com> |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Extensions |
|
Synopsis
- class KnownNat (BitSize a) => BitPack a where
- bitCoerce :: (BitPack a, BitPack b, BitSize a ~ BitSize b) => a -> b
- bitCoerceMap :: forall a b. (BitPack a, BitPack b, BitSize a ~ BitSize b) => (a -> a) -> b -> b
- boolToBV :: KnownNat n => Bool -> BitVector (n + 1)
- boolToBit :: Bool -> Bit
- bitToBool :: Bit -> Bool
- packXWith :: KnownNat n => (a -> BitVector n) -> a -> BitVector n
Documentation
class KnownNat (BitSize a) => BitPack a where Source #
Convert to and from a BitVector
Nothing
pack :: a -> BitVector (BitSize a) Source #
Convert element of type a
to a BitVector
>>>
pack (-5 :: Signed 6)
11_1011
default pack :: (Generic a, GBitPack (Rep a), KnownNat (BitSize a), KnownNat constrSize, KnownNat fieldSize, constrSize ~ CLog 2 (GConstructorCount (Rep a)), fieldSize ~ GFieldSize (Rep a), (constrSize + fieldSize) ~ BitSize a) => a -> BitVector (BitSize a) Source #
unpack :: BitVector (BitSize a) -> a Source #
Convert a BitVector
to an element of type a
>>>
pack (-5 :: Signed 6)
11_1011>>>
let x = pack (-5 :: Signed 6)
>>>
unpack x :: Unsigned 6
59>>>
pack (59 :: Unsigned 6)
11_1011
Instances
BitPack Bool Source # | |
BitPack Double Source # | |
BitPack Float Source # | |
BitPack Int Source # | |
BitPack Int8 Source # | |
BitPack Int16 Source # | |
BitPack Int32 Source # | |
BitPack Int64 Source # | |
BitPack Word Source # | |
BitPack Word8 Source # | |
BitPack Word16 Source # | |
BitPack Word32 Source # | |
BitPack Word64 Source # | |
BitPack () Source # | |
BitPack CUShort Source # | |
BitPack Half Source # | |
BitPack Bit Source # | |
BitPack a => BitPack (Maybe a) Source # | |
BitPack a => BitPack (Complex a) Source # | |
BitPack a => BitPack (Down a) Source # | |
KnownNat n => BitPack (BitVector n) Source # | |
(KnownNat n, 1 <= n) => BitPack (Index n) Source # | |
KnownNat n => BitPack (Unsigned n) Source # | |
KnownNat n => BitPack (Signed n) Source # | |
(BitPack a, BitPack b) => BitPack (Either a b) Source # | |
(BitPack a, BitPack b) => BitPack (a, b) Source # | |
(KnownNat n, BitPack a) => BitPack (Vec n a) Source # | |
(KnownNat d, BitPack a) => BitPack (RTree d a) Source # | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3), KnownNat (BitSize (a2, a3))) => BitPack (a1, a2, a3) Source # | |
BitPack (rep (int + frac)) => BitPack (Fixed rep int frac) Source # | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4), KnownNat (BitSize (a2, a3, a4))) => BitPack (a1, a2, a3, a4) Source # | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5), KnownNat (BitSize (a2, a3, a4, a5))) => BitPack (a1, a2, a3, a4, a5) Source # | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5, a6), KnownNat (BitSize (a2, a3, a4, a5, a6))) => BitPack (a1, a2, a3, a4, a5, a6) Source # | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5, a6, a7), KnownNat (BitSize (a2, a3, a4, a5, a6, a7))) => BitPack (a1, a2, a3, a4, a5, a6, a7) Source # | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5, a6, a7, a8), KnownNat (BitSize (a2, a3, a4, a5, a6, a7, a8))) => BitPack (a1, a2, a3, a4, a5, a6, a7, a8) Source # | |
Defined in Clash.Class.BitPack | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5, a6, a7, a8, a9), KnownNat (BitSize (a2, a3, a4, a5, a6, a7, a8, a9))) => BitPack (a1, a2, a3, a4, a5, a6, a7, a8, a9) Source # | |
Defined in Clash.Class.BitPack | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5, a6, a7, a8, a9, a10), KnownNat (BitSize (a2, a3, a4, a5, a6, a7, a8, a9, a10))) => BitPack (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) Source # | |
Defined in Clash.Class.BitPack | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5, a6, a7, a8, a9, a10, a11), KnownNat (BitSize (a2, a3, a4, a5, a6, a7, a8, a9, a10, a11))) => BitPack (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) Source # | |
Defined in Clash.Class.BitPack | |
(BitPack a1, KnownNat (BitSize a1), BitPack (a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12), KnownNat (BitSize (a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12))) => BitPack (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) Source # | |
Defined in Clash.Class.BitPack |
bitCoerce :: (BitPack a, BitPack b, BitSize a ~ BitSize b) => a -> b Source #
Coerce a value from one type to another through its bit representation.
>>>
pack (-5 :: Signed 6)
11_1011>>>
bitCoerce (-5 :: Signed 6) :: Unsigned 6
59>>>
pack (59 :: Unsigned 6)
11_1011
bitCoerceMap :: forall a b. (BitPack a, BitPack b, BitSize a ~ BitSize b) => (a -> a) -> b -> b Source #
Map a value by first coercing to another type through its bit representation.
>>>
pack (-5 :: Signed 32)
1111_1111_1111_1111_1111_1111_1111_1011>>>
bitCoerceMap @(Vec 4 (BitVector 8)) (replace 1 0) (-5 :: Signed 32)
-16711685>>>
pack (-16711685 :: Signed 32)
1111_1111_0000_0000_1111_1111_1111_1011