Fix VerilatedVarProps::totalSize missing the first unpacked dim (#2296)

This commit is contained in:
John Demme 2020-05-01 04:42:29 -07:00 committed by GitHub
parent 5ded80cf79
commit 6e9008fb5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 4 deletions

View File

@ -17,6 +17,7 @@ Iztok Jeras
James Hanlon
Jeremy Bennett
John Coiner
John Demme
Julien Margetts
Kanad Kanhere
Kevin Kiningham

View File

@ -2444,7 +2444,7 @@ vluint32_t VerilatedVarProps::entSize() const {
size_t VerilatedVarProps::totalSize() const {
size_t size = entSize();
for (int dim = 1; dim <= dims(); ++dim) size *= m_unpacked[dim].elements();
for (int dim = 0; dim <= dims(); ++dim) size *= m_unpacked[dim].elements();
return size;
}

View File

@ -22,6 +22,8 @@
# include "../vc_hdrs.h"
#elif defined(NC)
# define NEED_EXTERNS
// #elif defined(MS)
// # define NEED_EXTERNS
#else
# error "Unknown simulator for DPI test"
#endif
@ -94,6 +96,15 @@ int dpii_failure() { return failure; }
} \
} while (0)
#define CHECK_RESULT_HEX_NE(got, exp) \
do { \
if ((got) == (exp)) { \
std::cout << std::dec << "%Error: " << __FILE__ << ":" << __LINE__ << std::hex \
<< ": GOT=" << (got) << " EXP!=" << (exp) << std::endl; \
failure = __LINE__; \
} \
} while (0)
void dpii_unused(const svOpenArrayHandle u) {}
void _dpii_all(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
@ -102,8 +113,10 @@ void _dpii_all(int c, int p, int u, const svOpenArrayHandle i, const svOpenArray
__FILE__, __LINE__, c, p, u, svGetArrayPtr(i));
#endif
(void)svGetArrayPtr(i);
#ifndef NC
// NC always returns zero and warns
//(void)svSizeOfArray(i);
(void)svSizeOfArray(i);
#endif
#ifndef VCS // VCS does not support dimension 0 query
if (p) {
int d = 0;
@ -222,8 +235,29 @@ void dpii_open_pw_u3(int c, int p, int u, const svOpenArrayHandle i, const svOpe
}
void dpii_open_bit(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
void dpii_open_byte(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
void dpii_open_int(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
void dpii_open_byte(const svOpenArrayHandle i, const svOpenArrayHandle o) {
intptr_t arrPtr = (intptr_t)svGetArrayPtr(i);
CHECK_RESULT_HEX_NE(arrPtr, 0); // All the arrays should actually exist
#ifndef NC
// NC always returns zero and warns
int sizeInputOfArray = svSizeOfArray(i);
CHECK_RESULT_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size
CHECK_RESULT_HEX_NE(svDimensions(i), 0); // All the test cases are unpacked arrays
#endif
}
void dpii_open_int(const svOpenArrayHandle i, const svOpenArrayHandle o) {
intptr_t arrPtr = (intptr_t)svGetArrayPtr(i);
CHECK_RESULT_HEX_NE(arrPtr, 0); // All the arrays should actually exist
#ifndef NC
// NC always returns zero and warns
int sizeInputOfArray = svSizeOfArray(i);
CHECK_RESULT_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size
CHECK_RESULT_HEX_NE(svDimensions(i), 0); // All the test cases are unpacked arrays
#endif
}
void dpii_open_integer(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
void dpii_open_logic(const svOpenArrayHandle i, const svOpenArrayHandle o) {}