Skip to content

SystemVerilog: --initial-zero #1001

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

SystemVerilog: --initial-zero #1001

wants to merge 1 commit into from

Conversation

kroening
Copy link
Member

The SystemVerilog standard specifies that variables are to be zero initialized before simulation begins. Some synthesis tools generate logic to achieve this, whereas others do not.

This adds the option --initial-zero to match the synthesis semantics when appropriate.

@kroening kroening marked this pull request as ready for review February 20, 2025 11:23
Comment on lines 14 to 48
std::optional<exprt> verilog_zero_initializer(const typet &type)
{
if(type.id() == ID_signedbv || type.id() == ID_unsignedbv)
return from_integer(0, type);
else if(type.id() == ID_bool)
return false_exprt{};
else if(type.id() == ID_array)
{
auto &array_type = to_array_type(type);
auto zero_element_opt = verilog_zero_initializer(array_type.element_type());
if(!zero_element_opt.has_value())
return {};
else
return array_of_exprt{*zero_element_opt, array_type};
}
else if(type.id() == ID_struct)
{
auto &struct_type = to_struct_type(type);
exprt::operandst member_values;
for(auto &component : struct_type.components())
{
auto member_value_opt = verilog_zero_initializer(component.type());
if(!member_value_opt.has_value())
return {};
member_values.push_back(*member_value_opt);
}
return struct_exprt{std::move(member_values), struct_type};
}
else
return {};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would seem safe to just use zero_initializer from CBMC's code base?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ping? ^^

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we actually need to make CBMC's zero_initializer easier to extend?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's either that or a copy.

The SystemVerilog standard specifies that variables are to be zero
initialized before simulation begins.  Some synthesis tools generate logic
to achieve this, whereas others do not.

This adds the option --initial-zero to match the synthesis semantics when
appropriate.
Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

I'm always opposed to code duplication so I'd strongly favour an approach that will facilitate code reuse, but I understand that this may require more effort than is possible to put in right now.

@kroening
Copy link
Member Author

I'm always opposed to code duplication so I'd strongly favour an approach that will facilitate code reuse, but I understand that this may require more effort than is possible to put in right now.

We also need extensibility for the solvers, the SMT-LIB converter, and the simplifier.

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.

None yet

2 participants