Copyright | (c) Matthew Naylor 2019 (c) Alexandre Joannou 2019-2021 |
---|---|
License | MIT |
Maintainer | mattfn@gmail.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
This module provides a set of circuit primitives.
Synopsis
- data Prim
- = Const OutputWidth Integer
- | DontCare OutputWidth
- | Add OutputWidth
- | Sub OutputWidth
- | Mul { }
- | Div OutputWidth
- | Mod OutputWidth
- | Not OutputWidth
- | And OutputWidth
- | Or OutputWidth
- | Xor OutputWidth
- | ShiftLeft InputWidth OutputWidth
- | ShiftRight InputWidth OutputWidth
- | ArithShiftRight InputWidth OutputWidth
- | Equal InputWidth
- | NotEqual InputWidth
- | LessThan InputWidth
- | LessThanEq InputWidth
- | ReplicateBit OutputWidth
- | ZeroExtend InputWidth OutputWidth
- | SignExtend InputWidth OutputWidth
- | SelectBits InputWidth BitIndex BitIndex
- | Concat InputWidth InputWidth
- | Mux Int InputWidth OutputWidth
- | Identity OutputWidth
- | Register InitVal InputWidth
- | RegisterEn InitVal InputWidth
- | MergeWrites MergeStrategy Int Width
- | Input OutputWidth String
- | Output InputWidth String
- | BRAM { }
- | Custom {
- customName :: String
- customInputs :: [(String, InputWidth)]
- customOutputs :: [(String, OutputWidth)]
- customParams :: [Param]
- customIsClocked :: Bool
- customResetable :: Bool
- customNetlist :: Maybe CustomNetlist
- | RegFileMake RegFileInfo
- | RegFileRead RegFileInfo
- | RegFileWrite RegFileInfo
- | Display [DisplayArg]
- | Finish
- | TestPlusArgs String
- | Assert String
- canInline :: Prim -> Bool
- canInlineInput :: Prim -> Bool
- clamp :: (Num a, Bits a) => Width -> a -> a
- primStr :: Prim -> String
- primSemEvalRaw :: PrimSample a => Prim -> Maybe ([a] -> [a])
- primSemEval :: PrimSample a => Prim -> [a] -> [a]
- primDontKill :: Prim -> Bool
- primIsRoot :: Prim -> Bool
- primInputs :: Prim -> [(String, InputWidth)]
- primOutputs :: Prim -> [(String, OutputWidth)]
- primOutIndex :: Prim -> OutputName -> Maybe Int
- primOutWidth :: Prim -> OutputName -> OutputWidth
- data BRAMKind
- type InstId = Int
- type Width = Int
- type InputWidth = Width
- type OutputWidth = Width
- type OutputName = Maybe String
- type InitVal = Ternary
- type BitIndex = Int
- data MergeStrategy = MStratOr
- data RegFileInfo = RegFileInfo {}
- data DisplayArg
- data DisplayArgRadix
- data Param = String :-> String
- data NameHint
- type NameHints = Set NameHint
- data Net = Net {}
- type WireId = (InstId, OutputName)
- data NetInput
- type Netlist = Array InstId Net
- newtype CustomNetlist = CustomNetlist Netlist
Prim
primitive type and helpers
The Prim
type is used to represent the fundamental operations in blarney.
Each Prim
constructor can expect some statically known arguments such as
desired widths for inputs or outputs, initial values for registers, etc...
Each Prim
will expect to be used with a list of inputs, and to provide a
list of outputs. The shape of these lists is documented here for
convenience, but these are not enforced in the Prim
type.
The primInputs
and primOutputs
functions can be used to query the shape
of the inputs and outpus lists that can be used for a given Prim
.
Const OutputWidth Integer |
|
DontCare OutputWidth |
|
Add OutputWidth |
|
Sub OutputWidth |
|
Mul | Mul { primMulInputWidth = w , primMulSigned = isSigned , primMulFullPrecision = isFullPrecision } represents a multiplier
|
| |
Div OutputWidth |
|
Mod OutputWidth |
|
Not OutputWidth |
|
And OutputWidth |
|
Or OutputWidth |
|
Xor OutputWidth |
|
ShiftLeft InputWidth OutputWidth |
|
ShiftRight InputWidth OutputWidth |
|
ArithShiftRight InputWidth OutputWidth |
|
Equal InputWidth |
|
NotEqual InputWidth |
|
LessThan InputWidth |
|
LessThanEq InputWidth |
|
ReplicateBit OutputWidth |
|
ZeroExtend InputWidth OutputWidth |
|
SignExtend InputWidth OutputWidth |
|
SelectBits InputWidth BitIndex BitIndex |
|
Concat InputWidth InputWidth |
|
Mux Int InputWidth OutputWidth |
|
Identity OutputWidth |
|
Register InitVal InputWidth |
|
RegisterEn InitVal InputWidth |
|
MergeWrites MergeStrategy Int Width |
|
Input OutputWidth String |
|
Output InputWidth String |
|
BRAM | Block RAM |
| |
Custom | Custom component |
| |
RegFileMake RegFileInfo | Register file declaration (only used in RTL context, not expression context) |
RegFileRead RegFileInfo | Register file lookup (input: index, output: data) |
RegFileWrite RegFileInfo | Register file update (inputs: write-enable, address, data) |
Display [DisplayArg] | Not for synthesis
|
Finish | Not for synthesis
|
TestPlusArgs String | Not for synthesis
|
Assert String | Not for synthesis
|
canInline :: Prim -> Bool Source #
Helper to tell whether a Prim
can be inlined during Netlist optimisation
canInlineInput :: Prim -> Bool Source #
Helper to tell whether a Prim
inputs can be inlined during Netlist
optimisation
primSemEvalRaw :: PrimSample a => Prim -> Maybe ([a] -> [a]) Source #
Helper to retrieve a primitive's semantic evaluation function or lack thereof
primSemEval :: PrimSample a => Prim -> [a] -> [a] Source #
Helper to retrieve a primitive's semantic evaluation function
primInputs :: Prim -> [(String, InputWidth)] Source #
Helper to get the inputs of a Prim
primOutputs :: Prim -> [(String, OutputWidth)] Source #
Helper to get the outputs of a Prim
primOutIndex :: Prim -> OutputName -> Maybe Int Source #
Helper to get the index of a given named output of a Prim
primOutWidth :: Prim -> OutputName -> OutputWidth Source #
Helper to get the OutputWidth
for a given named output of a Prim
Kind of block RAM
Other primitive types
Unique identifier used to identify every instance of a component in a circuit
type InputWidth = Width Source #
Width of an input to a primitive
type OutputWidth = Width Source #
Width of an output from a primitive
data MergeStrategy Source #
Merging Strategy
Instances
Show MergeStrategy # | |
Defined in Blarney.Core.Prim showsPrec :: Int -> MergeStrategy -> ShowS # show :: MergeStrategy -> String # showList :: [MergeStrategy] -> ShowS # | |
Eq MergeStrategy # | |
Defined in Blarney.Core.Prim (==) :: MergeStrategy -> MergeStrategy -> Bool # (/=) :: MergeStrategy -> MergeStrategy -> Bool # |
data RegFileInfo Source #
Register file primitive parameters
RegFileInfo | |
|
Instances
Show RegFileInfo # | |
Defined in Blarney.Core.Prim showsPrec :: Int -> RegFileInfo -> ShowS # show :: RegFileInfo -> String # showList :: [RegFileInfo] -> ShowS # |
data DisplayArg Source #
For the Display primitive: display a string literal or a bit-vector value of a given width
DisplayArgString String | Display a string |
DisplayArgBit | Display a bit vector with formatting options |
| |
DisplayCondBlockBegin | Subsequences of arguments of a display can be conditionally displayed |
DisplayCondBlockEnd |
Instances
Show DisplayArg # | |
Defined in Blarney.Core.Prim showsPrec :: Int -> DisplayArg -> ShowS # show :: DisplayArg -> String # showList :: [DisplayArg] -> ShowS # |
data DisplayArgRadix Source #
Format for displaying bit vectors
Instances
Show DisplayArgRadix # | |
Defined in Blarney.Core.Prim showsPrec :: Int -> DisplayArgRadix -> ShowS # show :: DisplayArgRadix -> String # showList :: [DisplayArgRadix] -> ShowS # |
Custom components may have compile-time parameters. A parameter has a name and a value, both represented as strings
Hint to generate useful names when working with Net
s
NmPrefix Int String | Suggested name prefix |
NmRoot Int String | Suggested name |
NmSuffix Int String | Suggested name suffix |
Netlists
type WireId = (InstId, OutputName) Source #
A WireId
uniquely identify a wire with a Net'
s instance identifier
(InstId
) and an output name (OutputName
)
newtype CustomNetlist Source #
Netlist for a Custom Prim. We use a new type here so that we can keep
automatic deriving of the Show
class for Prim
.
Instances
Show CustomNetlist # | |
Defined in Blarney.Core.Prim showsPrec :: Int -> CustomNetlist -> ShowS # show :: CustomNetlist -> String # showList :: [CustomNetlist] -> ShowS # |