From 87e87a45e22ddc55cdf0beb1b154abd8c590abe5 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 24 Nov 2019 13:13:40 +0000 Subject: Add cross-check between netlists --- src/Verismith.hs | 4 ++-- src/Verismith/Fuzz.hs | 20 +++++++++++--------- src/Verismith/OptParser.hs | 3 +++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Verismith.hs b/src/Verismith.hs index 48f851e..077fd98 100644 --- a/src/Verismith.hs +++ b/src/Verismith.hs @@ -144,13 +144,13 @@ randomise config@(Config a _ c d e) = do ce = config ^. configProbability . probExpr handleOpts :: Opts -> IO () -handleOpts (Fuzz o configF f k n nosim noequiv noreduction file top) = do +handleOpts (Fuzz o configF f k n nosim noequiv noreduction file top cc) = do config <- getConfig configF gen <- getGenerator config top file datadir <- getDataDir _ <- runFuzz (FuzzOpts (Just $ fromText o) - f k n nosim noequiv noreduction config (toFP datadir)) + f k n nosim noequiv noreduction config (toFP datadir) cc) defaultYosys (fuzzMultiple gen) return () diff --git a/src/Verismith/Fuzz.hs b/src/Verismith/Fuzz.hs index c73f8e4..226f368 100644 --- a/src/Verismith/Fuzz.hs +++ b/src/Verismith/Fuzz.hs @@ -74,6 +74,7 @@ data FuzzOpts = FuzzOpts { _fuzzOptsOutput :: !(Maybe FilePath) , _fuzzOptsNoReduction :: !Bool , _fuzzOptsConfig :: {-# UNPACK #-} !Config , _fuzzDataDir :: {-# UNPACK #-} !FilePath + , _fuzzOptsCrossCheck :: !Bool } deriving (Show, Eq) @@ -89,6 +90,7 @@ defaultFuzzOpts = FuzzOpts { _fuzzOptsOutput = Nothing , _fuzzOptsNoReduction = False , _fuzzOptsConfig = defaultConfig , _fuzzDataDir = fromText "." + , _fuzzOptsCrossCheck = False } data FuzzEnv = FuzzEnv { _getSynthesisers :: ![SynthTool] @@ -188,8 +190,8 @@ synthesisers = lift $ asks _getSynthesisers --simulators :: (Monad m) => Fuzz () m [SimTool] --simulators = lift $ asks getSimulators ---combinations :: [a] -> [b] -> [(a, b)] ---combinations l1 l2 = [ (x, y) | x <- l1, y <- l2 ] +combinations :: [a] -> [b] -> [(a, b)] +combinations l1 l2 = [ (x, y) | x <- l1, y <- l2 ] logT :: MonadSh m => Text -> m () logT = liftSh . logger @@ -252,7 +254,9 @@ toSimResult :: SimTool -> [(NominalDiffTime, Result Failed ByteString)] -> [SimResult] toSimResult sima bs as b = - applyList (applyList (repeat uncurry) (applyList (applyList (SimResult <$> as) (repeat sima)) (repeat bs))) $ fmap swap b + applyList (applyList (repeat uncurry) + (applyList (applyList (SimResult <$> as) (repeat sima)) (repeat bs))) + $ fmap swap b toolRun :: (MonadIO m, MonadSh m) => Text -> m a -> m (NominalDiffTime, a) toolRun t m = do @@ -263,15 +267,13 @@ toolRun t m = do equivalence :: (MonadBaseControl IO m, MonadSh m) => SourceInfo -> Fuzz m () equivalence src = do + doCrossCheck <- fmap _fuzzOptsCrossCheck askOpts datadir <- fmap _fuzzDataDir askOpts synth <- passedSynthesis --- let synthComb = --- nubBy tupEq . filter (uncurry (/=)) $ combinations synth synth let synthComb = - nubBy tupEq - . filter (uncurry (/=)) - $ (,) defaultIdentitySynth - <$> synth + if doCrossCheck + then nubBy tupEq . filter (uncurry (/=)) $ combinations synth synth + else nubBy tupEq . filter (uncurry (/=)) $ (,) defaultIdentitySynth <$> synth resTimes <- liftSh $ mapM (uncurry (equiv datadir)) synthComb fuzzSynthResults .= toSynthResult synthComb resTimes liftSh $ inspect resTimes diff --git a/src/Verismith/OptParser.hs b/src/Verismith/OptParser.hs index 2ccfe31..37d00fd 100644 --- a/src/Verismith/OptParser.hs +++ b/src/Verismith/OptParser.hs @@ -34,6 +34,7 @@ data Opts = Fuzz { fuzzOutput :: {-# UNPACK #-} !Text , fuzzNoReduction :: !Bool , fuzzExistingFile :: !(Maybe FilePath) , fuzzExistingFileTop :: !Text + , fuzzCrossCheck :: !Bool } | Generate { generateFilename :: !(Maybe FilePath) , generateConfigFile :: !(Maybe FilePath) @@ -128,6 +129,8 @@ fuzzOpts = <> Opt.help "Define the top module for the source file." <> Opt.showDefault <> Opt.value "top") + <*> (Opt.switch $ Opt.long "crosscheck" <> Opt.help + "Do not only compare against the original design, but also against other netlists.") genOpts :: Parser Opts genOpts = -- cgit