diff --git a/clash-protocols-base/src/Protocols/Internal.hs b/clash-protocols-base/src/Protocols/Internal.hs index d82318b7..34d52c08 100644 --- a/clash-protocols-base/src/Protocols/Internal.hs +++ b/clash-protocols-base/src/Protocols/Internal.hs @@ -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'. -} diff --git a/clash-protocols/src/Protocols.hs b/clash-protocols/src/Protocols.hs index 0d2b1aff..bda4bd7e 100644 --- a/clash-protocols/src/Protocols.hs +++ b/clash-protocols/src/Protocols.hs @@ -30,6 +30,7 @@ module Protocols ( -- * Basic circuits idC, repeatC, + repeatWithIndexC, prod2C, -- * Simulation