clash-prelude-0.6.0.1: CAES Language for Synchronous Hardware - Prelude library

Safe HaskellNone
LanguageHaskell2010

CLaSH.Class.BitPack

Synopsis

Documentation

class BitPack a where Source

Convert to and from a BitVector

Associated Types

type BitSize a :: Nat Source

Number of Bits needed to represents elements of type a

Methods

pack :: a -> BitVector (BitSize a) Source

Convert element of type a to a BitVector

>>> pack (-5 :: Signed 6)
111011

unpack :: BitVector (BitSize a) -> a Source

Convert a BitVector to an element of type a

>>> pack (-5 :: Signed 6)
111011
>>> let x = pack (-5 :: Signed 6)
>>> unpack x :: Unsigned 6
59
>>> pack (59 :: Unsigned 6)
111011

Instances

BitPack Bool 
BitPack (BitVector n) 
KnownNat n => BitPack (Signed n) 
BitPack (Unsigned n) 
(KnownNat (BitSize a), KnownNat (BitSize b), BitPack a, BitPack b) => BitPack (a, b) 
(KnownNat n, KnownNat (BitSize a), BitPack a) => BitPack (Vec n a) 
BitPack (rep ((+) int frac)) => BitPack (Fixed rep int frac) 

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)
111011
>>> bitCoerce (-5 :: Signed 6) :: Unsigned 6
59
>>> pack (59 :: Unsigned 6)
111011