aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2020-04-09 16:35:03 +0100
committerYann Herklotz <git@yannherklotz.com>2020-04-09 16:35:03 +0100
commit659e25c9d5b8a31ab3b8412b658c5e7b11f9408e (patch)
tree80063bda340f6dc72e4d0ad911a229b443c2819b
parentd86cb8fd763e687cf2cd7ad40094d15ebba6bf87 (diff)
downloadverismith-659e25c9d5b8a31ab3b8412b658c5e7b11f9408e.tar.gz
verismith-659e25c9d5b8a31ab3b8412b658c5e7b11f9408e.zip
Add option to drop reg and wire from output
-rw-r--r--src/Verismith.hs4
-rw-r--r--src/Verismith/Config.hs62
-rw-r--r--src/Verismith/Generate.hs26
3 files changed, 74 insertions, 18 deletions
diff --git a/src/Verismith.hs b/src/Verismith.hs
index 578b7ac..c9d3e78 100644
--- a/src/Verismith.hs
+++ b/src/Verismith.hs
@@ -107,6 +107,8 @@ randomise config@(Config a _ c d e) = do
ssc <- return $ cs ^. probStmntCond
ssf <- return $ cs ^. probStmntFor
en <- return $ ce ^. probExprNum
+ keep_out <- return $ cmo ^. probModDropOutput
+ drop_out <- randDelete $ cmo ^. probModDropOutput
ei <- randDelete $ ce ^. probExprId
ers <- randDelete $ ce ^. probExprRangeSelect
euo <- randDelete $ ce ^. probExprUnOp
@@ -121,6 +123,7 @@ randomise config@(Config a _ c d e) = do
(Probability (ProbModItem mia misa mica mii)
(ProbStatement ssb ssnb ssc ssf)
(ProbExpr en ei ers euo ebo ec eco estr esgn eus)
+ (ProbMod drop_out keep_out)
)
c
d
@@ -129,6 +132,7 @@ randomise config@(Config a _ c d e) = do
cm = config ^. configProbability . probModItem
cs = config ^. configProbability . probStmnt
ce = config ^. configProbability . probExpr
+ cmo = config ^. configProbability . probMod
handleOpts :: Opts -> IO ()
handleOpts (Fuzz o configF f k n nosim noequiv noreduction file top cc checker) = do
diff --git a/src/Verismith/Config.hs b/src/Verismith/Config.hs
index 2c239d7..f757ebb 100644
--- a/src/Verismith/Config.hs
+++ b/src/Verismith/Config.hs
@@ -25,6 +25,8 @@ module Verismith.Config
, ProbModItem(..)
-- *** Statement
, ProbStatement(..)
+ -- *** Module
+ , ProbMod (..)
-- ** ConfProperty
, ConfProperty(..)
-- ** Simulator Description
@@ -42,6 +44,9 @@ module Verismith.Config
, configSimulators
, configSynthesisers
, probModItem
+ , probMod
+ , probModDropOutput
+ , probModKeepOutput
, probStmnt
, probExpr
, probExprNum
@@ -199,6 +204,14 @@ data ProbStatement = ProbStatement { _probStmntBlock :: {-# UNPACK #-} !Int
}
deriving (Eq, Show)
+-- | Probability of generating various properties of a module.
+data ProbMod = ProbMod { _probModDropOutput :: {-# UNPACK #-} !Int
+ -- ^ "@module.drop_output@: frequency of a wire or register being dropped from the output."
+ , _probModKeepOutput :: {-# UNPACK #-} !Int
+ -- ^ "@module.keep_output@: frequency of a wire or register being kept in the output."
+ }
+ deriving (Eq, Show)
+
-- | @[probability]@: combined probabilities.
data Probability = Probability { _probModItem :: {-# UNPACK #-} !ProbModItem
-- ^ Probabilities for module items.
@@ -206,6 +219,7 @@ data Probability = Probability { _probModItem :: {-# UNPACK #-} !ProbModItem
-- ^ Probabilities for statements.
, _probExpr :: {-# UNPACK #-} !ProbExpr
-- ^ Probaiblities for expressions.
+ , _probMod :: {-# UNPACK #-} !ProbMod
}
deriving (Eq, Show)
@@ -282,6 +296,7 @@ data Config = Config { _configInfo :: Info
$(makeLenses ''ProbExpr)
$(makeLenses ''ProbModItem)
$(makeLenses ''ProbStatement)
+$(makeLenses ''ProbMod)
$(makeLenses ''Probability)
$(makeLenses ''ConfProperty)
$(makeLenses ''Info)
@@ -325,32 +340,35 @@ fromQuartusLight (QuartusLight a b c) = SynthDescription "quartuslight"
defaultConfig :: Config
defaultConfig = Config
(Info (pack $(gitHash)) (pack $ showVersion version))
- (Probability defModItem defStmnt defExpr)
+ (Probability defModItem defStmnt defExpr defMod)
(ConfProperty 20 Nothing 3 2 5 "random" 10 False 0 1 Nothing)
[]
[fromYosys defaultYosys, fromVivado defaultVivado]
where
+ defMod =
+ ProbMod 0 -- Drop Output
+ 1 -- Keep Output
defModItem =
ProbModItem 5 -- Assign
- 1 -- Sequential Always
- 1 -- Combinational Always
- 1 -- Instantiation
+ 1 -- Sequential Always
+ 1 -- Combinational Always
+ 1 -- Instantiation
defStmnt =
ProbStatement 0 -- Blocking assignment
- 3 -- Non-blocking assignment
- 1 -- Conditional
- 0 -- For loop
+ 3 -- Non-blocking assignment
+ 1 -- Conditional
+ 0 -- For loop
defExpr =
ProbExpr 1 -- Number
- 5 -- Identifier
- 5 -- Range selection
- 5 -- Unary operator
- 5 -- Binary operator
- 5 -- Ternary conditional
- 3 -- Concatenation
- 0 -- String
- 5 -- Signed function
- 5 -- Unsigned funtion
+ 5 -- Identifier
+ 5 -- Range selection
+ 5 -- Unary operator
+ 5 -- Binary operator
+ 5 -- Ternary conditional
+ 3 -- Concatenation
+ 0 -- String
+ 5 -- Signed function
+ 5 -- Unsigned funtion
twoKey :: Toml.Piece -> Toml.Piece -> Toml.Key
twoKey a b = Toml.Key (a :| [b])
@@ -415,6 +433,16 @@ modItemCodec =
defProb i = defaultConfig ^. configProbability . probModItem . i
intM = int "moditem"
+modCodec :: TomlCodec ProbMod
+modCodec =
+ ProbMod <$> defaultValue (defProb probModDropOutput) (intM "drop_output")
+ .= _probModDropOutput
+ <*> defaultValue (defProb probModKeepOutput) (intM "keep_output")
+ .= _probModKeepOutput
+ where
+ defProb i = defaultConfig ^. configProbability . probMod . i
+ intM = int "module"
+
probCodec :: TomlCodec Probability
probCodec =
Probability
@@ -424,6 +452,8 @@ probCodec =
.= _probStmnt
<*> defaultValue (defProb probExpr) exprCodec
.= _probExpr
+ <*> defaultValue (defProb probMod) modCodec
+ .= _probMod
where defProb i = defaultConfig ^. configProbability . i
propCodec :: TomlCodec ConfProperty
diff --git a/src/Verismith/Generate.hs b/src/Verismith/Generate.hs
index 4d51d21..52baf0d 100644
--- a/src/Verismith/Generate.hs
+++ b/src/Verismith/Generate.hs
@@ -562,6 +562,26 @@ calcRange ps i (Range l r) = eval l - eval r + 1
identElem :: Port -> [Port] -> Bool
identElem p = elem (p ^. portName) . toListOf (traverse . portName)
+-- | Select items from a list with a specific frequency, returning the new list
+-- that contains the selected items. If 0 is passed to both the select and
+-- not-select parameter, the function will act like the idententy, returning the
+-- original list inside the 'Gen' monad.
+--
+-- The reason for doing this at the output of a module reduces the number of
+-- wires that are exposed at the output and therefore allows the synthesis tool
+-- to perform more optimisations that it could otherwise not perform. The
+-- synthesis tool is quite strict with optimisations if all the wires and
+-- registers are exposed.
+selectwfreq :: (MonadGen m) => Int -> Int -> [a] -> m [a]
+selectwfreq _ _ [] = return []
+selectwfreq s n a@(l:ls)
+ | s > 0 && n > 0 =
+ Hog.frequency
+ [ (s, (l:) <$> selectwfreq s n ls)
+ , (n, selectwfreq s n ls)
+ ]
+ | otherwise = return a
+
-- | Generates a module definition randomly. It always has one output port which
-- is set to @y@. The size of @y@ is the total combination of all the locally
-- defined wires, so that it correctly reflects the internal state of the
@@ -582,11 +602,13 @@ moduleDef top = do
$ local
^.. traverse
. portSize
- let combine = config ^. configProperty . propCombine
+ let (ProbMod n s) = config ^. configProbability . probMod
+ newlocal <- selectwfreq s n local
let clock = Port Wire False 1 "clk"
+ let combine = config ^. configProperty . propCombine
let yport =
if combine then Port Wire False 1 "y" else Port Wire False size "y"
- let comb = combineAssigns_ combine yport local
+ let comb = combineAssigns_ combine yport newlocal
return
. declareMod local
. ModDecl name [yport] (clock : newPorts) (comb : mi)