Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate double inverts in pyrtl.optimize #462

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

gaborszita
Copy link
Contributor

Closes #447

Example:

Block before optimize Block after optimize (without my changes) Block after optimize (with my changes)
image image image

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.8%. Comparing base (5077c24) to head (6e872b3).

Additional details and impacted files
@@              Coverage Diff              @@
##           development    #462     +/-   ##
=============================================
+ Coverage         91.7%   91.8%   +0.2%     
=============================================
  Files               24      24             
  Lines             6403    6454     +51     
=============================================
+ Hits              5866    5920     +54     
+ Misses             537     534      -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@fdxmw fdxmw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this issue! A couple high-level comments before we get into coding details:

  1. O(N^2) nested for loops over block.logic should generally be avoided in passes because they don't scale well as the number of nets increases - the pass will take too long to run. It seems possible to iterate over block.logic once and build a list of all the inverter chains in the block (see how other passes create a _ProducerList for example). Then I think we can iterate over that list and decide if each inverter chain can be simplified?
  2. This really needs a test :) Some test cases that come to mind:
    1. Chains of 1, 2, 3, and 4 inverters (even numbers of inverters should be removed, and odd numbers of inverters should be simplified to one inverter)
    2. A chain of 2 inverters with another user of the first inverter's output (should not be simplified)

@gaborszita
Copy link
Contributor Author

Thank you for fixing this issue! A couple high-level comments before we get into coding details:

  1. O(N^2) nested for loops over block.logic should generally be avoided in passes because they don't scale well as the number of nets increases - the pass will take too long to run. It seems possible to iterate over block.logic once and build a list of all the inverter chains in the block (see how other passes create a _ProducerList for example). Then I think we can iterate over that list and decide if each inverter chain can be simplified?

  2. This really needs a test :) Some test cases that come to mind:

    1. Chains of 1, 2, 3, and 4 inverters (even numbers of inverters should be removed, and odd numbers of inverters should be simplified to one inverter)
    2. A chain of 2 inverters with another user of the first inverter's output (should not be simplified)

All addressed

@gaborszita gaborszita requested a review from fdxmw January 17, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize is currently missing the elimination of "double not"
2 participants