From 84ee833ea78d481a9a0db9150ee3a4038c7abc7d Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 2 Jan 2022 12:26:10 -0500 Subject: [PATCH] Ignore --x-initial unique inside classes. --- docs/guide/exe_verilator.rst | 7 ++++--- src/V3Unknown.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/guide/exe_verilator.rst b/docs/guide/exe_verilator.rst index b85a7036c..37741a603 100644 --- a/docs/guide/exe_verilator.rst +++ b/docs/guide/exe_verilator.rst @@ -1364,9 +1364,10 @@ Summary: .. note:: This option applies only to values which are explicitly written as X - in the Verilog source code. Initial values of clocks are set to 0 - unless `--x-initial-edge` is specified. Initial values of all other - state holding variables are controlled with `--x-initial`. + in modules (not classes) in the Verilog source code. Initial values + of clocks are set to 0 unless `--x-initial-edge` is + specified. Initial values of all other state holding variables are + controlled with `--x-initial`. .. option:: --x-initial 0 diff --git a/src/V3Unknown.cpp b/src/V3Unknown.cpp index b5daaf8a5..e1db3adc5 100644 --- a/src/V3Unknown.cpp +++ b/src/V3Unknown.cpp @@ -57,6 +57,7 @@ private: AstAssignW* m_assignwp = nullptr; // Current assignment AstAssignDly* m_assigndlyp = nullptr; // Current assignment bool m_constXCvt = false; // Convert X's + bool m_allowXUnique = true; // Allow unique assignments VDouble0 m_statUnkVars; // Statistic tracking V3UniqueNames m_lvboundNames; // For generating unique temporary variable names V3UniqueNames m_xrandNames; // For generating unique temporary variable names @@ -141,9 +142,12 @@ private: UINFO(4, " MOD " << nodep << endl); VL_RESTORER(m_modp); VL_RESTORER(m_constXCvt); + VL_RESTORER(m_allowXUnique); { m_modp = nodep; m_constXCvt = true; + // Class X randomization causes Vxrand in strange places, so disable + if (VN_IS(nodep, Class)) m_allowXUnique = false; m_lvboundNames.reset(); m_xrandNames.reset(); iterateChildren(nodep); @@ -310,7 +314,7 @@ private: numb1.opBitsOne(nodep->num()); V3Number numbx(nodep, nodep->width()); numbx.opBitsXZ(nodep->num()); - if (v3Global.opt.xAssign() != "unique") { + if (!m_allowXUnique || v3Global.opt.xAssign() != "unique") { // All X bits just become 0; fastest simulation, but not nice V3Number numnew(nodep, numb1.width()); if (v3Global.opt.xAssign() == "1") { @@ -329,6 +333,7 @@ private: AstVar* const newvarp = new AstVar(nodep->fileline(), AstVarType::XTEMP, m_xrandNames.get(nodep), VFlagLogicPacked(), nodep->width()); + newvarp->lifetime(VLifetime::STATIC); ++m_statUnkVars; VNRelinker replaceHandle; nodep->unlinkFrBack(&replaceHandle);