-
Notifications
You must be signed in to change notification settings - Fork 162
Description
Clash primitives currently require KnownDomain
constraints in order to change their behavior depending on their synthesis domain. It's implemented using class constraints as this - apart from all the dormant bugs it exposed - didn't require adding additional logic to the Clash compiler. An example of a primitive requiring a KnownDomain
constraint is register#
:
clash-compiler/clash-prelude/src/Clash/Signal/Internal.hs
Lines 1078 to 1082 in 9d278c2
register# (Clock dom) rst (fromEnable -> ena) powerUpVal0 resetVal = | |
case knownDomainByName dom of | |
SDomainConfiguration _name _period _edge SSynchronous _init _polarity -> | |
goSync powerUpVal1 (unsafeToHighPolarity rst) ena | |
SDomainConfiguration _name _period _edge SAsynchronous _init _polarity -> |
To remove the need for this constraint we would need to do two things:
- On the simulation side of things, we'd need to remove all the
KnownDomain
constraints on Clash primitives. We subsequently need to add them toclockGen
,resetGen
, andenableGen
. These primitives would useknownDomain
to store aSDomainConfiguration
inside the constructs they're building. For example,Clock
might look like:
data Clock (dom :: Domain) =
Clock
(SSymbol dom)
(SDomainConfiguration dom (KnownConf dom))
(If this doesn't work out, we could go for VDomainConfiguration
too.) Simulation constructs can now simply extract the synthesis domains from their given clocks. Of course, deconstructing clocks, resets, and enables is still not synthesizable! Thus...
- To get synthesis working we need domain-extracting primitives for clocks, resets, and enables. For example, for a
Clock
this would look like:
clockDomain :: Clock dom -> SDomainConfiguration dom (KnownConf dom)
(We might want to wrap this in a typeclass so we can use the same function on clocks, resets, and enables all the same.) Clash would need to collect all instances of KnownDomain
before synthesis and insert the result of knownDomain
for every clockDomain
it sees.