Optimize constant operations and enforce Const immutability#682
Open
mkorbel1 wants to merge 21 commits into
Open
Optimize constant operations and enforce Const immutability#682mkorbel1 wants to merge 21 commits into
mkorbel1 wants to merge 21 commits into
Conversation
Added some more changes based on feedback (intel#481)
desmonddak
approved these changes
Jul 15, 2026
desmonddak
left a comment
Contributor
There was a problem hiding this comment.
Looks great.
I'm curious about simulation performance improvements, especially the shift operators.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description & Motivation
This PR supersedes #481 and continues the work started there. The original commits from #481 are included in this branch so that @mjayasim9 remains credited for her contributions.
This completes and expands the constant optimizations described in #429:
Const.Modules for constant bitwise operations, reductions, comparisons, and shifts when the result can be computed immediately.Muxwhen its control is a validConst.zinstead of producingx.This also addresses #486 by preventing a
Constvalue from being changed throughputorinject, including attempts made through anotherLogicdriven by thatConst. These attempts now throw anUnassignableExceptionthat identifies the signal through which the update was attempted and the immutable signal driving it.Together, these changes improve simulation performance, reduce unnecessary generated SystemVerilog, and ensure that simulated and synthesized constant values remain consistent.
Related Issue(s)
Closes #429.
Closes #486.
Supersedes #481.
Testing
Added and expanded tests covering:
xandzbehavior, including cases that must not be optimized into direct operand reuse.Const.Const.Backwards-compatibility
Narrowly, yes. Code that directly modifies a
Const, or modifies anotherLogicdriven by aConst, throughputorinjectwill now throw anUnassignableException.This is an intentional behavior correction for #486. Mutating a
Constcontradicted its contract and could cause simulation results to disagree with synthesized output. Normal uses ofConstand existing operation APIs are otherwise unchanged.Documentation
Yes. API documentation for
Constand constant-controlled mux behavior has been updated.