From 74fe41143be5f76142d84af0a4a58604e1ff9207 Mon Sep 17 00:00:00 2001 From: Diego Roux Date: Mon, 30 Sep 2024 14:29:00 -0600 Subject: [PATCH] vpi_get_value_array: fix vpiRawTwoStateVal's WDATA return. WDATA only worked if the bit length was a multiple of 32. Signed-off-by: Diego Roux --- include/verilated_vpi.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 0a0c78147..451986c39 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -2993,8 +2993,7 @@ void vl_get_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, case VLVT_UINT64: ngroups = 8; break; case VLVT_WDATA: { - int elemBits = varp->packed().elements(); - ngroups = (elemBits + 7) / 8; break; + ngroups = VL_WORDS_I(varp->packed().elements()) * sizeof(WData); break; } default: ngroups = 0; break; @@ -3036,13 +3035,17 @@ void vl_get_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, index = index % size; } } else if (varp->vltype() == VLVT_WDATA) { - CData *ptr = reinterpret_cast(vop->varDatap()); + WData *rawvals = reinterpret_cast(value_ptr); + WData *ptr = reinterpret_cast(vop->varDatap()); - int elemBits = varp->packed().elements(); - int ngroups = (elemBits + 7) / 8; + const int words = VL_WORDS_I(varp->packed().elements()); for (int i = 0; i < num; i++) { - std::memcpy(&value_ptr[i * ngroups], &ptr[index++ * ngroups], ngroups); + for (int j = 0; j < words; j++) { + rawvals[i * words + j] = ptr[index * words + j]; + } + + index = ++index % size; } }