From 51af6ed41355ba1e56550c90a9ef5f8bb4502b12 Mon Sep 17 00:00:00 2001 From: Mateusz Gancarz Date: Mon, 10 Feb 2025 15:01:00 +0100 Subject: [PATCH] [#72179] fix implementation of emitting words --- include/verilated_saif_c.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/include/verilated_saif_c.cpp b/include/verilated_saif_c.cpp index 9e20ebc25..ca77eace2 100644 --- a/include/verilated_saif_c.cpp +++ b/include/verilated_saif_c.cpp @@ -563,25 +563,32 @@ void VerilatedSaifBuffer::emitQData(uint32_t code, QData newval, int bits) { VL_ATTR_ALWINLINE void VerilatedSaifBuffer::emitWData(uint32_t code, const WData* newvalp, int bits) { - const int bitsInMSW = VL_BITBIT_E(bits) ? VL_BITBIT_E(bits) : VL_EDATASIZE; auto& activity = m_owner.m_activity[m_owner.m_codeToActivity[code]]; - fprintf(stdout, "Emitting wide - name: %s, code: %d, bits: %d, activity.width: %d\n", activity.name, code, bits, activity.width); + fprintf(stdout, "Emitting words - name: %s, code: %d, bits: %d, activity.width: %d\n", activity.name, code, bits, activity.width); if (bits > activity.width) { fprintf(stdout, "Trying to emit more bits than activity width\n"); } + const int bitsInMSW = VL_BITBIT_E(bits) ? VL_BITBIT_E(bits) : VL_EDATASIZE; + int numOfWords = VL_WORDS_I(bits); + + fprintf(stdout, "Number of bits in most significant word: %d\n", bitsInMSW); + fprintf(stdout, "Number of bits in a word: %d\n", VL_EDATASIZE); + fprintf(stdout, "Number of words: %d\n", numOfWords); + auto dt = m_owner.m_time - activity.lastTime; - //NOTE: is (i = bitsInMSW; i < bitsInMSW) intentional - for (size_t i = bitsInMSW; i < bitsInMSW; i++) { + for (std::size_t i = 0; i < bitsInMSW; ++i) { activity.bits[i].aggregateVal(dt, (newvalp[0] >> VL_BITBIT_E(i)) & 1); } - for (size_t i = bitsInMSW; i < activity.width; i++) { - size_t j = VL_WORDS_I(i); - activity.bits[i].aggregateVal(dt, (newvalp[j] >> VL_BITBIT_E(i)) & 1); + + for (std::size_t i = bitsInMSW; i < activity.width; ++i) { + size_t wordIndex = VL_WORDS_I(i); + activity.bits[i].aggregateVal(dt, (newvalp[wordIndex] >> VL_BITBIT_E(i)) & 1); } + activity.lastTime = m_owner.m_time; }