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 a minimal value-addressable multiplexer primitive valid on LHS and RHS #480

whitequark opened this issue Aug 17, 2020 · 0 comments


Copy link

@whitequark whitequark commented Aug 17, 2020

Right now, Array holds a special position in the language: it is one of the few constructs (the other being indexed part select) that encapsulates control flow, and at the same time can be used at both left-hand and right-hand side of assignment. That is, the result of indexing Array with a value, ArrayProxy, can be assigned to, but unlike ValueCastable, it doesn't have to be replaced with just a single value. This is made possible by expanding any statements that contains an ArrayProxy (or several) into a switch statement where the branches are the combinatorial product of every possible value of every controlling expression of an ArrayProxy.

It is unfortunate that ArrayProxy is tied deep into the language because it has broad powers (control flow + being on LHS) restricted to a narrow scope (emulating the list interface):

  • ArrayProxy has a lot of code that has nothing to do with multiplexing per se (it deals with transparent-ish proxying of Python sequences).
  • Array and ArrayProxy are mimicking Python lists. This is a reasonable approach, but not the only reasonable approach: it would be nice to have something similar mimicking Python dicts.
  • Building abstractions on top of ArrayProxy is a bad experience, as @pepijndevos discovered. Since nMigen aims to be a toolkit suitable for building HLS-style systems, it is important to enable this.

I propose to add a new primitive tentatively called ValueSwitch (name subject to bikeshed), that would encapsulate only the bare minimum of what Array does, enabling downstream code to easily define their own variations on Array that translate efficiently, and also potentially enabling us to add AssocArray (#73) and migrate ArrayProxy to be a simple ValueCastable (#73 (comment)) without any changes to the RTLIL backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

1 participant