Remove dead code related to bit arrays/vectors

In previous incarnations of the vvp runtime, bit vectors were passed
around as arrays of unsigned char that charried bit4 vectors. That
is no longer used. Remove the last vestiges of that dead code.
This commit is contained in:
Stephen Williams 2008-04-20 20:43:53 -07:00
parent 40fd07d46e
commit 6d2ef15951
5 changed files with 11 additions and 203 deletions

View File

@ -503,14 +503,9 @@ extern const char* vpip_name_string(const char*str);
/*
* This function is used to make decimal string versions of various
* vectors. The input format is an array of bit values (0, 1, 2, 3)
* lsb first, and the result is written into buf, without overflowing
* nbuf.
* vectors. The input format is a vvp_vector4_t, and the result is
* written into buf, without overflowing nbuf.
*/
extern unsigned vpip_bits_to_dec_str(const unsigned char *bits,
unsigned int nbits,
char *buf, unsigned int nbuf,
int signed_flag);
extern unsigned vpip_vec4_to_dec_str(const vvp_vector4_t&vec4,
char *buf, unsigned int nbuf,
int signed_flag);
@ -521,8 +516,6 @@ extern void vpip_bin_str_to_vec4(vvp_vector4_t&val,
extern void vpip_vec4_to_hex_str(const vvp_vector4_t&bits, char*buf,
unsigned nbuf, bool signed_flag);
extern void vpip_bits_to_oct_str(const unsigned char*bits, unsigned nbits,
char*buf, unsigned nbuf, bool signed_flag);
extern void vpip_vec4_to_oct_str(const vvp_vector4_t&bits, char*buf,
unsigned nbuf, bool signed_flag);

View File

@ -239,39 +239,13 @@ static vpiHandle signal_iterate(int code, vpiHandle ref)
static char *signal_vpiDecStrVal(struct __vpiSignal*rfp, s_vpi_value*vp)
{
unsigned wid = (rfp->msb >= rfp->lsb)
? (rfp->msb - rfp->lsb + 1)
: (rfp->lsb - rfp->msb + 1);
vvp_fun_signal_vec*vsig = dynamic_cast<vvp_fun_signal_vec*>(rfp->node->fun);
assert(vsig);
/* FIXME: bits should be an array of vvp_bit4_t. */
unsigned char* bits = new unsigned char[wid];
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
switch (vsig->value(idx)) {
case BIT4_0:
bits[idx] = 0;
break;
case BIT4_1:
bits[idx] = 1;
break;
case BIT4_Z:
bits[idx] = 3;
break;
case BIT4_X:
bits[idx] = 2;
break;
}
}
unsigned hwid = (wid+2) / 3 + 1;
unsigned hwid = (vsig->size()+2) / 3 + 1;
char *rbuf = need_result_buf(hwid, RBUF_VAL);
vpip_bits_to_dec_str(bits, wid, rbuf, hwid, rfp->signed_flag);
delete[]bits;
vpip_vec4_to_dec_str(vsig->vec4_value(), rbuf, hwid, rfp->signed_flag);
return rbuf;
}

View File

