UCSBarchlab / PyRTL

A collection of classes providing simple hardware specification, simulation, tracing, and testing suitable for teaching and research. Simplicity, usability, clarity, and extensibility are the overarching goals, rather than performance or optimization.
http://ucsbarchlab.github.io/PyRTL
BSD 3-Clause "New" or "Revised" License
257 stars 78 forks source link

Add optional pass for making all fanouts <= 2 #361

Closed mdko closed 3 years ago

mdko commented 3 years ago

This PR adds an optional pass (pyrtl.two_way_fanout()) that makes it so all wires go to at most 2 destinations. It also adds a convenient helper function called pyrtl.fanout for calculating the fanout of a wire.

In a future PR, it would be nice to make the maximum target fanout an argument to the function. Another nicety would be to optimize so that the first split after the original wire isn't needed.

Note the fanout of the wire coming out of and in this example was originally 4 but now has a tree of wires so that no fanout is greater than 2.

Before

pre

After

post