Skip to content

Commit

Permalink
Introduce repeatWithIndexC
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed Sep 9, 2024
1 parent 5b378a1 commit 241c6c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions clash-protocols-base/src/Protocols/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ repeatC ::
repeatC (Circuit f) =
Circuit (C.unzip . C.map f . uncurry C.zip)

{- | Copy a circuit /n/ times, providing access to the index of each replica.
If looking for a circuit that turns a single channel into multiple, check out
'Protocols.Df.fanout'.
-}
repeatWithIndexC
:: forall n a b. (C.KnownNat n) =>
(C.Index n -> Circuit a b) ->
Circuit (C.Vec n a) (C.Vec n b)
repeatWithIndexC f =
Circuit (C.unzip . C.zipWith g C.indicesI . uncurry C.zip)
where
g i = case f i of Circuit f' -> f'

{- | Combine two separate circuits into one. If you are looking to combine
multiple streams into a single stream, checkout 'Protocols.Df.fanin'.
-}
Expand Down
1 change: 1 addition & 0 deletions clash-protocols/src/Protocols.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Protocols (
-- * Basic circuits
idC,
repeatC,
repeatWithIndexC,
prod2C,

-- * Simulation
Expand Down

0 comments on commit 241c6c1

Please sign in to comment.