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 FVIntegerAttr #7461

Merged
merged 1 commit into from
Aug 8, 2024
Merged

[Moore] Add FVIntegerAttr #7461

merged 1 commit into from
Aug 8, 2024

Conversation

fabianschuiki
Copy link
Contributor

Add the FVIntegerAttr, an attribute containing an FVInt value. This allows four-valued integer constants to be used as attributes on operations and for constant folding to occur on such values. In contrast to the builtin IntegerAttr, FVIntegerAttr does not have a type yet. The type can be added later as soon as we have a concrete use case.

I expect us to eventually move FVIntegerAttr into the HW dialect once we are happy with its design. Other parts of CIRCT will eventually want to reason about four-valued integers as well.

The parsing and printing of the attribute tries to make the FVInt read like a plain old APInt when there are no X or Z bits present. Otherwise it falls back to printing as hexadecimal or binary number. To distinguish the different representations and to allow constants with X or Z to be parsed as keywords, a h and b prefix is used for the hexadecimal and binary formatting, respectively.

Examples of the attribute:

#moore.fvint<42 : 32>
#moore.fvint<-42 : 32>
#moore.fvint<1234567890123456789012345678901234567890 : 131>
#moore.fvint<hABCDEFXZ0123456789 : 72>
#moore.fvint<b1010XZ01 : 8>

Add the `FVIntegerAttr`, an attribute containing an `FVInt` value. This
allows four-valued integer constants to be used as attributes on
operations and for constant folding to occur on such values. In contrast
to the builtin `IntegerAttr`, `FVIntegerAttr` does not have a type yet.
The type can be added later as soon as we have a concrete use case.

I expect us to eventually move `FVIntegerAttr` into the HW dialect once
we are happy with its design. Other parts of CIRCT will eventually want
to reason about four-valued integers as well.

The parsing and printing of the attribute tries to make the `FVInt` read
like a plain old `APInt` when there are no X or Z bits present.
Otherwise it falls back to printing as hexadecimal or binary number.
To distinguish the different representations and to allow constants with
X or Z to be parsed as keywords, a `h` and `b` prefix is used for the
hexadecimal and binary formatting, respectively.

Examples of the attribute:

    #moore.fvint<42 : 32>
    #moore.fvint<-42 : 32>
    #moore.fvint<1234567890123456789012345678901234567890 : 131>
    #moore.fvint<hABCDEFXZ0123456789 : 72>
    #moore.fvint<b1010XZ01 : 8>
Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

I think the boilerplate to add the attribute looks good. The printer/parser is nice, looks good to me.

Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

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

Awesome!

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.

Learned some new coding. LGTM 🎉!

@fabianschuiki
Copy link
Contributor Author

Thanks for the reviews 😃 Going to land this.

@fabianschuiki fabianschuiki merged commit 04ba6a3 into main Aug 8, 2024
4 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/FVIntegerAttr branch August 8, 2024 15:57
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.

4 participants