blarney
Copyright(c) Matthew Naylor 2019
(c) Alexandre Joannou 2019-2021
LicenseMIT
Maintainermattfn@gmail.com
Stabilityexperimental
Safe HaskellSafe-Inferred

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

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.

Constructors

FromBV 

Fields

Instances

Instances details
Val PulseWire (Bit 1) #

Val instance for PulseWire, returning whether the wire was pulsed

Instance details

Defined in Blarney.PulseWire

Methods

val :: PulseWire -> Bit 1 Source #

KnownNat n => Num (Bit n) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(+) :: Bit n -> Bit n -> Bit n #

(-) :: Bit n -> Bit n -> Bit n #

(*) :: Bit n -> Bit n -> Bit n #

negate :: Bit n -> Bit n #

abs :: Bit n -> Bit n #

signum :: Bit n -> Bit n #

fromInteger :: Integer -> Bit n #

Cmp (Bit n) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: Bit n -> Bit n -> Bit 1 Source #

(.<=.) :: Bit n -> Bit n -> Bit 1 Source #

(.==.) :: Bit n -> Bit n -> Bit 1 Source #

(.>.) :: Bit n -> Bit n -> Bit 1 Source #

(.>=.) :: Bit n -> Bit n -> Bit 1 Source #

(.!=.) :: Bit n -> Bit n -> Bit 1 Source #

KnownNat n => Bits (Bit n) # 
Instance details

Defined in Blarney.Core.Bits

Associated Types

type SizeOf (Bit n) :: Nat Source #

Methods

sizeOf :: Bit n -> Int Source #

pack :: Bit n -> Bit (SizeOf (Bit n)) Source #

unpack :: Bit (SizeOf (Bit n)) -> Bit n Source #

nameBits :: String -> Bit n -> Bit n Source #

FShow (Bit n) # 
Instance details

Defined in Blarney.Core.FShow

Methods

fshow :: Bit n -> Format Source #

fshowList :: [Bit n] -> Format Source #

KnownNat n => Interface (Bit n) # 
Instance details

Defined in Blarney.Core.Interface

Bits a => IfThenElse (Bit 1) a #

Overloaded if-then-else

Instance details

Defined in Blarney.Core.Prelude

Methods

ifThenElse :: Bit 1 -> a -> a -> a Source #

When (Bit 1) Action #

Overloaded conditional for actions

Instance details

Defined in Blarney.Core.Module

Methods

when :: Bit 1 -> Action () -> Action () Source #

When (Bit 1) Stmt # 
Instance details

Defined in Blarney.Stmt

Methods

when :: Bit 1 -> Stmt () -> Stmt () Source #

Lookup (Bit n) OneHotList (Bit 1) #

Index a bit vector using a one-hot bit list

Instance details

Defined in Blarney.Core.Lookup

Methods

(!) :: Bit n -> OneHotList -> Bit 1 Source #

Lookup (Bit n) Integer (Bit 1) #

Index a bit vector using an Integer

Instance details

Defined in Blarney.Core.Lookup

Methods

(!) :: Bit n -> Integer -> Bit 1 Source #

Lookup (Bit n) Int (Bit 1) #

Index a bit vector using an Int

Instance details

Defined in Blarney.Core.Lookup

Methods

(!) :: Bit n -> Int -> Bit 1 Source #

Bits a => IfThenElse (Bit 1) (Action a) #

Overloaded if-then-else

Instance details

Defined in Blarney.Core.Module

Methods

ifThenElse :: Bit 1 -> Action a -> Action a -> Action a Source #

IfThenElse (Bit 1) (Stmt ()) # 
Instance details

Defined in Blarney.Stmt

Methods

ifThenElse :: Bit 1 -> Stmt () -> Stmt () -> Stmt () Source #

(Interface a, KnownNat n) => Lookup [a] (Bit n) a #

Index a list using a bit vector

Instance details

Defined in Blarney.Core.Lookup

Methods

(!) :: [a] -> Bit n -> a Source #

KnownNat m => Lookup (Bit n) (Bit m) (Bit 1) #

Index a bit vector using a bit vector

Instance details

Defined in Blarney.Core.Lookup

Methods

(!) :: Bit n -> Bit m -> Bit 1 Source #

(Interface a, KnownNat n) => Lookup (Vec m a) (Bit n) a #

Index a vector using a bit vector

Instance details

Defined in Blarney.Vector

Methods

(!) :: Vec m a -> Bit n -> a Source #

type SizeOf (Bit n) # 
Instance details

Defined in Blarney.Core.Bits

type SizeOf (Bit n) = n

widthOf :: KnownNat n => Bit n -> Int Source #

Determine width of bit-vector from type

unsafeWidthOf :: Bit n -> Int Source #

Determine width of bit-vector from underlying BV

valueOf :: forall n. KnownNat n => Int Source #

Convert type Nat to Ingeter value

constant :: KnownNat n => Integer -> Bit n Source #

Constant bit-vector

lit :: KnownNat n => Integer -> Bit n Source #

nameBit :: String -> Bit n -> Bit n Source #

Give a name to a 'Bit n' signal

testPlusArgs :: String -> Bit 1 Source #

Test plusargs

true :: Bit 1 Source #

True

false :: Bit 1 Source #

False

Bit-vector arithmetic

(.+.) :: Bit n -> Bit n -> Bit n infixl 6 Source #

Adder

add :: forall {n :: Nat}. Bit n -> Bit n -> Bit n Source #

Adder

(.-.) :: Bit n -> Bit n -> Bit n infixl 6 Source #

Subtractor

sub :: forall {n :: Nat}. Bit n -> Bit n -> Bit n Source #

Subtractor

(.*.) :: Bit n -> Bit n -> Bit n infixl 7 Source #

Multiplier

mul :: forall {n :: Nat}. Bit n -> Bit n -> Bit n Source #

Multiplier

fullMul :: Bool -> Bit n -> Bit n -> Bit (2 * n) Source #

Multiplier (full precision)

(./.) :: Bit n -> Bit n -> Bit n infixl 7 Source #

Quotient

quotient :: forall {n :: Nat}. Bit n -> Bit n -> Bit n Source #

Quotient

(.%.) :: Bit n -> Bit n -> Bit n infixl 7 Source #

Remainder

remainder :: forall {n :: Nat}. Bit n -> Bit n -> Bit n Source #

Remainder

Bitwise operations on bit-vectors

inv :: Bit n -> Bit n Source #

Bitwise invert

(.&.) :: Bit n -> Bit n -> Bit n infixl 7 Source #

Bitwise and

(.|.) :: Bit n -> Bit n -> Bit n infixl 5 Source #

Bitwise or

(.^.) :: Bit n -> Bit n -> Bit n infixl 6 Source #

Bitwise xor

(.&&.) :: Bit 1 -> Bit 1 -> Bit 1 infixr 3 Source #

Logical and

(.||.) :: Bit 1 -> Bit 1 -> Bit 1 infixr 2 Source #

Logical or

(.==>.) :: Bit 1 -> Bit 1 -> Bit 1 infixr 1 Source #

Logical implication

(.<==>.) :: Bit 1 -> Bit 1 -> Bit 1 infixr 1 Source #

Logical equivalence

(.<<.) :: Bit n -> Bit m -> Bit n infixl 8 Source #

Shift left

(.>>.) :: Bit n -> Bit m -> Bit n infixl 8 Source #

Shift right

(.>>>.) :: Bit n -> Bit m -> Bit n infixl 8 Source #

Arithmetic shift right

rotl :: Bit n -> Bit m -> Bit n Source #

Rotate left

rotr :: Bit n -> Bit m -> Bit n Source #

Rotate right

Bit-vector comparison primitives

class Cmp a where Source #

Minimal complete definition

Nothing

Methods

(.<.) :: a -> a -> Bit 1 infix 4 Source #

