Skip to content

Conversation

@kroening
Copy link
Collaborator

This adds conversions from/to packed unions to/from vector types.

@kroening kroening marked this pull request as ready for review September 29, 2024 22:10
}
else if(dest.id() == ID_union)
{
// We use the first field of the union.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious: does Verilog require that all fields have the same width? If not, could there be any problems if the first field wasn't sufficiently wide?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, in Verilog packed unions all fields must be the same width. Will add comment to say so.

{
auto new_type =
unsignedbv_typet{numeric_cast_v<std::size_t>(get_width(type))};
expr = typecast_exprt{expr, new_type};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this reach our back-end? I don't think we'd support casts from a union. I suspect we'd need an extractbits here instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the synthesis stage turns these into a member expression -- will add comment.

This adds conversions from/to packed unions to/from vector types.
@tautschnig tautschnig merged commit d4525b6 into main Sep 30, 2024
@tautschnig tautschnig deleted the union4 branch September 30, 2024 16:44
Romy15200 pushed a commit to Romy15200/nws that referenced this pull request Aug 19, 2025
SystemVerilog: conversion from/to packed union
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.

3 participants