Copyright | (c) Matthew Naylor 2019 (c) Alexandre Joannou 2019-2021 |
---|---|
License | MIT |
Maintainer | mattfn@gmail.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Blarney.Core.Bit
Description
This module provides size-typed bit vectors and circuit primitives, on top of Blarney's untyped bit vectors and circuit primitives. Hardware developers should always use the typed versions!
Synopsis
- newtype Bit (n :: Nat) = FromBV {}
- widthOf :: KnownNat n => Bit n -> Int
- unsafeWidthOf :: Bit n -> Int
- valueOf :: forall n. KnownNat n => Int
- constant :: KnownNat n => Integer -> Bit n
- lit :: KnownNat n => Integer -> Bit n
- nameBit :: String -> Bit n -> Bit n
- testPlusArgs :: String -> Bit 1
- true :: Bit 1
- false :: Bit 1
- (.+.) :: Bit n -> Bit n -> Bit n
- add :: forall {n :: Nat}. Bit n -> Bit n -> Bit n
- (.-.) :: Bit n -> Bit n -> Bit n
- sub :: forall {n :: Nat}. Bit n -> Bit n -> Bit n
- (.*.) :: Bit n -> Bit n -> Bit n
- mul :: forall {n :: Nat}. Bit n -> Bit n -> Bit n
- fullMul :: Bool -> Bit n -> Bit n -> Bit (2 * n)
- (./.) :: Bit n -> Bit n -> Bit n
- quotient :: forall {n :: Nat}. Bit n -> Bit n -> Bit n
- (.%.) :: Bit n -> Bit n -> Bit n
- remainder :: forall {n :: Nat}. Bit n -> Bit n -> Bit n
- inv :: Bit n -> Bit n
- (.&.) :: Bit n -> Bit n -> Bit n
- (.|.) :: Bit n -> Bit n -> Bit n
- (.^.) :: Bit n -> Bit n -> Bit n
- (.&&.) :: Bit 1 -> Bit 1 -> Bit 1
- (.||.) :: Bit 1 -> Bit 1 -> Bit 1
- (.==>.) :: Bit 1 -> Bit 1 -> Bit 1
- (.<==>.) :: Bit 1 -> Bit 1 -> Bit 1
- (.<<.) :: Bit n -> Bit m -> Bit n
- (.>>.) :: Bit n -> Bit m -> Bit n
- (.>>>.) :: Bit n -> Bit m -> Bit n
- rotl :: Bit n -> Bit m -> Bit n
- rotr :: Bit n -> Bit m -> Bit n
- class Cmp a where
- less :: Bit n -> Bit n -> Bit 1
- lessEq :: Bit n -> Bit n -> Bit 1
- equal :: Bit n -> Bit n -> Bit 1
- notEqual :: Bit n -> Bit n -> Bit 1
- signedLess :: Bit n -> Bit n -> Bit 1
- signedGreater :: Bit n -> Bit n -> Bit 1
- signedLessEq :: Bit n -> Bit n -> Bit 1
- signedGreaterEq :: Bit n -> Bit n -> Bit 1
- rep :: KnownNat n => Bit 1 -> Bit n
- zeroExtend :: (KnownNat m, n <= m) => Bit n -> Bit m
- signExtend :: (KnownNat m, n <= m) => Bit n -> Bit m
- (#) :: Bit n -> Bit m -> Bit (n + m)
- upper :: (KnownNat m, m <= n) => Bit n -> Bit m
- truncateLSB :: forall m n. (KnownNat m, m <= n) => Bit n -> Bit m
- lower :: (KnownNat m, m <= n) => Bit n -> Bit m
- truncate :: forall m n. (KnownNat m, m <= n) => Bit n -> Bit m
- split :: KnownNat n => Bit (n + m) -> (Bit n, Bit m)
- dropBits :: forall d n. KnownNat d => Bit (d + n) -> Bit n
- dropBitsLSB :: forall d n. KnownNat n => Bit (n + d) -> Bit n
- invMSB :: Bit n -> Bit n
- slice :: forall (hi :: Nat) (lo :: Nat) i o. (KnownNat hi, KnownNat lo, (lo + o) ~ (hi + 1), (hi + 1) <= i, o <= i) => Bit i -> Bit o
- untypedSlice :: KnownNat m => (Int, Int) -> Bit n -> Bit m
- unsafeSlice :: (Int, Int) -> Bit n -> Bit m
- at :: forall (i :: Nat) n. (KnownNat i, (i + 1) <= n) => Bit n -> Bit 1
- untypedAt :: Int -> Bit n -> Bit 1
- unsafeAt :: Int -> Bit n -> Bit 1
- inputPin :: forall n. KnownNat n => String -> Bit n
- reg :: Bit n -> Bit n -> Bit n
- regEn :: Bit n -> Bit 1 -> Bit n -> Bit n
- mergeWritesBit :: MergeStrategy -> Width -> [(Bit 1, Bit n)] -> Bit n
- mux :: Bit 1 -> Bit n -> Bit n -> Bit n
- nmux :: Bit w -> [Bit n] -> Bit n
- liftNat :: Int -> (forall n. KnownNat n => Proxy n -> a) -> a
- fromBitList :: KnownNat n => [Bit 1] -> Bit n
- toBitList :: KnownNat n => Bit n -> [Bit 1]
- newtype OneHotList = OneHotList [Bit 1]
- unsafeFromBitList :: [Bit 1] -> Bit n
- unsafeToBitList :: Bit n -> [Bit 1]
- onBitList :: ([Bit 1] -> [Bit 1]) -> Bit n -> Bit n
- unsafeBitCast :: Bit n -> Bit m
- truncateCast :: (KnownNat n, KnownNat m) => Bit n -> Bit m
- truncateLSBCast :: (KnownNat n, KnownNat m) => Bit n -> Bit m
- zeroExtendCast :: (KnownNat n, KnownNat m) => Bit n -> Bit m
- cast :: (KnownNat n, KnownNat m) => Bit n -> Bit m
- class GCmp f where
- newtype Signed (n :: Nat) = Signed (Bit n)
- toSigned :: Bit n -> Signed n
- fromSigned :: Signed n -> Bit n
Typed bit-vectors
newtype Bit (n :: Nat) Source #
Phantom type wrapping an untyped bit vector,
capturing the bit-vector width. All bit vectors
are members of the Num
and Cmp
classes.
Instances
Val PulseWire (Bit 1) # |
|
KnownNat n => Num (Bit n) # | |
Cmp (Bit n) # | |
KnownNat n => Bits (Bit n) # | |
FShow (Bit n) # | |
KnownNat n => Interface (Bit n) # | |
Bits a => IfThenElse (Bit 1) a # | Overloaded if-then-else |
Defined in Blarney.Core.Common Methods ifThenElse :: Bit 1 -> a -> a -> a Source # | |
When (Bit 1) Action # | Overloaded conditional for actions |
When (Bit 1) Stmt # | |
Lookup (Bit n) OneHotList (Bit 1) # | Index a bit vector using a one-hot bit list |
Defined in Blarney.Core.Lookup | |
Lookup (Bit n) Integer (Bit 1) # | Index a bit vector using an Integer |
Lookup (Bit n) Int (Bit 1) # | Index a bit vector using an Int |
Bits a => IfThenElse (Bit 1) (Action a) # | Overloaded if-then-else |
Defined in Blarney.Core.Module | |
IfThenElse (Bit 1) (Stmt ()) # | |
Defined in Blarney.Stmt | |
(Interface a, KnownNat n) => Lookup [a] (Bit n) a # | Index a list using a bit vector |
Defined in Blarney.Core.Lookup | |
KnownNat m => Lookup (Bit n) (Bit m) (Bit 1) # | Index a bit vector using a bit vector |
(Interface a, KnownNat n) => Lookup (Vec m a) (Bit n) a # | Index a vector using a bit vector |
type SizeOf (Bit n) # | |
Defined in Blarney.Core.Bits |
testPlusArgs :: String -> Bit 1 Source #
Test plusargs
Bit-vector arithmetic
Bitwise operations on bit-vectors
Bit-vector comparison primitives
Minimal complete definition
Nothing
Methods
(.<.) :: a -> a -> Bit 1 infix 4 Source #
(.<=.) :: a -> a -> Bit 1 infix 4 Source #
(.==.) :: a -> a -> Bit 1 infix 4 Source #
(.>.) :: a -> a -> Bit 1 infix 4 Source #
Instances
Cmp () # | |
Cmp (Bit n) # | |
Cmp (Signed n) # | |
Defined in Blarney.Core.Bit | |
Cmp t => Cmp (Option t) # | |
Defined in Blarney.Option | |
(Cmp a, Cmp b) => Cmp (a, b) # | |
(Cmp a, Cmp b, Cmp c) => Cmp (a, b, c) # | |
(Cmp a, Cmp b, Cmp c, Cmp d) => Cmp (a, b, c, d) # | |
Defined in Blarney.Core.Bit | |
(Cmp a, Cmp b, Cmp c, Cmp d, Cmp e) => Cmp (a, b, c, d, e) # | |
Defined in Blarney.Core.Bit Methods (.<.) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bit 1 Source # (.<=.) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bit 1 Source # (.==.) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bit 1 Source # (.>.) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bit 1 Source # (.>=.) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bit 1 Source # (.!=.) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bit 1 Source # | |
(Cmp a, Cmp b, Cmp c, Cmp d, Cmp e, Cmp f) => Cmp (a, b, c, d, e, f) # | |
Defined in Blarney.Core.Bit Methods (.<.) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bit 1 Source # (.<=.) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bit 1 Source # (.==.) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bit 1 Source # (.>.) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bit 1 Source # (.>=.) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bit 1 Source # (.!=.) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bit 1 Source # | |
(Cmp a, Cmp b, Cmp c, Cmp d, Cmp e, Cmp f, Cmp g) => Cmp (a, b, c, d, e, f, g) # | |
Defined in Blarney.Core.Bit Methods (.<.) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bit 1 Source # (.<=.) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bit 1 Source # (.==.) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bit 1 Source # (.>.) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bit 1 Source # (.>=.) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bit 1 Source # (.!=.) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bit 1 Source # |
Bit-vector width adjustment
truncateLSB :: forall m n. (KnownNat m, m <= n) => Bit n -> Bit m Source #
Extract most significant bits
truncate :: forall m n. (KnownNat m, m <= n) => Bit n -> Bit m Source #
Extract least significant bits
Bit-vector selection primitives
slice :: forall (hi :: Nat) (lo :: Nat) i o. (KnownNat hi, KnownNat lo, (lo + o) ~ (hi + 1), (hi + 1) <= i, o <= i) => Bit i -> Bit o Source #
Statically-typed bit selection. Use type application to specify upper and lower indices.
at :: forall (i :: Nat) n. (KnownNat i, (i + 1) <= n) => Bit n -> Bit 1 Source #
Statically-typed bit indexing. Use type application to specify index.
Bit-vector inputs
Bit-vector registers
mergeWritesBit :: MergeStrategy -> Width -> [(Bit 1, Bit n)] -> Bit n Source #
Merge inputs together according to a merging strategy
Misc. bit-vector operations
nmux :: Bit w -> [Bit n] -> Bit n Source #
Multiplexer using a selector signal to index a list of input signals. Raises a circuit generation time error on empty list of inputs
liftNat :: Int -> (forall n. KnownNat n => Proxy n -> a) -> a Source #
Lift integer value to type-level natural
newtype OneHotList Source #
One-hot bit list
Constructors
OneHotList [Bit 1] |
Instances
Interface a => Lookup [a] OneHotList a # | Index a list using a one-hot bit list |
Defined in Blarney.Core.Lookup Methods (!) :: [a] -> OneHotList -> a Source # | |
Lookup (Bit n) OneHotList (Bit 1) # | Index a bit vector using a one-hot bit list |
Defined in Blarney.Core.Lookup |
unsafeFromBitList :: [Bit 1] -> Bit n Source #
Collapse a '[Bit 1]' of size n to a single 'Bit n'
unsafeToBitList :: Bit n -> [Bit 1] Source #
Expand a single 'Bit n' to a '[Bit 1]' of size n
onBitList :: ([Bit 1] -> [Bit 1]) -> Bit n -> Bit n Source #
Apply bit-list transformation on bit-vector
unsafeBitCast :: Bit n -> Bit m Source #
Cast one size of vector to another (dangerous)
truncateCast :: (KnownNat n, KnownNat m) => Bit n -> Bit m Source #
Similar to truncate
but width check done at elaboration time
truncateLSBCast :: (KnownNat n, KnownNat m) => Bit n -> Bit m Source #
Similar to truncateLSB
but width check done at elaboration time
zeroExtendCast :: (KnownNat n, KnownNat m) => Bit n -> Bit m Source #
Similar to zeroExtend
but width check done at elaboration time
cast :: (KnownNat n, KnownNat m) => Bit n -> Bit m Source #
Zero extend or truncate input to give output
For generic deriving of Cmp class
Signed typed bit-vectors
newtype Signed (n :: Nat) Source #
Signed bit vectors
fromSigned :: Signed n -> Bit n Source #
Convert from signed bit-vector