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

Add variants of Df functions that handle function arguments wrapped in signals #107

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

t-wallet
Copy link
Collaborator

@t-wallet t-wallet commented Sep 6, 2024

Various Df combinators are higher-order functions, such as map and filter. Sometimes it is handy if those combinators are able to handle functions that are wrapped inside of a Signal. For example:

arpReceiverC
  :: forall (dom :: Domain) (dataWidth :: Nat)
   . HiddenClockResetEnable dom
  => KnownNat dataWidth
  => 1 <= dataWidth
  => Signal dom IPv4Address
  -> Circuit (PacketStream dom dataWidth EthernetHeader) (Df dom ArpEntry, Df dom ArpLite)
arpReceiverC myIP = circuit $ \ethStream -> do
  arpDf <- depacketizeToDfC const -< ethStream
  arpDf' <- Df.filterS (isValidArp <$> myIP) -< arpDf
  (arpRequests, arpEntries) <- partitionS (isRequest <$> myIP) -< arpDf'
  ...

In this case we want to filter out all invalid ARP packets from a Df stream. But such a filter depends on our IPv4 address, which may change over time and is thus wrapped in a Signal. Then, the filter function itself is also wrapped in a Signal.

This PR adds such combinators, named with an S suffix. For map and filter we already have such functions. This PR adds:

bimapS
eitherS
firstS
secondS
mapLeftS
mapRightS
selectUntilS
partitionS
zipWithS
faninS

@rowanG077 rowanG077 self-requested a review September 13, 2024 13:10
Copy link
Member

@rowanG077 rowanG077 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, can be merged once the conflicts are fixed.

@t-wallet t-wallet enabled auto-merge September 13, 2024 17:42
@t-wallet t-wallet merged commit 0832a42 into main Sep 13, 2024
8 checks passed
@t-wallet t-wallet deleted the df-signal-functions branch September 13, 2024 18:01
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

Successfully merging this pull request may close these issues.

2 participants