{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Unsafe #-}
{-# OPTIONS_HADDOCK show-extensions #-}
{-# OPTIONS_GHC -fplugin=GHC.TypeLits.Normalise #-}
{-# OPTIONS_GHC -fplugin=GHC.TypeLits.KnownNat.Solver #-}
module Clash.Explicit.Testbench
(
assert
, assertBitVector
, ignoreFor
, stimuliGenerator
, tbClockGen
, tbEnableGen
, tbSystemClockGen
, outputVerifier
, outputVerifier'
, outputVerifierBitVector
, outputVerifierBitVector'
, biTbClockGen
)
where
import Control.Exception (catch, evaluate)
import Debug.Trace (trace)
import GHC.TypeLits (KnownNat, type (+))
import Prelude hiding ((!!), length)
import System.IO.Unsafe (unsafeDupablePerformIO)
import Clash.Annotations.Primitive (hasBlackBox)
import Clash.Class.Num (satSucc, SaturationMode(SatBound))
import Clash.Promoted.Nat (SNat(..), snatToNum)
import Clash.Promoted.Symbol (SSymbol (..))
import Clash.Explicit.Signal
(Clock, Reset, System, Signal, clockPeriod, toEnable, fromList, register,
unbundle, unsafeSynchronizer, veryUnsafeSynchronizer)
import Clash.Signal.Internal (Clock (..), Reset (..))
import Clash.Signal (mux, KnownDomain, Enable)
import Clash.Sized.Index (Index)
import Clash.Sized.Internal.BitVector
(BitVector, isLike)
import Clash.Sized.Vector (Vec, (!!), length)
import Clash.XException (ShowX (..), XException)
assert
:: (KnownDomain dom, Eq a, ShowX a)
=> Clock dom
-> Reset dom
-> String
-> Signal dom a
-> Signal dom a
-> Signal dom b
-> Signal dom b
assert :: Clock dom
-> Reset dom
-> String
-> Signal dom a
-> Signal dom a
-> Signal dom b
-> Signal dom b
assert Clock dom
clk (Reset Signal dom Bool
_) String
msg Signal dom a
checked Signal dom a
expected Signal dom b
returned =
(\a
c a
e Integer
cnt b
r ->
if a -> a -> Bool
forall a. Eq a => a -> a -> Bool
eqX a
c a
e
then b
r
else String -> b -> b
forall a. String -> a -> a
trace ([String] -> String
forall (t :: Type -> Type) a. Foldable t => t [a] -> [a]
concat [ String
"\ncycle(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Clock dom -> String
forall a. Show a => a -> String
show Clock dom
clk String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"): "
, Integer -> String
forall a. Show a => a -> String
show Integer
cnt
, String
", "
, String
msg
, String
"\nexpected value: "
, a -> String
forall a. ShowX a => a -> String
showX a
e
, String
", not equal to actual value: "
, a -> String
forall a. ShowX a => a -> String
showX a
c
]) b
r)
(a -> a -> Integer -> b -> b)
-> Signal dom a -> Signal dom (a -> Integer -> b -> b)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom a
checked Signal dom (a -> Integer -> b -> b)
-> Signal dom a -> Signal dom (Integer -> b -> b)
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Signal dom a
expected Signal dom (Integer -> b -> b)
-> Signal dom Integer -> Signal dom (b -> b)
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> [Integer] -> Signal dom Integer
forall a (dom :: Domain). NFDataX a => [a] -> Signal dom a
fromList [(Integer
0::Integer)..] Signal dom (b -> b) -> Signal dom b -> Signal dom b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Signal dom b
returned
where
eqX :: a -> a -> Bool
eqX a
a a
b = IO Bool -> Bool
forall a. IO a -> a
unsafeDupablePerformIO (IO Bool -> (XException -> IO Bool) -> IO Bool
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch (Bool -> IO Bool
forall a. a -> IO a
evaluate (a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b))
(\(XException
_ :: XException) -> Bool -> IO Bool
forall (m :: Type -> Type) a. Monad m => a -> m a
return Bool
False))
{-# NOINLINE assert #-}
{-# ANN assert hasBlackBox #-}
assertBitVector
:: (KnownDomain dom, KnownNat n)
=> Clock dom
-> Reset dom
-> String
-> Signal dom (BitVector n)
-> Signal dom (BitVector n)
-> Signal dom b
-> Signal dom b
assertBitVector :: Clock dom
-> Reset dom
-> String
-> Signal dom (BitVector n)
-> Signal dom (BitVector n)
-> Signal dom b
-> Signal dom b
assertBitVector Clock dom
clk (Reset Signal dom Bool
_) String
msg Signal dom (BitVector n)
checked Signal dom (BitVector n)
expected Signal dom b
returned =
(\BitVector n
c BitVector n
e Integer
cnt b
r ->
if BitVector n -> BitVector n -> Bool
forall (n :: Nat). KnownNat n => BitVector n -> BitVector n -> Bool
eqX BitVector n
c BitVector n
e
then b
r
else String -> b -> b
forall a. String -> a -> a
trace ([String] -> String
forall (t :: Type -> Type) a. Foldable t => t [a] -> [a]
concat [ String
"\ncycle(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Clock dom -> String
forall a. Show a => a -> String
show Clock dom
clk String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"): "
, Integer -> String
forall a. Show a => a -> String
show Integer
cnt
, String
", "
, String
msg
, String
"\nexpected value: "
, BitVector n -> String
forall a. ShowX a => a -> String
showX BitVector n
e
, String
", not equal to actual value: "
, BitVector n -> String
forall a. ShowX a => a -> String
showX BitVector n
c
]) b
r)
(BitVector n -> BitVector n -> Integer -> b -> b)
-> Signal dom (BitVector n)
-> Signal dom (BitVector n -> Integer -> b -> b)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom (BitVector n)
checked Signal dom (BitVector n -> Integer -> b -> b)
-> Signal dom (BitVector n) -> Signal dom (Integer -> b -> b)
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Signal dom (BitVector n)
expected Signal dom (Integer -> b -> b)
-> Signal dom Integer -> Signal dom (b -> b)
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> [Integer] -> Signal dom Integer
forall a (dom :: Domain). NFDataX a => [a] -> Signal dom a
fromList [(Integer
0::Integer)..] Signal dom (b -> b) -> Signal dom b -> Signal dom b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Signal dom b
returned
where
eqX :: BitVector n -> BitVector n -> Bool
eqX BitVector n
a BitVector n
b = IO Bool -> Bool
forall a. IO a -> a
unsafeDupablePerformIO (IO Bool -> (XException -> IO Bool) -> IO Bool
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch (Bool -> IO Bool
forall a. a -> IO a
evaluate (BitVector n
a BitVector n -> BitVector n -> Bool
forall (n :: Nat). KnownNat n => BitVector n -> BitVector n -> Bool
`isLike` BitVector n
b))
(\(XException
_ :: XException) -> Bool -> IO Bool
forall (m :: Type -> Type) a. Monad m => a -> m a
return Bool
False))
{-# NOINLINE assertBitVector #-}
{-# ANN assertBitVector hasBlackBox #-}
stimuliGenerator
:: forall l dom a
. ( KnownNat l
, KnownDomain dom )
=> Clock dom
-> Reset dom
-> Vec l a
-> Signal dom a
stimuliGenerator :: Clock dom -> Reset dom -> Vec l a -> Signal dom a
stimuliGenerator Clock dom
clk Reset dom
rst Vec l a
samples =
let (Signal dom (Index l)
r,Signal dom a
o) = Signal dom (Index l, a) -> Unbundled dom (Index l, a)
forall a (dom :: Domain).
Bundle a =>
Signal dom a -> Unbundled dom a
unbundle (Index l -> (Index l, a)
genT (Index l -> (Index l, a))
-> Signal dom (Index l) -> Signal dom (Index l, a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Clock dom
-> Reset dom
-> Enable dom
-> Index l
-> Signal dom (Index l)
-> Signal dom (Index l)
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock dom
clk Reset dom
rst (Signal dom Bool -> Enable dom
forall (dom :: Domain). Signal dom Bool -> Enable dom
toEnable (Bool -> Signal dom Bool
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Bool
True)) Index l
0 Signal dom (Index l)
r)
in Signal dom a
o
where
genT :: Index l -> (Index l,a)
genT :: Index l -> (Index l, a)
genT Index l
s = (Index l
s',Vec l a
samples Vec l a -> Index l -> a
forall (n :: Nat) i a. (KnownNat n, Enum i) => Vec n a -> i -> a
!! Index l
s)
where
maxI :: Index l
maxI = Int -> Index l
forall a. Enum a => Int -> a
toEnum (Vec l a -> Int
forall (n :: Nat) a. KnownNat n => Vec n a -> Int
length Vec l a
samples Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
s' :: Index l
s' = if Index l
s Index l -> Index l -> Bool
forall a. Ord a => a -> a -> Bool
< Index l
maxI
then Index l
s Index l -> Index l -> Index l
forall a. Num a => a -> a -> a
+ Index l
1
else Index l
s
{-# INLINABLE stimuliGenerator #-}
outputVerifier'
:: forall l a dom
. ( KnownNat l
, KnownDomain dom
, Eq a
, ShowX a )
=> Clock dom
-> Reset dom
-> Vec l a
-> Signal dom a
-> Signal dom Bool
outputVerifier' :: Clock dom
-> Reset dom -> Vec l a -> Signal dom a -> Signal dom Bool
outputVerifier' =
(KnownNat l, KnownDomain dom, KnownDomain dom, Eq a, ShowX a) =>
Clock dom
-> Reset dom -> Vec l a -> Signal dom a -> Signal dom Bool
forall (l :: Nat) a (testDom :: Domain) (circuitDom :: Domain).
(KnownNat l, KnownDomain testDom, KnownDomain circuitDom, Eq a,
ShowX a) =>
Clock testDom
-> Reset testDom
-> Vec l a
-> Signal circuitDom a
-> Signal testDom Bool
outputVerifier @l @a @dom @dom
{-# INLINABLE outputVerifier' #-}
outputVerifier
:: forall l a testDom circuitDom
. ( KnownNat l
, KnownDomain testDom
, KnownDomain circuitDom
, Eq a
, ShowX a )
=> Clock testDom
-> Reset testDom
-> Vec l a
-> Signal circuitDom a
-> Signal testDom Bool
outputVerifier :: Clock testDom
-> Reset testDom
-> Vec l a
-> Signal circuitDom a
-> Signal testDom Bool
outputVerifier Clock testDom
clk Reset testDom
rst Vec l a
samples Signal circuitDom a
i0 =
let t1 :: Int
t1 = SNat (DomainConfigurationPeriod (KnownConf circuitDom)) -> Int
forall a (n :: Nat). Num a => SNat n -> a
snatToNum (forall (period :: Nat).
(KnownDomain circuitDom,
DomainConfigurationPeriod (KnownConf circuitDom) ~ period) =>
SNat period
forall (dom :: Domain) (period :: Nat).
(KnownDomain dom, DomainPeriod dom ~ period) =>
SNat period
clockPeriod @circuitDom)
t2 :: Int
t2 = SNat (DomainConfigurationPeriod (KnownConf testDom)) -> Int
forall a (n :: Nat). Num a => SNat n -> a
snatToNum (forall (period :: Nat).
(KnownDomain testDom,
DomainConfigurationPeriod (KnownConf testDom) ~ period) =>
SNat period
forall (dom :: Domain) (period :: Nat).
(KnownDomain dom, DomainPeriod dom ~ period) =>
SNat period
clockPeriod @testDom)
i1 :: Signal testDom a
i1 = Int -> Int -> Signal circuitDom a -> Signal testDom a
forall (dom1 :: Domain) a (dom2 :: Domain).
Int -> Int -> Signal dom1 a -> Signal dom2 a
veryUnsafeSynchronizer Int
t1 Int
t2 Signal circuitDom a
i0
en :: Enable dom
en = Signal dom Bool -> Enable dom
forall (dom :: Domain). Signal dom Bool -> Enable dom
toEnable (Bool -> Signal dom Bool
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Bool
True)
(Signal testDom (Index l)
s,Signal testDom (a, Bool)
o) = Signal testDom (Index l, (a, Bool))
-> Unbundled testDom (Index l, (a, Bool))
forall a (dom :: Domain).
Bundle a =>
Signal dom a -> Unbundled dom a
unbundle (Index l -> (Index l, (a, Bool))
genT (Index l -> (Index l, (a, Bool)))
-> Signal testDom (Index l) -> Signal testDom (Index l, (a, Bool))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Clock testDom
-> Reset testDom
-> Enable testDom
-> Index l
-> Signal testDom (Index l)
-> Signal testDom (Index l)
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock testDom
clk Reset testDom
rst Enable testDom
forall (dom :: Domain). Enable dom
en Index l
0 Signal testDom (Index l)
s)
(Signal testDom a
e,Signal testDom Bool
f) = Signal testDom (a, Bool) -> Unbundled testDom (a, Bool)
forall a (dom :: Domain).
Bundle a =>
Signal dom a -> Unbundled dom a
unbundle Signal testDom (a, Bool)
o
f' :: Signal testDom Bool
f' = Clock testDom
-> Reset testDom
-> Enable testDom
-> Bool
-> Signal testDom Bool
-> Signal testDom Bool
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock testDom
clk Reset testDom
rst Enable testDom
forall (dom :: Domain). Enable dom
en Bool
False Signal testDom Bool
f
in Signal testDom Bool
-> Signal testDom Bool
-> Signal testDom Bool
-> Signal testDom Bool
forall (f :: Type -> Type) a.
Applicative f =>
f Bool -> f a -> f a -> f a
mux Signal testDom Bool
f' Signal testDom Bool
f' (Signal testDom Bool -> Signal testDom Bool)
-> Signal testDom Bool -> Signal testDom Bool
forall a b. (a -> b) -> a -> b
$ Clock testDom
-> Reset testDom
-> String
-> Signal testDom a
-> Signal testDom a
-> Signal testDom Bool
-> Signal testDom Bool
forall (dom :: Domain) a b.
(KnownDomain dom, Eq a, ShowX a) =>
Clock dom
-> Reset dom
-> String
-> Signal dom a
-> Signal dom a
-> Signal dom b
-> Signal dom b
assert Clock testDom
clk Reset testDom
rst String
"outputVerifier" Signal testDom a
i1 Signal testDom a
e Signal testDom Bool
f'
where
genT :: Index l -> (Index l,(a,Bool))
genT :: Index l -> (Index l, (a, Bool))
genT Index l
s = (Index l
s',(Vec l a
samples Vec l a -> Index l -> a
forall (n :: Nat) i a. (KnownNat n, Enum i) => Vec n a -> i -> a
!! Index l
s,Bool
finished))
where
maxI :: Index l
maxI = Int -> Index l
forall a. Enum a => Int -> a
toEnum (Vec l a -> Int
forall (n :: Nat) a. KnownNat n => Vec n a -> Int
length Vec l a
samples Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
s' :: Index l
s' = if Index l
s Index l -> Index l -> Bool
forall a. Ord a => a -> a -> Bool
< Index l
maxI
then Index l
s Index l -> Index l -> Index l
forall a. Num a => a -> a -> a
+ Index l
1
else Index l
s
finished :: Bool
finished = Index l
s Index l -> Index l -> Bool
forall a. Eq a => a -> a -> Bool
== Index l
maxI
{-# INLINABLE outputVerifier #-}
outputVerifierBitVector'
:: forall l n dom
. ( KnownNat l
, KnownNat n
, KnownDomain dom
)
=> Clock dom
-> Reset dom
-> Vec l (BitVector n)
-> Signal dom (BitVector n)
-> Signal dom Bool
outputVerifierBitVector' :: Clock dom
-> Reset dom
-> Vec l (BitVector n)
-> Signal dom (BitVector n)
-> Signal dom Bool
outputVerifierBitVector' =
(KnownNat l, KnownNat n, KnownDomain dom, KnownDomain dom) =>
Clock dom
-> Reset dom
-> Vec l (BitVector n)
-> Signal dom (BitVector n)
-> Signal dom Bool
forall (l :: Nat) (n :: Nat) (testDom :: Domain)
(circuitDom :: Domain).
(KnownNat l, KnownNat n, KnownDomain testDom,
KnownDomain circuitDom) =>
Clock testDom
-> Reset testDom
-> Vec l (BitVector n)
-> Signal circuitDom (BitVector n)
-> Signal testDom Bool
outputVerifierBitVector @l @n @dom @dom
{-# INLINABLE outputVerifierBitVector' #-}
outputVerifierBitVector
:: forall l n testDom circuitDom
. ( KnownNat l
, KnownNat n
, KnownDomain testDom
, KnownDomain circuitDom
)
=> Clock testDom
-> Reset testDom
-> Vec l (BitVector n)
-> Signal circuitDom (BitVector n)
-> Signal testDom Bool
outputVerifierBitVector :: Clock testDom
-> Reset testDom
-> Vec l (BitVector n)
-> Signal circuitDom (BitVector n)
-> Signal testDom Bool
outputVerifierBitVector Clock testDom
clk Reset testDom
rst Vec l (BitVector n)
samples Signal circuitDom (BitVector n)
i0 =
let t1 :: Int
t1 = SNat (DomainConfigurationPeriod (KnownConf circuitDom)) -> Int
forall a (n :: Nat). Num a => SNat n -> a
snatToNum (forall (period :: Nat).
(KnownDomain circuitDom,
DomainConfigurationPeriod (KnownConf circuitDom) ~ period) =>
SNat period
forall (dom :: Domain) (period :: Nat).
(KnownDomain dom, DomainPeriod dom ~ period) =>
SNat period
clockPeriod @circuitDom)
t2 :: Int
t2 = SNat (DomainConfigurationPeriod (KnownConf testDom)) -> Int
forall a (n :: Nat). Num a => SNat n -> a
snatToNum (forall (period :: Nat).
(KnownDomain testDom,
DomainConfigurationPeriod (KnownConf testDom) ~ period) =>
SNat period
forall (dom :: Domain) (period :: Nat).
(KnownDomain dom, DomainPeriod dom ~ period) =>
SNat period
clockPeriod @testDom)
i1 :: Signal testDom (BitVector n)
i1 = Int
-> Int
-> Signal circuitDom (BitVector n)
-> Signal testDom (BitVector n)
forall (dom1 :: Domain) a (dom2 :: Domain).
Int -> Int -> Signal dom1 a -> Signal dom2 a
veryUnsafeSynchronizer Int
t1 Int
t2 Signal circuitDom (BitVector n)
i0
en :: Enable dom
en = Signal dom Bool -> Enable dom
forall (dom :: Domain). Signal dom Bool -> Enable dom
toEnable (Bool -> Signal dom Bool
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Bool
True)
(Signal testDom (Index l)
s,Signal testDom (BitVector n, Bool)
o) = Signal testDom (Index l, (BitVector n, Bool))
-> Unbundled testDom (Index l, (BitVector n, Bool))
forall a (dom :: Domain).
Bundle a =>
Signal dom a -> Unbundled dom a
unbundle (Index l -> (Index l, (BitVector n, Bool))
genT (Index l -> (Index l, (BitVector n, Bool)))
-> Signal testDom (Index l)
-> Signal testDom (Index l, (BitVector n, Bool))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Clock testDom
-> Reset testDom
-> Enable testDom
-> Index l
-> Signal testDom (Index l)
-> Signal testDom (Index l)
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock testDom
clk Reset testDom
rst Enable testDom
forall (dom :: Domain). Enable dom
en Index l
0 Signal testDom (Index l)
s)
(Signal testDom (BitVector n)
e,Signal testDom Bool
f) = Signal testDom (BitVector n, Bool)
-> Unbundled testDom (BitVector n, Bool)
forall a (dom :: Domain).
Bundle a =>
Signal dom a -> Unbundled dom a
unbundle Signal testDom (BitVector n, Bool)
o
f' :: Signal testDom Bool
f' = Clock testDom
-> Reset testDom
-> Enable testDom
-> Bool
-> Signal testDom Bool
-> Signal testDom Bool
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock testDom
clk Reset testDom
rst Enable testDom
forall (dom :: Domain). Enable dom
en Bool
False Signal testDom Bool
f
in Signal testDom Bool
-> Signal testDom Bool
-> Signal testDom Bool
-> Signal testDom Bool
forall (f :: Type -> Type) a.
Applicative f =>
f Bool -> f a -> f a -> f a
mux Signal testDom Bool
f' Signal testDom Bool
f' (Signal testDom Bool -> Signal testDom Bool)
-> Signal testDom Bool -> Signal testDom Bool
forall a b. (a -> b) -> a -> b
$ Clock testDom
-> Reset testDom
-> String
-> Signal testDom (BitVector n)
-> Signal testDom (BitVector n)
-> Signal testDom Bool
-> Signal testDom Bool
forall (dom :: Domain) (n :: Nat) b.
(KnownDomain dom, KnownNat n) =>
Clock dom
-> Reset dom
-> String
-> Signal dom (BitVector n)
-> Signal dom (BitVector n)
-> Signal dom b
-> Signal dom b
assertBitVector Clock testDom
clk Reset testDom
rst String
"outputVerifierBitVector'" Signal testDom (BitVector n)
i1 Signal testDom (BitVector n)
e Signal testDom Bool
f'
where
genT :: Index l -> (Index l,(BitVector n,Bool))
genT :: Index l -> (Index l, (BitVector n, Bool))
genT Index l
s = (Index l
s',(Vec l (BitVector n)
samples Vec l (BitVector n) -> Index l -> BitVector n
forall (n :: Nat) i a. (KnownNat n, Enum i) => Vec n a -> i -> a
!! Index l
s,Bool
finished))
where
maxI :: Index l
maxI = Int -> Index l
forall a. Enum a => Int -> a
toEnum (Vec l (BitVector n) -> Int
forall (n :: Nat) a. KnownNat n => Vec n a -> Int
length Vec l (BitVector n)
samples Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
s' :: Index l
s' = if Index l
s Index l -> Index l -> Bool
forall a. Ord a => a -> a -> Bool
< Index l
maxI
then Index l
s Index l -> Index l -> Index l
forall a. Num a => a -> a -> a
+ Index l
1
else Index l
s
finished :: Bool
finished = Index l
s Index l -> Index l -> Bool
forall a. Eq a => a -> a -> Bool
== Index l
maxI
{-# INLINABLE outputVerifierBitVector #-}
ignoreFor
:: forall dom n a
. KnownDomain dom
=> Clock dom
-> Reset dom
-> Enable dom
-> SNat n
-> a
-> Signal dom a
-> Signal dom a
ignoreFor :: Clock dom
-> Reset dom
-> Enable dom
-> SNat n
-> a
-> Signal dom a
-> Signal dom a
ignoreFor Clock dom
clk Reset dom
rst Enable dom
en SNat n
SNat a
a Signal dom a
i =
Signal dom Bool -> Signal dom a -> Signal dom a -> Signal dom a
forall (f :: Type -> Type) a.
Applicative f =>
f Bool -> f a -> f a -> f a
mux (Index (n + 1) -> Index (n + 1) -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Index (n + 1) -> Index (n + 1) -> Bool)
-> Signal dom (Index (n + 1)) -> Signal dom (Index (n + 1) -> Bool)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom (Index (n + 1))
counter Signal dom (Index (n + 1) -> Bool)
-> Signal dom (Index (n + 1)) -> Signal dom Bool
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> (Index (n + 1) -> Signal dom (Index (n + 1))
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Index (n + 1)
forall a. Bounded a => a
maxBound)) Signal dom a
i (a -> Signal dom a
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure a
a)
where
counter :: Signal dom (Index (n+1))
counter :: Signal dom (Index (n + 1))
counter = Clock dom
-> Reset dom
-> Enable dom
-> Index (n + 1)
-> Signal dom (Index (n + 1))
-> Signal dom (Index (n + 1))
forall (dom :: Domain) a.
(KnownDomain dom, NFDataX a) =>
Clock dom
-> Reset dom -> Enable dom -> a -> Signal dom a -> Signal dom a
register Clock dom
clk Reset dom
rst Enable dom
en Index (n + 1)
0 (SaturationMode -> Index (n + 1) -> Index (n + 1)
forall a. SaturatingNum a => SaturationMode -> a -> a
satSucc SaturationMode
SatBound (Index (n + 1) -> Index (n + 1))
-> Signal dom (Index (n + 1)) -> Signal dom (Index (n + 1))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Signal dom (Index (n + 1))
counter)
biTbClockGen
:: forall testDom circuitDom
. ( KnownDomain testDom
, KnownDomain circuitDom
)
=> Signal testDom Bool
-> (Clock testDom, Clock circuitDom)
biTbClockGen :: Signal testDom Bool -> (Clock testDom, Clock circuitDom)
biTbClockGen Signal testDom Bool
done = (Clock testDom
testClk, Clock circuitDom
circuitClk)
where
testClk :: Clock testDom
testClk = Signal testDom Bool -> Clock testDom
forall (testDom :: Domain).
KnownDomain testDom =>
Signal testDom Bool -> Clock testDom
tbClockGen Signal testDom Bool
done
circuitClk :: Clock circuitDom
circuitClk = Signal circuitDom Bool -> Clock circuitDom
forall (testDom :: Domain).
KnownDomain testDom =>
Signal testDom Bool -> Clock testDom
tbClockGen (Clock testDom
-> Clock circuitDom
-> Signal testDom Bool
-> Signal circuitDom Bool
forall (dom1 :: Domain) (dom2 :: Domain) a.
(KnownDomain dom1, KnownDomain dom2) =>
Clock dom1 -> Clock dom2 -> Signal dom1 a -> Signal dom2 a
unsafeSynchronizer Clock testDom
testClk Clock circuitDom
circuitClk Signal testDom Bool
done)
tbClockGen
:: KnownDomain testDom
=> Signal testDom Bool
-> Clock testDom
tbClockGen :: Signal testDom Bool -> Clock testDom
tbClockGen Signal testDom Bool
done = SSymbol testDom -> Clock testDom
forall (dom :: Domain). SSymbol dom -> Clock dom
Clock (Signal testDom Bool
done Signal testDom Bool -> SSymbol testDom -> SSymbol testDom
`seq` SSymbol testDom
forall (s :: Domain). KnownSymbol s => SSymbol s
SSymbol)
{-# NOINLINE tbClockGen #-}
{-# ANN tbClockGen hasBlackBox #-}
tbEnableGen :: Enable tag
tbEnableGen :: Enable tag
tbEnableGen = Signal tag Bool -> Enable tag
forall (dom :: Domain). Signal dom Bool -> Enable dom
toEnable (Bool -> Signal tag Bool
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Bool
True)
{-# NOINLINE tbEnableGen #-}
{-# ANN tbEnableGen hasBlackBox #-}
tbSystemClockGen
:: Signal System Bool
-> Clock System
tbSystemClockGen :: Signal System Bool -> Clock System
tbSystemClockGen = Signal System Bool -> Clock System
forall (testDom :: Domain).
KnownDomain testDom =>
Signal testDom Bool -> Clock testDom
tbClockGen