default (.<.) :: (Generic a, GCmp (Rep a)) => a -> a -> Bit 1 Source #

(.<=.) :: a -> a -> Bit 1 infix 4 Source #

default (.<=.) :: (Generic a, GCmp (Rep a)) => a -> a -> Bit 1 Source #

(.==.) :: a -> a -> Bit 1 infix 4 Source #

default (.==.) :: (Generic a, GCmp (Rep a)) => a -> a -> Bit 1 Source #

(.>.) :: a -> a -> Bit 1 infix 4 Source #

(.>=.) :: a -> a -> Bit 1 infix 4 Source #

(.!=.) :: a -> a -> Bit 1 infix 4 Source #

Instances

Instances details
Cmp () # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: () -> () -> Bit 1 Source #

(.<=.) :: () -> () -> Bit 1 Source #

(.==.) :: () -> () -> Bit 1 Source #

(.>.) :: () -> () -> Bit 1 Source #

(.>=.) :: () -> () -> Bit 1 Source #

(.!=.) :: () -> () -> Bit 1 Source #

Cmp (Bit n) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: Bit n -> Bit n -> Bit 1 Source #

(.<=.) :: Bit n -> Bit n -> Bit 1 Source #

(.==.) :: Bit n -> Bit n -> Bit 1 Source #

(.>.) :: Bit n -> Bit n -> Bit 1 Source #

(.>=.) :: Bit n -> Bit n -> Bit 1 Source #

(.!=.) :: Bit n -> Bit n -> Bit 1 Source #

Cmp (Signed n) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: Signed n -> Signed n -> Bit 1 Source #

(.<=.) :: Signed n -> Signed n -> Bit 1 Source #

(.==.) :: Signed n -> Signed n -> Bit 1 Source #

(.>.) :: Signed n -> Signed n -> Bit 1 Source #

(.>=.) :: Signed n -> Signed n -> Bit 1 Source #

(.!=.) :: Signed n -> Signed n -> Bit 1 Source #

Cmp t => Cmp (Option t) # 
Instance details

Defined in Blarney.Option

Methods

(.<.) :: Option t -> Option t -> Bit 1 Source #

(.<=.) :: Option t -> Option t -> Bit 1 Source #

(.==.) :: Option t -> Option t -> Bit 1 Source #

(.>.) :: Option t -> Option t -> Bit 1 Source #

(.>=.) :: Option t -> Option t -> Bit 1 Source #

(.!=.) :: Option t -> Option t -> Bit 1 Source #

(Cmp a, Cmp b) => Cmp (a, b) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: (a, b) -> (a, b) -> Bit 1 Source #

(.<=.) :: (a, b) -> (a, b) -> Bit 1 Source #

(.==.) :: (a, b) -> (a, b) -> Bit 1 Source #

(.>.) :: (a, b) -> (a, b) -> Bit 1 Source #

(.>=.) :: (a, b) -> (a, b) -> Bit 1 Source #

(.!=.) :: (a, b) -> (a, b) -> Bit 1 Source #

(Cmp a, Cmp b, Cmp c) => Cmp (a, b, c) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: (a, b, c) -> (a, b, c) -> Bit 1 Source #

(.<=.) :: (a, b, c) -> (a, b, c) -> Bit 1 Source #

(.==.) :: (a, b, c) -> (a, b, c) -> Bit 1 Source #

(.>.) :: (a, b, c) -> (a, b, c) -> Bit 1 Source #

(.>=.) :: (a, b, c) -> (a, b, c) -> Bit 1 Source #

(.!=.) :: (a, b, c) -> (a, b, c) -> Bit 1 Source #

(Cmp a, Cmp b, Cmp c, Cmp d) => Cmp (a, b, c, d) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: (a, b, c, d) -> (a, b, c, d) -> Bit 1 Source #

(.<=.) :: (a, b, c, d) -> (a, b, c, d) -> Bit 1 Source #

