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

verific: Add bottom and top bound properties to wire #4538

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

RCoeurjoly
Copy link
Contributor

@RCoeurjoly RCoeurjoly commented Aug 14, 2024

What are the reasons/motivation for this change?

Having bound properties for wires would help detect underflow and overflow in cases where the user is more restrictive than the RTLIL representation.
For example, the following VHDL

signal a : INTEGER range 0 to 6;
is represented in RTLIL as:
wire width 3 input 1 \a because to represent decimal 6 you need at least 3 bits.
However, decimal 7 can also be represented, which would be an overflow as per the user specified range, and that user constraint would get lost without this attribute.
This patch helps ensure that those user constraints are maintained and accessible in the RTLIL representation.

Explain how this is achieved.

With the Verific API, we get the bounds information and create attributes (named bottom_bound and top_bound).
Those attributes are of the same bit width as the wire they belong to.
If at least one the bound is negative, both constants are flagged as signed.

Supporting changes

printattrs.cc: Updated the logic to print attributes for signed constants.
RTLIL::Const: The constructor was modified to use long long instead of int. This is necessary because to support VHDL 2019 integers with bit widths up to 64, the Verific API’s TypeRange::GetScalarRangeLeftBound() method returns a long long.

Discarded options

We decided that bound attributes for enumeration types will not be added in this PR.

frontends/verific/verific.cc Outdated Show resolved Hide resolved
frontends/verific/verific.cc Outdated Show resolved Hide resolved
@widlarizer widlarizer changed the title Add left and right bound properties to wire verific: Add left and right bound properties to wire Aug 15, 2024
Copy link
Member

@nakengelhardt nakengelhardt left a comment

Choose a reason for hiding this comment

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

Please make your formatting conform to the surrounding code/the yosys coding style.

The tests do not seem to test anything, what is their intent?

frontends/verific/verific.cc Outdated Show resolved Hide resolved
@RCoeurjoly
Copy link
Contributor Author

Please make your formatting conform to the surrounding code/the yosys coding style.

The tests do not seem to test anything, what is their intent?

Formatting done.

The tests were meant to exercise the log_asserts, but now that there are none, we could remove them.

@RCoeurjoly RCoeurjoly marked this pull request as draft August 19, 2024 17:40
@RCoeurjoly
Copy link
Contributor Author

Coverted to draft because most likely we want this PR to be merged first so that is_bound_signed attribute is not necessary.

@RCoeurjoly RCoeurjoly marked this pull request as ready for review August 21, 2024 14:22
@RCoeurjoly RCoeurjoly dismissed nakengelhardt’s stale review August 21, 2024 14:31

Requested changes are done, but no way to resolve the conversation

@RCoeurjoly RCoeurjoly requested a review from povik August 21, 2024 14:41
@RCoeurjoly RCoeurjoly changed the title verific: Add left and right bound properties to wire verific: Add bttom and top bound properties to wire Aug 22, 2024
@RCoeurjoly RCoeurjoly changed the title verific: Add bttom and top bound properties to wire verific: Add bottom and top bound properties to wire Aug 22, 2024
tests/verific/bounds.ys Outdated Show resolved Hide resolved
frontends/verific/verific.cc Outdated Show resolved Hide resolved
for signed attributes

Co-authored-by: N. Engelhardt <[email protected]>
Co-authored-by: Roland Coeurjoly <[email protected]>
Copy link
Member

@povik povik left a comment

Choose a reason for hiding this comment

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

I can't speak to how the Verific interface is used, but otherwise it looks good to me

tests/verific/bounds.ys Show resolved Hide resolved
@nakengelhardt nakengelhardt merged commit c8b42b7 into YosysHQ:main Sep 12, 2024
14 checks passed
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.

4 participants