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

[Moore] Add explicit truncation and zero/sign-extension #7783

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

fabianschuiki
Copy link
Contributor

Add the moore.trunc operation to explicitly truncate the bit width of IntType values, and moore.zext and moore.sext to explicitly extend such a value with zeroes or its sign bit.

This requires tweaking the way how ImportVerilog generates conversion ops. Currently moore.conversion is used as a catch-all operation that expresses any kind of type conversion. In the future, we'll want to split this up into multiple dedicated operations. These width adjustment ops are the first step in that direction.

Making sign-extension explicit also fixes a long-standing issue where a $signed or signed'(x) expression would be erroneously converted into a zero-extension.

Add the `moore.trunc` operation to explicitly truncate the bit width of
`IntType` values, and `moore.zext` and `moore.sext` to explicitly extend
such a value with zeroes or its sign bit.

This requires tweaking the way how ImportVerilog generates conversion
ops. Currently `moore.conversion` is used as a catch-all operation that
expresses any kind of type conversion. In the future, we'll want to
split this up into multiple dedicated operations. These width adjustment
ops are the first step in that direction.

Making sign-extension explicit also fixes a long-standing issue where a
`$signed` or `signed'(x)` expression would be erroneously converted into
a zero-extension.
Copy link
Member

@hailongSun2000 hailongSun2000 left a comment

Choose a reason for hiding this comment

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

I don't have any questions. Perfect 👍!

Comment on lines +1082 to +1084
if (value.getType() != srcWidthType)
value = builder.create<moore::ConversionOp>(value.getLoc(), srcWidthType,
value);
Copy link
Member

Choose a reason for hiding this comment

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

So cool 😎!

@fabianschuiki fabianschuiki merged commit 1a592a7 into main Nov 8, 2024
4 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/moore-trunc-ext branch November 8, 2024 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants