From 949be9d0a139ae28be4ade2e6b5538021c8ecbfc Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Tue, 2 May 2023 14:28:56 +0300 Subject: [PATCH] Optimize VPI callValueCbs (#4155) Co-authored-by: Oleh Maks --- docs/CONTRIBUTORS | 2 ++ include/verilated_vpi.cpp | 44 +++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 629517575..103cd554d 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -43,6 +43,7 @@ Guokai Chen Gustav Svensk G-A. Kamendje Harald Heckmann +Hennadii Chernyshchyk Howard Su Huang Rui Huanghuang Zhou @@ -108,6 +109,7 @@ Mostafa Gamal Nandu Raj Nathan Kohagen Nathan Myers +Oleh Maksymenko Patrick Stewart Paul Wright Pawel Sagan diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 4d84eca49..2d2e00664 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -165,6 +165,7 @@ class VerilatedVpioVarBase VL_NOT_FINAL : public VerilatedVpio { protected: const VerilatedVar* m_varp = nullptr; const VerilatedScope* m_scopep = nullptr; + std::string m_fullname; const VerilatedRange& get_range() const { // Determine number of dimensions and return outermost return (m_varp->dims() > 1) ? m_varp->unpacked() : m_varp->packed(); @@ -173,11 +174,13 @@ protected: public: VerilatedVpioVarBase(const VerilatedVar* varp, const VerilatedScope* scopep) : m_varp{varp} - , m_scopep{scopep} {} + , m_scopep{scopep} + , m_fullname{std::string{m_scopep->name()} + '.' + name()} {} explicit VerilatedVpioVarBase(const VerilatedVpioVarBase* varp) { if (varp) { m_varp = varp->m_varp; m_scopep = varp->m_scopep; + m_fullname = varp->m_fullname; } } static VerilatedVpioVarBase* castp(vpiHandle h) { @@ -188,11 +191,7 @@ public: uint32_t size() const override { return get_range().elements(); } const VerilatedRange* rangep() const override { return &get_range(); } const char* name() const override { return m_varp->name(); } - const char* fullname() const override { - static thread_local std::string t_out; - t_out = std::string{m_scopep->name()} + "." + name(); - return t_out.c_str(); - } + const char* fullname() const override { return m_fullname.c_str(); } }; class VerilatedVpioParam final : public VerilatedVpioVarBase { @@ -646,23 +645,22 @@ public: continue; } VerilatedVpiCbHolder& ho = *it++; - if (VerilatedVpioVar* const varop = VerilatedVpioVar::castp(ho.cb_datap()->obj)) { - void* const newDatap = varop->varDatap(); - void* const prevDatap - = varop->prevDatap(); // Was malloced when we added the callback - VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_test %s v[0]=%d/%d %p %p\n", - varop->fullname(), *(static_cast(newDatap)), - *(static_cast(prevDatap)), newDatap, - prevDatap);); - if (std::memcmp(prevDatap, newDatap, varop->entSize()) != 0) { - VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_callback %" PRId64 " %s v[0]=%d\n", - ho.id(), varop->fullname(), - *(static_cast(newDatap)));); - update.insert(varop); - vpi_get_value(ho.cb_datap()->obj, ho.cb_datap()->value); - (ho.cb_rtnp())(ho.cb_datap()); - called = true; - } + VerilatedVpioVar* const varop = reinterpret_cast(ho.cb_datap()->obj); + void* const newDatap = varop->varDatap(); + void* const prevDatap + = varop->prevDatap(); // Was malloced when we added the callback + VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_test %s v[0]=%d/%d %p %p\n", + varop->fullname(), *(static_cast(newDatap)), + *(static_cast(prevDatap)), newDatap, + prevDatap);); + if (std::memcmp(prevDatap, newDatap, varop->entSize()) != 0) { + VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_callback %" PRId64 " %s v[0]=%d\n", + ho.id(), varop->fullname(), + *(static_cast(newDatap)));); + update.insert(varop); + vpi_get_value(ho.cb_datap()->obj, ho.cb_datap()->value); + (ho.cb_rtnp())(ho.cb_datap()); + called = true; } if (was_last) break; }