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

Avoid module creation for simple constant scenarios in gates #429

Open
mkorbel1 opened this issue Nov 3, 2023 · 3 comments · May be fixed by #481
Open

Avoid module creation for simple constant scenarios in gates #429

mkorbel1 opened this issue Nov 3, 2023 · 3 comments · May be fixed by #481
Assignees
Labels
enhancement New feature or request

Comments

@mkorbel1
Copy link
Contributor

mkorbel1 commented Nov 3, 2023

Motivation

Sometimes it's easy to initialize some variable to 0 or 1, and then do multiple operator functions on it afterwards like &, ~, and |. There are some common rules that we can use to avoid creating gates when not necessary. For example:

  • ~0 == 1 (inversion of a constant is constant of inversion)
  • (x & 0) == 0
  • (x & 1) == x
  • (x | 0) == x
  • (x | 1) == 1

Skipping over these scenarios would allow for boosts in simulation performance and cleaner generated verilog.

Desired solution

Modify the operator overrides in Logic to avoid creation of Modules if it can instead directly compute a Logic to return (like in above situations).

Note that this won't completely avoid all the applicable scenarios alone since there could be things like 0 assigned to another signal which is then used in a gate. Perhaps some optimization in the generation of verilog after assignment collapsing could help even more.

Alternatives considered

No response

Additional details

No response

@mkorbel1 mkorbel1 added the enhancement New feature or request label Nov 3, 2023
@mjayasim9
Copy link
Contributor

Will work on this!

@mkorbel1
Copy link
Contributor Author

We should probably make it impossible to put onto a Const to avoid weird surprises when this optimization happens

@mkorbel1
Copy link
Contributor Author

I think this should also cover shifts by 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants