diff --git a/vvp/vpi_memory.cc b/vvp/vpi_memory.cc index ba122c6b0..ff0fc0550 100644 --- a/vvp/vpi_memory.cc +++ b/vvp/vpi_memory.cc @@ -28,7 +28,7 @@ * Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704. */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpi_memory.cc,v 1.25 2005/03/05 05:43:03 steve Exp $" +#ident "$Id: vpi_memory.cc,v 1.26 2005/06/13 00:54:04 steve Exp $" #endif # include "vpi_priv.h" @@ -404,7 +404,7 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp) switch (vp->format) { default: - assert("format not implemented"); + assert(0 && "format not implemented"); case vpiBinStrVal: rbuf = need_result_buf(width+1, RBUF_VAL); @@ -415,71 +415,25 @@ static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp) rbuf[width] = 0; vp->value.str = rbuf; break; -#if 0 - /* XXXX Needs to be converted. */ + case vpiOctStrVal: { unsigned hwid = (width+2) / 3; - unsigned char*bits = new unsigned char[width]; - - for (unsigned idx = 0 ; idx < width ; idx += 1) { - unsigned bb = idx / 4; - unsigned bs = (idx % 4) * 2; - unsigned val = memory_get(rfp->mem->mem, bidx+idx); - if (bs == 0) - bits[bb] = val; - else - bits[bb] |= val << bs; - } - rbuf = need_result_buf(hwid+1, RBUF_VAL); - vpip_bits_to_oct_str(bits, width, rbuf, hwid+1, false); - - delete[]bits; + vpip_vec4_to_oct_str(word_val, rbuf, hwid+1, false); vp->value.str = rbuf; break; } -#endif -#if 0 - /* XXXX Needs to be converted. */ + case vpiHexStrVal: { - unsigned hval, hwid; - hwid = (width + 3) / 4; + unsigned hwid = (width + 3) / 4; rbuf = need_result_buf(hwid+1, RBUF_VAL); rbuf[hwid] = 0; - hval = 0; - for (unsigned idx = 0 ; idx < width ; idx += 1) { - unsigned bit = memory_get(rfp->mem->mem, bidx+idx); - hval = hval | (bit << 2*(idx % 4)); - - if (idx%4 == 3) { - hwid -= 1; - rbuf[hwid] = hex_digits[hval]; - hval = 0; - } - } - - if (hwid > 0) { - unsigned padd = 0; - - hwid -= 1; - rbuf[hwid] = hex_digits[hval]; - switch(rbuf[hwid]) { - case 'X': padd = 2; break; - case 'Z': padd = 3; break; - } - if (padd) { - for (unsigned idx = width % 4; idx < 4; idx += 1) { - hval = hval | padd << 2*idx; - } - rbuf[hwid] = hex_digits[hval]; - } - } + vpip_vec4_to_hex_str(word_val, rbuf, hwid+1, false); vp->value.str = rbuf; break; } -#endif #if 0 case vpiDecStrVal: { unsigned char*bits = new unsigned char[width]; @@ -614,6 +568,9 @@ vpiHandle vpip_make_memory(vvp_memory_t mem, const char*name) /* * $Log: vpi_memory.cc,v $ + * Revision 1.26 2005/06/13 00:54:04 steve + * More unified vec4 to hex string functions. + * * Revision 1.25 2005/03/05 05:43:03 steve * Get base address from word ranges that VPI user passed. * diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 5ddc46aec..2270654d9 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpi_priv.h,v 1.62 2005/04/28 04:59:53 steve Exp $" +#ident "$Id: vpi_priv.h,v 1.63 2005/06/13 00:54:04 steve Exp $" #endif # include "vpi_user.h" @@ -395,11 +395,15 @@ extern void vpip_dec_str_to_bits(unsigned char*bits, unsigned nbits, extern void vpip_bin_str_to_bits(unsigned char*bits, unsigned nbits, const char*buf, bool signed_flag); +extern void vpip_vec4_to_hex_str(const vvp_vector4_t&bits, char*buf, + unsigned nbuf, bool signed_flag); extern void vpip_hex_str_to_bits(unsigned char*bits, unsigned nbits, const char*buf, 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); extern void vpip_oct_str_to_bits(unsigned char*bits, unsigned nbits, const char*buf, bool signed_flag); @@ -418,6 +422,9 @@ extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type); /* * $Log: vpi_priv.h,v $ + * Revision 1.63 2005/06/13 00:54:04 steve + * More unified vec4 to hex string functions. + * * Revision 1.62 2005/04/28 04:59:53 steve * Remove dead functor code. * diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index fc705e2a9..37c731d15 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpi_signal.cc,v 1.67 2005/06/12 01:10:26 steve Exp $" +#ident "$Id: vpi_signal.cc,v 1.68 2005/06/13 00:54:04 steve Exp $" #endif /* @@ -380,37 +380,12 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp) break; case vpiHexStrVal: { - unsigned hval, hwid; - hwid = (wid + 3) / 4; + unsigned hwid = (wid + 3) / 4; rbuf = need_result_buf(hwid+1, RBUF_VAL); rbuf[hwid] = 0; - hval = 0; - for (unsigned idx = 0 ; idx < wid ; idx += 1) { - hval = hval | (vsig->value(idx) << 2*(idx % 4)); - if (idx%4 == 3) { - hwid -= 1; - rbuf[hwid] = hex_digits[hval]; - hval = 0; - } - } - - if (hwid > 0) { - hwid -= 1; - rbuf[hwid] = hex_digits[hval]; - unsigned padd = 0; - switch(rbuf[hwid]) { - case 'X': padd = 2; break; - case 'Z': padd = 3; break; - } - if (padd) { - for (unsigned idx = wid % 4; idx < 4; idx += 1) { - hval = hval | padd << 2*idx; - } - rbuf[hwid] = hex_digits[hval]; - } - } + vpip_vec4_to_hex_str(vsig->vec4_value(), rbuf, hwid+1, false); vp->value.str = rbuf; break; } @@ -847,6 +822,9 @@ vpiHandle vpip_make_net(const char*name, int msb, int lsb, /* * $Log: vpi_signal.cc,v $ + * Revision 1.68 2005/06/13 00:54:04 steve + * More unified vec4 to hex string functions. + * * Revision 1.67 2005/06/12 01:10:26 steve * Remove useless references to functor.h * diff --git a/vvp/vpip_hex.cc b/vvp/vpip_hex.cc index 0e2197b05..a4d9d2e4f 100644 --- a/vvp/vpip_hex.cc +++ b/vvp/vpip_hex.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpip_hex.cc,v 1.2 2002/08/12 01:35:09 steve Exp $" +#ident "$Id: vpip_hex.cc,v 1.3 2005/06/13 00:54:04 steve Exp $" #endif # include "config.h" @@ -31,6 +31,58 @@ #endif # include +extern const char hex_digits[256]; + +void vpip_vec4_to_hex_str(const vvp_vector4_t&bits, char*buf, + unsigned nbuf, bool signed_flag) +{ + unsigned slen = (bits.size() + 3) / 4; + assert(slen < nbuf); + + buf[slen] = 0; + + unsigned val = 0; + for (unsigned idx = 0 ; idx < bits.size() ; idx += 1) { + unsigned vs = (idx%4) * 2; + + switch (bits.value(idx)) { + case BIT4_0: + break; + case BIT4_1: + val |= 1 << vs; + break; + case BIT4_X: + val |= 2 << vs; + break; + case BIT4_Z: + val |= 3 << vs; + } + + if (vs == 6) { + slen -= 1; + buf[slen] = hex_digits[val]; + val = 0; + } + } + + if (slen > 0) { + unsigned padd = 0; + + slen -= 1; + buf[slen] = hex_digits[val]; + switch(buf[slen]) { + case 'X': padd = 2; break; + case 'Z': padd = 3; break; + } + if (padd) { + for (unsigned idx = bits.size() % 4; idx < 4; idx += 1) { + val = val | padd << 2*idx; + } + buf[slen] = hex_digits[val]; + } + } +} + void vpip_hex_str_to_bits(unsigned char*bits, unsigned nbits, const char*buf, bool signed_flag) { @@ -111,6 +163,9 @@ void vpip_hex_str_to_bits(unsigned char*bits, unsigned nbits, /* * $Log: vpip_hex.cc,v $ + * Revision 1.3 2005/06/13 00:54:04 steve + * More unified vec4 to hex string functions. + * * Revision 1.2 2002/08/12 01:35:09 steve * conditional ident string using autoconfig. * diff --git a/vvp/vpip_oct.cc b/vvp/vpip_oct.cc index e65ceed17..7948bbb3a 100644 --- a/vvp/vpip_oct.cc +++ b/vvp/vpip_oct.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vpip_oct.cc,v 1.2 2002/08/12 01:35:09 steve Exp $" +#ident "$Id: vpip_oct.cc,v 1.3 2005/06/13 00:54:04 steve Exp $" #endif # include "config.h" @@ -169,8 +169,49 @@ void vpip_bits_to_oct_str(const unsigned char*bits, unsigned nbits, } } +void vpip_vec4_to_oct_str(const vvp_vector4_t&bits, char*buf, unsigned nbuf, + bool signed_flag) +{ + unsigned slen = (bits.size() + 2) / 3; + assert(slen < nbuf); + + buf[slen] = 0; + + unsigned val = 0; + for (unsigned idx = 0 ; idx < bits.size() ; idx += 1) { + unsigned vs = (idx%3) * 2; + + switch (bits.value(idx)) { + case BIT4_0: + break; + case BIT4_1: + val |= 1 << vs; + break; + case BIT4_X: + val |= 2 << vs; + break; + case BIT4_Z: + val |= 3 << vs; + } + + if (vs == 4) { + slen -= 1; + buf[slen] = oct_digits[val]; + val = 0; + } + } + + if (slen > 0) { + slen -= 1; + buf[slen] = oct_digits[val]; + } +} + /* * $Log: vpip_oct.cc,v $ + * Revision 1.3 2005/06/13 00:54:04 steve + * More unified vec4 to hex string functions. + * * Revision 1.2 2002/08/12 01:35:09 steve * conditional ident string using autoconfig. * diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index eb6b907b1..68108a9ec 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#ident "$Id: vvp_net.cc,v 1.30 2005/06/12 15:13:37 steve Exp $" +#ident "$Id: vvp_net.cc,v 1.31 2005/06/13 00:54:04 steve Exp $" # include "config.h" # include "vvp_net.h" @@ -384,6 +384,20 @@ bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val) return true; } +vvp_vector4_t coerce_to_width(const vvp_vector4_t&that, unsigned width) +{ + if (that.size() == width) + return that; + + assert(that.size() > width); + vvp_vector4_t res (width); + for (unsigned idx = 0 ; idx < width ; idx += 1) + res.set_bit(idx, that.value(idx)); + + return res; +} + + vvp_vector2_t::vvp_vector2_t() { vec_ = 0; @@ -747,6 +761,12 @@ void vvp_fun_signal::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit) break; case 2: // Force value + + // Force from a node may not have been sized completely + // by the source, so coerce the size here. + if (bit.size() != size()) + bit = coerce_to_width(bit, size()); + force_active_ = true; force_ = bit; vvp_send_vec4(ptr.ptr()->out, force_); @@ -1373,6 +1393,9 @@ vvp_bit4_t compare_gtge_signed(const vvp_vector4_t&a, /* * $Log: vvp_net.cc,v $ + * Revision 1.31 2005/06/13 00:54:04 steve + * More unified vec4 to hex string functions. + * * Revision 1.30 2005/06/12 15:13:37 steve * Support resistive mos devices. * diff --git a/vvp/vvp_net.h b/vvp/vvp_net.h index c303cbd4c..cf537c00c 100644 --- a/vvp/vvp_net.h +++ b/vvp/vvp_net.h @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#ident "$Id: vvp_net.h,v 1.31 2005/06/12 15:13:37 steve Exp $" +#ident "$Id: vvp_net.h,v 1.32 2005/06/13 00:54:04 steve Exp $" # include "config.h" # include @@ -117,6 +117,7 @@ extern vvp_bit4_t compare_gtge(const vvp_vector4_t&a, extern vvp_bit4_t compare_gtge_signed(const vvp_vector4_t&a, const vvp_vector4_t&b, vvp_bit4_t val_if_equal); +extern vvp_vector4_t coerce_to_width(const vvp_vector4_t&that, unsigned width); /* * These functions extract the value of the vector as a native type, @@ -754,6 +755,9 @@ class vvp_wide_fun_t : public vvp_net_fun_t { /* * $Log: vvp_net.h,v $ + * Revision 1.32 2005/06/13 00:54:04 steve + * More unified vec4 to hex string functions. + * * Revision 1.31 2005/06/12 15:13:37 steve * Support resistive mos devices. *