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
253 stars 76 forks source link

Optimize is currently missing the elimination of "double not" #447

Open timsherwood opened 3 months ago

timsherwood commented 3 months ago

The pyrtl.optimize code is not eliminating "double not" conditions (reducing them to a single wire). Right now it does some more complex optimizations including CSE but this very simple case gets missed. You can see very clearly from the code below.

import pyrtl

a = pyrtl.Input(1,'a')
q = pyrtl.Output(1,'q')
q <<= ~(~(a))

pyrtl.synthesize()

with open('pre-optimize.svg','w') as f:
    pyrtl.output_to_svg(f)

pyrtl.optimize()

with open('post-optimize.svg','w') as f:
    pyrtl.output_to_svg(f)