@ -41,7 +41,7 @@ struct __vpiVThrVec {
};
inline static
unsigned get_bit(struct __vpiVThrVec *rfp, unsigned idx)
vvp_bit4_t get_bit(struct __vpiVThrVec *rfp, unsigned idx)
{
return vthread_get_bit(vpip_current_vthread, rfp->bas+idx);
}
@ -111,26 +111,14 @@ static char* vthr_vec_get_str(int code, vpiHandle ref)
static void vthr_vec_DecStrVal(struct __vpiVThrVec*rfp, s_vpi_value*vp)
{
unsigned char*bits = new unsigned char[rfp->wid];
char *rbuf = need_result_buf((rfp->wid+2)/3 + 1, RBUF_VAL);
int nbuf = (rfp->wid+2)/3 + 1;
char *rbuf = need_result_buf(nbuf, RBUF_VAL);
vvp_vector4_t tmp (rfp->wid);
for (unsigned idx = 0 ; idx < rfp->wid ; idx += 1)
switch (get_bit(rfp, idx)) {
case BIT4_0:
bits[idx] = 0;
break;
case BIT4_1:
bits[idx] = 1;
break;
case BIT4_X:
bits[idx] = 2;
break;
case BIT4_Z:
bits[idx] = 3;
break;
}
tmp.set_bit(idx, get_bit(rfp, idx));
vpip_bits_to_dec_str(bits, rfp->wid, rbuf, rfp->wid+1, rfp->signed_flag);
vpip_vec4_to_dec_str(tmp, rbuf, nbuf, rfp->signed_flag);
vp->value.str = rbuf;
return;

View File

@ -88,37 +88,6 @@ void vpip_oct_str_to_vec4(vvp_vector4_t&val, const char*str)
}
}
void vpip_bits_to_oct_str(const unsigned char*bits, unsigned nbits,
char*buf, unsigned nbuf, bool signed_flag)
{
unsigned slen = (nbits + 2) / 3;
unsigned val = 0;
assert(slen < nbuf);
buf[slen] = 0;
for (unsigned idx = 0 ; idx < nbits ; idx += 1) {
unsigned bi = idx/4;
unsigned bs = (idx%4) * 2;
unsigned bit = (bits[bi] >> bs) & 3;
unsigned vs = (idx%3) * 2;
val |= bit << vs;
if (vs == 4) {
slen -= 1;
buf[slen] = oct_digits[val];
val = 0;
}
}
if (slen > 0) {
slen -= 1;
buf[slen] = oct_digits[val];
}
}
void vpip_vec4_to_oct_str(const vvp_vector4_t&bits, char*buf, unsigned nbuf,
bool signed_flag)
{

View File

@ -1,4 +1,5 @@
/*
* Copyright (c) 2008 Stephen Williams <steve@icarus.com>
* Copyright (c) 2002 Larry Doolittle (larry@doolittle.boa.org)
*
* This source code is free software; you can redistribute it
@ -16,9 +17,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpip_to_dec.cc,v 1.8 2006/02/21 02:39:27 steve Exp $"
#endif
# include "config.h"
# include "vpi_priv.h"
@ -222,100 +220,6 @@ unsigned vpip_vec4_to_dec_str(const vvp_vector4_t&vec4,
return 0;
}
unsigned vpip_bits_to_dec_str(const unsigned char *bits, unsigned int nbits,
char *buf, unsigned int nbuf, int signed_flag)
{
unsigned int idx, len, vlen;
unsigned int mbits=nbits; /* number of non-sign bits */
unsigned count_x = 0, count_z = 0;
/* Jump through some hoops so we don't have to malloc/free valv
* on every call, and implement an optional malloc-less version. */
static unsigned long *valv=NULL;
static unsigned int vlen_alloc=0;
unsigned long val=0;
int comp=0;
if (signed_flag) {
if (B_ISZ(bits[nbits-1])) count_z++;
else if (B_ISX(bits[nbits-1])) count_x++;
else if (B_IS1(bits[nbits-1])) comp=1;
--mbits;
}
assert(mbits<(UINT_MAX-92)/28);
vlen = ((mbits*28+92)/93+BDIGITS-1)/BDIGITS;
/* printf("vlen=%d\n",vlen); */
#define ALLOC_MARGIN 4
if (!valv || vlen > vlen_alloc) {
if (valv) free(valv);
valv = (unsigned long*)
calloc( vlen+ALLOC_MARGIN, sizeof (*valv));
if (!valv) {perror("malloc"); return 0; }
vlen_alloc=vlen+ALLOC_MARGIN;
} else {
memset(valv,0,vlen*sizeof(valv[0]));
}
for (idx = 0; idx < mbits; idx += 1) {
/* printf("%c ",bits[mbits-idx-1]); */
if (B_ISZ(bits[mbits-idx-1])) count_z++;
else if (B_ISX(bits[mbits-idx-1])) count_x++;
else if (!comp && B_IS1(bits[mbits-idx-1])) ++val;
else if ( comp && B_IS0(bits[mbits-idx-1])) ++val;
if ((mbits-idx-1)%BBITS==0) {
/* make negative 2's complement, not 1's complement */
if (comp && idx==mbits-1) ++val;
shift_in(valv,vlen,val);
val=0;
} else {
val=val+val;
}
}
if (count_x == nbits) {
len = 1;
buf[0] = 'x';
buf[1] = 0;
} else if (count_x > 0) {
len = 1;
buf[0] = 'X';
buf[1] = 0;
} else if (count_z == nbits) {
len = 1;
buf[0] = 'z';
buf[1] = 0;
} else if (count_z > 0) {
len = 1;
buf[0] = 'Z';
buf[1] = 0;
} else {
int i;
int zero_suppress=1;
if (comp) {
*buf++='-';
nbuf--;
/* printf("-"); */
}
for (i=vlen-1; i>=0; i--) {
zero_suppress = write_digits(valv[i],
&buf,&nbuf,zero_suppress);
/* printf(",%.4u",valv[i]); */
}
/* Awkward special case, since we don't want to
* zero suppress down to nothing at all. The only
* way we can still have zero_suppress on in the
* comp=1 case is if mbits==0, and therefore vlen==0.
* We represent 1'sb1 as "-1". */
if (zero_suppress) *buf++='0'+comp;
/* printf("\n"); */
*buf='\0';
}
/* hold on to the memory, since we expect to be called again. */
/* free(valv); */
return 0;
}
void vpip_dec_str_to_vec4(vvp_vector4_t&vec,
const char*buf, bool signed_flag)
{
@ -364,23 +268,3 @@ void vpip_dec_str_to_vec4(vvp_vector4_t&vec,
delete[]str;
}
/*
* $Log: vpip_to_dec.cc,v $
* Revision 1.8 2006/02/21 02:39:27 steve
* Support string values for memory words.
*
* Revision 1.7 2004/10/04 01:11:00 steve
* Clean up spurious trailing white space.
*
* Revision 1.6 2002/08/12 01:35:09 steve
* conditional ident string using autoconfig.
*
* Revision 1.5 2002/05/17 04:05:38 steve
* null terminate the reversed decimal string
*
* Revision 1.4 2002/05/11 04:39:36 steve
* Set and get memory words by string value.
*
*/