Skip to content

Remove the need for KnownDomain constraints throughout Clash designs #978

@martijnbastiaan

Description

@martijnbastiaan

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#:

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:

  1. On the simulation side of things, we'd need to remove all the KnownDomain constraints on Clash primitives. We subsequently need to add them to clockGen, resetGen, and enableGen. These primitives would use knownDomain to store a SDomainConfiguration 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...

  1. 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.

Metadata

Metadata

Assignees

Labels

enhancementintermediateRequires (some) knowledge of the clash compiler to implement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions