From 0dad9e3adb58838d1fa4d3b8a4e0d1cbecef4f8a Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 21 Sep 2010 17:41:06 -0700 Subject: [PATCH] Update fstapi.c to the latest from GTKWave-3.3.12 --- vpi/fstapi.c | 66 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/vpi/fstapi.c b/vpi/fstapi.c index bbb32e737..59211b772 100644 --- a/vpi/fstapi.c +++ b/vpi/fstapi.c @@ -42,6 +42,10 @@ #define FST_MACOSX #endif +#if defined(__CYGWIN__) && defined(__GNUC__) +#define FST_USE_FWRITE_COMBINING +#endif + /***********************/ /*** ***/ @@ -375,7 +379,7 @@ return(rc); static int fstWriterVarint(FILE *handle, uint64_t v) { uint64_t nxt; -unsigned char buf[32]; +unsigned char buf[10]; /* ceil(64/7) = 10 */ unsigned char *pnt = buf; int len; @@ -391,6 +395,50 @@ fstFwrite(buf, len, 1, handle); return(len); } +#ifndef FST_USE_FWRITE_COMBINING +static int fstWriterUint32WithVarint(FILE *handle, uint32_t *u, uint64_t v) +{ +uint64_t nxt; +unsigned char buf[10 + sizeof(uint32_t)]; +unsigned char *pnt = buf + sizeof(uint32_t); +int len; + +memcpy(buf, u, sizeof(uint32_t)); + +while((nxt = v>>7)) + { + *(pnt++) = (v&0x7f) | 0x80; + v = nxt; + } +*(pnt++) = (v&0x7f); + +len = pnt-buf; +fstFwrite(buf, len, 1, handle); +return(len); +} +#else +static int fstWriterUint32WithVarint(FILE *handle, uint32_t *u, uint64_t v, const void *dbuf, size_t siz) +{ +uint64_t nxt; +unsigned char buf[10 + sizeof(uint32_t) + siz]; /* gcc extension ok for cygwin */ +unsigned char *pnt = buf + sizeof(uint32_t); +int len; + +memcpy(buf, u, sizeof(uint32_t)); + +while((nxt = v>>7)) + { + *(pnt++) = (v&0x7f) | 0x80; + v = nxt; + } +*(pnt++) = (v&0x7f); +memcpy(pnt, dbuf, siz); + +len = pnt-buf + siz; +fstFwrite(buf, len, 1, handle); +return(len); +} +#endif /***********************/ /*** ***/ @@ -1555,7 +1603,6 @@ size_t len; if((xc) && (handle <= xc->maxhandle)) { - uint32_t prev_chg; uint32_t fpos; uint32_t *vm4ip; @@ -1573,14 +1620,15 @@ if((xc) && (handle <= xc->maxhandle)) if(!xc->is_initial_time) { - prev_chg = vm4ip[2]; fpos = xc->vchn_siz; - - fstFwrite(&prev_chg, 1, sizeof(uint32_t), xc->vchn_handle); - xc->vchn_siz += 4; - xc->vchn_siz += fstWriterVarint(xc->vchn_handle, xc->tchn_idx - vm4ip[3]); - fstFwrite(buf, len, 1, xc->vchn_handle); - xc->vchn_siz += len; + /* cygwin runs faster if these writes are combined, so the new fstWriterUint32WithVarint function, but should help with regular */ +#ifndef FST_USE_FWRITE_COMBINING + xc->vchn_siz += fstWriterUint32WithVarint(xc->vchn_handle, &vm4ip[2], xc->tchn_idx - vm4ip[3]); /* prev_chg is vm4ip[2] */ + fstFwrite(buf, len, 1, xc->vchn_handle); + xc->vchn_siz += len; +#else + xc->vchn_siz += fstWriterUint32WithVarint(xc->vchn_handle, &vm4ip[2], xc->tchn_idx - vm4ip[3], buf, len); /* do one fwrite op only */ +#endif vm4ip[3] = xc->tchn_idx; vm4ip[2] = fpos; }