(.==.) :: (a, b, c, d) -> (a, b, c, d) -> Bit 1 Source #

(.>.) :: (a, b, c, d) -> (a, b, c, d) -> Bit 1 Source #

(.>=.) :: (a, b, c, d) -> (a, b, c, d) -> Bit 1 Source #

(.!=.) :: (a, b, c, d) -> (a, b, c, d) -> Bit 1 Source #

(Cmp a, Cmp b, Cmp c, Cmp d, Cmp e) => Cmp (a, b, c, d, e) # 
Instance details

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) # 
Instance details

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) # 
Instance details

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 #

less :: Bit n -> Bit n -> Bit 1 Source #

Unsigned less-than

lessEq :: Bit n -> Bit n -> Bit 1 Source #

Unsigned less-than-or-equal-to

equal :: Bit n -> Bit n -> Bit 1 Source #

Equality

notEqual :: Bit n -> Bit n -> Bit 1 Source #

Disequality

signedLess :: Bit n -> Bit n -> Bit 1 infixl 8 Source #

Signed less than

signedGreater :: Bit n -> Bit n -> Bit 1 infixl 8 Source #

Signed greater than

signedLessEq :: Bit n -> Bit n -> Bit 1 infixl 8 Source #

Signed less than or equal

signedGreaterEq :: Bit n -> Bit n -> Bit 1 infixl 8 Source #

Signed greater than or equal

Bit-vector width adjustment

rep :: KnownNat n => Bit 1 -> Bit n Source #

Replicate bit

zeroExtend :: (KnownNat m, n <= m) => Bit n -> Bit m Source #

Zero extension

signExtend :: (KnownNat m, n <= m) => Bit n -> Bit m Source #

Sign extension

