-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Another shot to answer the evergreen undefinedness of undriven signals in Calyx (#922). In its most reduced operational form, it asks when is it safe to provide 'x as the default value for a port instead of '0.
The core of this proposal are two new attributes: @data and @control. The @data attribute marks a cell as a data path component, and the @control attribute marks a cell as a control path component. These attributes are mutually exclusive, and a cell can only have one of them.
comb primitive std_add[WIDTH](@data a: WIDTH, @data b: WIDTH) -> (out: WIDTH);
primitive std_mult_pipe[WIDTH](@control go: 1, @data a: WIDTH, @data b: WIDTH) -> (out: WIDTH, @control done: 1);
cells {
@data add0 = std_add(32);
@control incr = std_add(32);
@data mult = std_mult_pipe(32); // mult.go must always be defined
}
An instance marked with @control requires all its ports to have '0 as the default value. An instance marked with @data additionally needs to mark some of its ports with the @data attribute to state that these can accept 'x as the default value. This is because even for data path components, certain ports like the go port might always need a non-'x value.
This proposal follows a safe-by-default approach to the problem: it is always safe to ignore the @data attributes and provide all ports with a default value of '0. The @control attribute is just a safety mechanism that can be used to catch errors early.
Conditions for @control Instances
Following the things enumerated in #922, here is a list of some constraints the forces an instance to be a control instance:
- If it is used in the guard of an assignment
- If it is used as the done condition of a group
- If it is used as the conditional port for
iforwhile - If it is used as the input to a
@goport such aswrite_en - If it is used as an input for another
@controlinstance
Note that if any port of an instance is used in these positions, the instance must be marked as a @control instance. Number (5) is the challenging one here since it's a recursive condition. However, I don't see any other way to address the problem of propagation of undefinedness from data path to the control path. The interesting question is whether this approach will leave any instances as @data instances.
We can design a new pass that can compute which cells are @control using the criteria above. If these conditions are necessary and sufficient, all the cells not marked with @control are @data cells.
Semantics
Everything up till now gives a very operational view of how to address the undefinedness problem. However, it doesn't give us a clear view on what the exact semantic properties are. As far as I can tell, the semantics needs to be defined in terms of these attributes. There is no a priori way to define which signals are data path and which are control path; we can only call programs undefined given an assignment of attributes to instances.