Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling unidirectional Signals in circuits #59

Closed
bgamari opened this issue Jan 27, 2024 · 5 comments
Closed

Handling unidirectional Signals in circuits #59

bgamari opened this issue Jan 27, 2024 · 5 comments

Comments

@bgamari
Copy link
Collaborator

bgamari commented Jan 27, 2024

Currently clash-protocols provides the CSignal type for use in Circuits. This in principle allows us to write Circuits like (roughly modelling my axi-register package):

-- | An AXI4 subordinate implementing a memory-mapped register at the given Address.
-- (modelled after https://git.smart-cactus.org/ben/axi-register/-/blob/aca5748597c83d6e9d3d1c8e5f79b7390e3686e2/src/Protocols/Register.hs#L131) 
memoryMappedReg :: Address -> Circuit Axi4 (BitVector 32)
memoryMappedReg = ...

-- | Fan-out an AXI-MM bus; assumes that subordinates cover non-overlapping regions of address space.
-- (modelled after https://git.smart-cactus.org/ben/axi-register/-/blob/aca5748597c83d6e9d3d1c8e5f79b7390e3686e2/src/Protocols/Register.hs#L77)
fanoutAxi :: Circuit Axi4 (Axi4, Axi4)
fanoutAxi = ...

-- | A 'Circuit'  which produces the sum of two memory-mapped registers' values
sumRegs :: Circuit Axi4 (Signal dom (BitVector 32))
sumRegs = circuit $ \axi -> do
    (axi1, axi2) <- fanoutAxi -< axi
    Signal reg1 <- memoryMappedReg axi1
    Signal reg2 <- memoryMappedReg axi2
    idC -< Signal (reg1 + reg2)

Note that use of Signal patterns and expressions in sumRegs. As far as I can tell, this syntactic construct of circuit-notations allows the user to bind/use a unidirectional signal. However, I suspect that this currently doesn't work in clash-protocols as CSignal must be used in place of Signal in Circuits. My suspicion is that fixing this in the plugin should be quite straightforward.

Also see #58, which describes some confusion surrounding CSignal.

bgamari added a commit to bgamari/circuit-notation that referenced this issue Jan 27, 2024
Clash must use `CSignal`, not `Signal`, for unidirectional signals in
`Circuit`s.

See clash-lang/clash-protocols#59.
@bgamari
Copy link
Collaborator Author

bgamari commented Jan 27, 2024

I have opened cchalmers/circuit-notation#17 addressing this.

@martijnbastiaan
Copy link
Member

Does this actually compile? I think the plugin would handle Signal reg1 <- ... "correctly" as discussed in the PR, but I'm not sure how it would magically change CSignal to Signal.

@bgamari
Copy link
Collaborator Author

bgamari commented Jan 27, 2024

It doesn't. I realized that after opening it that upstream has shifted appreciably. Unfortunately it's not entirely clear to me how to account for these changes (particularly the addition of tagBundlePat, et al.) in clash-protocols.

@martijnbastiaan
Copy link
Member

That PR went in before I could properly understand it. I didn't even realize it had downstream consequences :(.

@martijnbastiaan
Copy link
Member

We've bumped to the latest circuit-notation in #61. I think we've cleared up the confusion in the meantime. If that's incorrect please re-open the issue @bgamari.

@DigitalBrains1 DigitalBrains1 changed the title Handling undirectional Signals in circuits Handling unidirectional Signals in circuits Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants