Open leonardt opened 5 years ago
Hmm, as I dig deeper into this issue, it seems that the coreir primitives use the same width
interface, so at some point the logic on these composite types need to be represented in terms of the coreir primitives (unless they are also extended to have this more "generalized" interface). It seems that we might be able to write some reuseable logic for all primitives to recursively apply these operators in terms of the leaf nodes of the type, so once it reaches coreir it's all been lowered into the wiring of Bit or Bits types.
I've added an initial implementation for multi-dimensional arrays in the mux, see this commit https://github.com/phanrahan/mantle/commit/645946de15a5e241cc577011ac149db35ca22b39
We should be able to generalize this logic for all operators (basically, if it's not a leaf node type, then recursively generate the children and wire them up).
It should be extendable to Tuples, but I haven't implemented that yet, will probably wait until we decide on a clean design before investing more into it, unless someone needs the feature.
The current interface to the mantle primitives accepts a
width
parameter to the generator.This interface is limiting when encountering more complex types, such as a multi dimensional array.
For example, one may want to write the following code
But when I try to run it I get
The underlying issue is that the mantle operator for
mux
expected that the input lengths are a single dimension array or single bit (soget_length
returns an integer for an array or None or a Bit). However, in this case, we have a 2d array. One augmentation to support this would be to add a notion of atuple
for width, sowidth=(2, 4)
would correspond to a 2x4 array. But this doesn't necessary extend to records.I think the more general solution would be to change the
width
parameter, to a "type" parameter (eithertype_
orT
), which specifies the magma type of the input/output. So instead ofwidth=4
, we would saytype_=Bits(4)
. We could still providewidth
as a convenience parameter (which would settype_=BitsOrBit(width)
under the hood), but then this would allow the user to specify something likemantle.Mux(height=2, type_=m.Tuple(m.Bit, m.Bits(3))
, which I think would be a better solution than trying to build some tuple semantics into thewidth
parameter.