You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit adds four new canonicalization patterns to FIRRTL.
mux(cond, 0, b) -> and(not(cond), b)
mux(cond, 1, b) -> or(cond, b)
mux(cond, a, 0) -> and(cond, a)
mux(cond, a, 1) -> or(not(cond), a)
These canonicalizations are already present for the comb dialect, but we want
to run these canonicalizers before lowering layers, which can obscure constant
ops behind ports.
The problem with these mux canonicalizers is, they conflict with a register
canonicalizer. This register canonicalizer converts a register to a constant,
if the register's next-value is a mux of either the register itself, or a
constant. For example:
connect(reg, mux(reset, 0, reg)) ==> reg -> 0
These new canonicalizers would transform the connect to:
connect(reg, and(not(reset), reg))
...which prevents the register canonicalizer from running. To get this
behaviour back, this PR adds four additional canonicalizations for both
registers and reg resets: For registers, the canonicalizers are:
connect(reg, and(reg, x)) ==> reg -> 0
connect(reg, and(x, reg)) ==> reg -> 0
connect(reg, or(reg, x)) ==> reg -> 1
connect(reg, or(x, reg)) ==> reg -> 1
For regresets, we have the same canonicalizers, but with an additional check:
the reset value must be a constant zero or one.
reset(reg) = 0 ==> connect(reg, and(reg, x)) ==> reg -> 0
reset(reg) = 0 ==> connect(reg, and(x, reg)) ==> reg -> 0
reset(reg) = 1 ==> connect(reg, or(reg, x)) ==> reg -> 1
reset(reg) = 1 ==> connect(reg, or(x, reg)) ==> reg -> 1
0 commit comments