8000 Fix --x-initial and --x-assign random stability (#2662) by toddstrader · Pull Request #5958 · verilator/verilator · GitHub
[go: up one dir, main page]

Skip to content

Fix --x-initial and --x-assign random stability (#2662) #5958

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

Merged
merged 21 commits into from
May 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
toddstrader committed May 16, 2025
commit fba7ab56aff6a07eccd0a5696cac8035e517fec0
9 changes: 0 additions & 9 deletions src/V3EmitCFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#include <string>
#include <vector>

// NOCOMMIT
VL_DEFINE_DEBUG_FUNCTIONS;

// We use a static char array in VL_VALUE_STRING
constexpr int VL_VALUE_STRING_MAX_WIDTH = 8192;

Expand Down Expand Up @@ -674,8 +671,6 @@ void EmitCFunc::emitVarReset(AstVar* varp, bool constructing) {
string EmitCFunc::emitVarResetRecurse(const AstVar* varp, bool constructing,
const string& varNameProtected, AstNodeDType* dtypep,
int depth, const string& suffix) {
UINFO(1, "Var Reset -- " << varp->prettyName() << " -- " << varp->name() << " - "
<< varp->origName() << " -- " << varp << endl);
dtypep = dtypep->skipRefp();
AstBasicDType* const basicp = dtypep->basicp();
// Returns string to do resetting, empty to do nothing (which caller should handle)
Expand Down Expand Up @@ -778,7 +773,6 @@ string EmitCFunc::emitVarResetRecurse(const AstVar* varp, bool constructing,
if (!zeroit) {
emitVarResetScopeHash();
uint64_t salt = std::hash<std::string>{}(varp->prettyName());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
uint64_t salt = std::hash<std::string>{}(varp->prettyName());
const uint64_t salt = std::hash<std::string>{}(varp->prettyName());

Copy link
Member

Choose a reason for hiding this comment

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

C++ "Hash functions are only required to produce the same result for the same input within a single execution of a program". So use VString functions instead, making a new one if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a bummer.

I dropped a hash function in V3String and also the runtime library. Is there something better to do here? I don't see any hash functions already associated with VString. There is a SHA256 in there, but it speaks about 64B blocks and I don't think that's what we want for this application. There's also V3Hash but that is intrinsically 32b. Also, is there a reasonable way to share code between the compiler and the runtime? I'm not seeing any examples.

UINFO(1, "Var Hash -- " << varp->prettyName() << " -- " << salt << endl);
out += ", ";
out += "__VscopeHash, ";
out += std::to_string(salt);
Expand All @@ -799,10 +793,8 @@ string EmitCFunc::emitVarResetRecurse(const AstVar* varp, bool constructing,
} else {
emitVarResetScopeHash();
uint64_t salt = std::hash<std::string>{}(varp->prettyName());
UINFO(1, "Var Hash -- " << varp->prettyName() << " -- " << salt << endl);
out += " = VL_SCOPED_RAND_RESET_";
out += dtypep->charIQWN();
// NOCOMMIT -- 64b
out += "(" + cvtToStr(dtypep->widthMin()) + ", " + "__VscopeHash, "
+ std::to_string(salt) + "ull);\n";
}
Expand All @@ -816,7 +808,6 @@ string EmitCFunc::emitVarResetRecurse(const AstVar* varp, bool constructing,

void EmitCFunc::emitVarResetScopeHash() {
if (m_createdScopeHash) { return; }
// NOCOMMIT -- name?
if (m_class) {
puts("uint64_t __VscopeHash = " + std::to_string(std::hash<std::string>{}(m_class->name()))
+ "ULL;\n");
Expand Down
0