(#) :: Bit n -> Bit m -> Bit (n + m) infixr 8 Source #

Bit-vector concatenation

upper :: (KnownNat m, m <= n) => Bit n -> Bit m Source #

Extract most significant bits

truncateLSB :: forall m n. (KnownNat m, m <= n) => Bit n -> Bit m Source #

Extract most significant bits

lower :: (KnownNat m, m <= n) => Bit n -> Bit m Source #

Extract least significant bits

truncate :: forall m n. (KnownNat m, m <= n) => Bit n -> Bit m Source #

Extract least significant bits

split :: KnownNat n => Bit (n + m) -> (Bit n, Bit m) Source #

Split bit vector

dropBits :: forall d n. KnownNat d => Bit (d + n) -> Bit n Source #

Drop most significant bits

dropBitsLSB :: forall d n. KnownNat n => Bit (n + d) -> Bit n Source #

Drop least significant bits

invMSB :: Bit n -> Bit n Source #

Invert most significant bit

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.

untypedSlice :: KnownNat m => (Int, Int) -> Bit n -> Bit m Source #

Dynamically-typed bit selection

unsafeSlice :: (Int, Int) -> Bit n -> Bit m Source #

Untyped bit selection (try to avoid!)

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.

untypedAt :: Int -> Bit n -> Bit 1 Source #

Dynamically-typed bit indexing

unsafeAt :: Int -> Bit n -> Bit 1 Source #

Dynamically-typed bit indexing

Bit-vector inputs

inputPin :: forall n. KnownNat n => String -> Bit n Source #

Input bit-vector

Bit-vector registers

reg :: Bit n -> Bit n -> Bit n Source #

Register

regEn :: Bit n -> Bit 1 -> Bit n -> Bit n Source #

Register with enable wire

mergeWritesBit :: MergeStrategy -> Width -> [(Bit 1, Bit n)] -> Bit n Source #

Merge inputs together according to a merging strategy

Misc. bit-vector operations

mux :: Bit 1 -> Bit n -> Bit n -> Bit n Source #

Two-input multiplexer

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

fromBitList :: KnownNat n => [Bit 1] -> Bit n Source #

Convert list of bits to bit vector

toBitList :: KnownNat n => Bit n -> [Bit 1] Source #

Convert bit vector to list of bits

newtype OneHotList Source #

One-hot bit list

Constructors

OneHotList [Bit 1] 

Instances

Instances details
Interface a => Lookup [a] OneHotList a #

Index a list using a one-hot bit list

Instance details

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

Instance details

Defined in Blarney.Core.Lookup

Methods

(!) :: Bit n -> OneHotList -> Bit 1 Source #

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

class GCmp f where Source #

For generic deriving of Cmp class

Methods

gCmpLT :: f a -> f a -> Bit 1 Source #

gCmpLTE :: f a -> f a -> Bit 1 Source #

gCmpEQ :: f a -> f a -> Bit 1 Source #

Instances

Instances details
GCmp (U1 :: k -> Type) # 
Instance details

Defined in Blarney.Core.Bit

Methods

gCmpLT :: forall (a :: k0). U1 a -> U1 a -> Bit 1 Source #

gCmpLTE :: forall (a :: k0). U1 a -> U1 a -> Bit 1 Source #

gCmpEQ :: forall (a :: k0). U1 a -> U1 a -> Bit 1 Source #

(GCmp a, GCmp b) => GCmp (a :*: b :: k -> Type) # 
Instance details

Defined in Blarney.Core.Bit

Methods

gCmpLT :: forall (a0 :: k0). (a :*: b) a0 -> (a :*: b) a0 -> Bit 1 Source #

gCmpLTE :: forall (a0 :: k0). (a :*: b) a0 -> (a :*: b) a0 -> Bit 1 Source #

gCmpEQ :: forall (a0 :: k0). (a :*: b) a0 -> (a :*: b) a0 -> Bit 1 Source #

Cmp a => GCmp (K1 i a :: k -> Type) # 
Instance details

Defined in Blarney.Core.Bit

Methods

gCmpLT :: forall (a0 :: k0). K1 i a a0 -> K1 i a a0 -> Bit 1 Source #

gCmpLTE :: forall (a0 :: k0). K1 i a a0 -> K1 i a a0 -> Bit 1 Source #

gCmpEQ :: forall (a0 :: k0). K1 i a a0 -> K1 i a a0 -> Bit 1 Source #

GCmp a => GCmp (M1 i c a :: k -> Type) # 
Instance details

Defined in Blarney.Core.Bit

Methods

gCmpLT :: forall (a0 :: k0). M1 i c a a0 -> M1 i c a a0 -> Bit 1 Source #

gCmpLTE :: forall (a0 :: k0). M1 i c a a0 -> M1 i c a a0 -> Bit 1 Source #

gCmpEQ :: forall (a0 :: k0). M1 i c a a0 -> M1 i c a a0 -> Bit 1 Source #

Signed typed bit-vectors

newtype Signed (n :: Nat) Source #

Signed bit vectors

Constructors

Signed (Bit n) 

Instances

Instances details
Cmp (Signed n) # 
Instance details

Defined in Blarney.Core.Bit

Methods

(.<.) :: Signed n -> Signed n -> Bit 1 Source #

(.<=.) :: Signed n -> Signed n -> Bit 1 Source #

(.==.) :: Signed n -> Signed n -> Bit 1 Source #

(.>.) :: Signed n -> Signed n -> Bit 1 Source #

(.>=.) :: Signed n -> Signed n -> Bit 1 Source #

(.!=.) :: Signed n -> Signed n -> Bit 1 Source #

KnownNat n => Bits (Signed n) # 
Instance details

Defined in Blarney.Core.Bits

Associated Types

type SizeOf (Signed n) :: Nat Source #

KnownNat n => Interface (Signed n) # 
Instance details

Defined in Blarney.Core.Interface

type SizeOf (Signed n) # 
Instance details

Defined in Blarney.Core.Bits

type SizeOf (Signed n) = n

toSigned :: Bit n -> Signed n Source #

Convert to signed bit-vector

fromSigned :: Signed n -> Bit n Source #

Convert from signed bit-vector