Fix word size to match uint64_t on -m64 systems, bug238.

This commit is contained in:
Wilson Snyder 2010-04-09 21:51:15 -04:00
parent c807bf1e0e
commit ef51de72c9
6 changed files with 29 additions and 11 deletions

View File

@ -9,6 +9,8 @@ indicates the contributor was also the author of the fix; Thanks!
*** Add /*verilator public_flat_rw*/ for timing-specific public access.
*** Fix word size to match uint64_t on -m64 systems, bug238. [Joe Eiler]
**** Improve error handling on slices of arrays, bug226. [by Bryon Bradley]
**** Report errors when extra underscores used in meta-comments.

View File

@ -234,7 +234,7 @@ void VerilatedVcd::printStr (const char* str) {
void VerilatedVcd::printQuad (vluint64_t n) {
char buf [100];
sprintf(buf,"%" VL_PRI64 "u",(long long unsigned)n);
sprintf(buf,"%" VL_PRI64 "u", n);
printStr(buf);
}

View File

@ -126,8 +126,13 @@ typedef unsigned long uint32_t; ///< 32-bit unsigned type (backward compatibili
typedef long vlsint32_t; ///< 32-bit signed type
typedef unsigned long vluint32_t; ///< 32-bit unsigned type
# endif
# if defined(__WORDSIZE) && (__WORDSIZE == 64)
typedef long vlsint64_t; ///< 64-bit signed type
typedef unsigned long vluint64_t; ///< 64-bit unsigned type
# else
typedef long long vlsint64_t; ///< 64-bit signed type
typedef unsigned long long vluint64_t; ///< 64-bit unsigned type
# endif
#elif defined(_WIN32) && defined(_MSC_VER)
@ -149,9 +154,14 @@ typedef uint8_t vluint8_t; ///< 32-bit unsigned type
typedef uint16_t vluint16_t; ///< 32-bit unsigned type
typedef int vlsint32_t; ///< 32-bit signed type
typedef uint32_t vluint32_t; ///< 32-bit signed type
# if defined(__WORDSIZE) && (__WORDSIZE == 64)
typedef long vlsint64_t; ///< 64-bit signed type
typedef unsigned long vluint64_t; ///< 64-bit unsigned type
# else
typedef long long vlsint64_t; ///< 64-bit signed type
typedef unsigned long long vluint64_t; ///< 64-bit unsigned type
# endif
#endif
//=========================================================================
// Printing printf/scanf formats
@ -160,8 +170,12 @@ typedef unsigned long long vluint64_t; ///< 64-bit unsigned type
#ifdef _WIN32
# define VL_PRI64 "I64"
#else // Linux or compliant Unix flavors
# if defined(__WORDSIZE) && (__WORDSIZE == 64)
# define VL_PRI64 "l"
# else
# define VL_PRI64 "ll"
# endif
#endif
//=========================================================================
// Integer size macros

View File

@ -126,6 +126,7 @@ sub prep {
#
$wholefile =~ s/\b(uint[0-9]+_t)/vl$1/g;
$wholefile =~ s/%ll/%" VL_PRI64 "/g;
$wholefile =~ s/\(long long unsigned\)n/ n/g; # printQuad
#
$wholefile =~ s/\bSP_SC_BV/VL_SC_BV/g;
$wholefile =~ s/\bSP_UNLIKELY/VL_UNLIKELY/g;

View File

@ -543,17 +543,18 @@ public:
}
for (int word=VL_WORDS_I(nodep->num().minWidth())-1; word>0; word--) {
// Only 32 bits - llx + long long here just to appease CPP format warning
ofp()->printf(",0x%08" VL_PRI64 "x", (long long)(nodep->num().dataWord(word)));
ofp()->printf(",0x%08" VL_PRI64 "x", (vluint64_t)(nodep->num().dataWord(word)));
}
ofp()->printf(",0x%08" VL_PRI64 "x)", (long long)(nodep->num().dataWord(0)));
ofp()->printf(",0x%08" VL_PRI64 "x)", (vluint64_t)(nodep->num().dataWord(0)));
} else if (nodep->isQuad()) {
vluint64_t num = nodep->toUQuad();
if (num<10) ofp()->printf("VL_ULL(%" VL_PRI64 "d)", (long long)num);
else ofp()->printf("VL_ULL(0x%" VL_PRI64 "x)", (long long)num);
if (num<10) ofp()->printf("VL_ULL(%" VL_PRI64 "d)", num);
else ofp()->printf("VL_ULL(0x%" VL_PRI64 "x)", num);
} else {
uint32_t num = nodep->toUInt();
// Only 32 bits - llx + long long here just to appease CPP format warning
if (num<10) puts(cvtToStr(num));
else ofp()->printf("0x%" VL_PRI64 "x", (long long)num);
else ofp()->printf("0x%" VL_PRI64 "x", (vluint64_t)num);
//Unneeded-Causes %lx format warnings:
// if (!nodep->num().isSigned() && (num & (1UL<<31))) puts("U");
}

View File

@ -28,7 +28,7 @@ long long get_memory_usage() {
if (!fp) return 0;
int ps_ign;
long long ps_vsize, ps_rss;
vluint64_t ps_vsize, ps_rss;
int items = fscanf(fp, ("%d (%*[^) ]) %*1s %d %*d %*d %*d %*d %u"
" %u %u %u %u %d %d %d %d"
" %*d %*d %*u %*u %d %" VL_PRI64 "u %" VL_PRI64 "u "),
@ -61,7 +61,7 @@ void make_and_destroy () {
}
int main (int argc, char *argv[]) {
long long firstUsage = get_memory_usage();
vluint64_t firstUsage = get_memory_usage();
// Warmup phase
for (int i=0; i<1000; i++) {
@ -77,7 +77,7 @@ int main (int argc, char *argv[]) {
}
}
long long leaked = get_memory_usage() - firstUsage;
vluint64_t leaked = get_memory_usage() - firstUsage;
if (leaked > 64*1024) { // Have to allow some slop for this code.
printf ("Leaked %" VL_PRI64 "d bytes, or ~ %" VL_PRI64 "d bytes/construt\n", leaked, leaked/loops);
vl_fatal(__FILE__,__LINE__,"top", "Leaked memory\n");