From 6e5373c87e5cf17774923abe2fdf7a3caa0d07f9 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Tue, 3 Jun 2008 08:52:42 -0700 Subject: [PATCH] Add part select support to vvp_vector8_t Need a convenient way to handle part selects of vvp_vector8_t objects. --- vvp/vvp_net.cc | 28 ++++++++++++++++++++++++++++ vvp/vvp_net.h | 6 ++++++ 2 files changed, 34 insertions(+) diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index dfc77fb40..b11b0469e 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -1840,6 +1840,34 @@ bool vvp_vector8_t::eeq(const vvp_vector8_t&that) const return true; } +vvp_vector8_t vvp_vector8_t::subvalue(unsigned base, unsigned wid) const +{ + vvp_vector8_t tmp (wid); + + unsigned idx = 0; + while (base+idx < size_) { + tmp.bits_[idx] = bits_[base+idx]; + idx += 1; + } + + return tmp; +} + +vvp_vector8_t part_expand(const vvp_vector8_t&that, unsigned wid, unsigned off) +{ + assert(off < wid); + vvp_vector8_t tmp (wid); + + unsigned idx = off; + + while (idx < wid && that.size_ > (idx-off)) { + tmp.bits_[idx] = that.bits_[idx-off]; + idx += 1; + } + + return tmp; +} + ostream& operator<<(ostream&out, const vvp_vector8_t&that) { out << "C8<"; diff --git a/vvp/vvp_net.h b/vvp/vvp_net.h index 27fcbee23..7d3c6e5db 100644 --- a/vvp/vvp_net.h +++ b/vvp/vvp_net.h @@ -542,6 +542,8 @@ extern ostream& operator<< (ostream&, vvp_scalar_t); */ class vvp_vector8_t { + friend vvp_vector8_t part_expand(const vvp_vector8_t&, unsigned, unsigned); + public: explicit vvp_vector8_t(unsigned size =0); // Make a vvp_vector8_t from a vector4 and a specified strength. @@ -554,6 +556,7 @@ class vvp_vector8_t { unsigned size() const { return size_; } vvp_scalar_t value(unsigned idx) const; + vvp_vector8_t subvalue(unsigned idx, unsigned size) const; void set_bit(unsigned idx, vvp_scalar_t val); // Test that the vectors are exactly equal @@ -576,6 +579,7 @@ extern vvp_vector8_t resistive_reduction(const vvp_vector8_t&a); /* The reduce4 function converts a vector8 to a vector4, losing strength information in the process. */ extern vvp_vector4_t reduce4(const vvp_vector8_t&that); +extern vvp_vector8_t part_expand(const vvp_vector8_t&a, unsigned wid, unsigned off); /* Print a vector8 value to a stream. */ extern ostream& operator<< (ostream&, const vvp_vector8_t&); @@ -643,6 +647,8 @@ template class vvp_sub_pointer_t { }; typedef vvp_sub_pointer_t vvp_net_ptr_t; +template ostream& operator << (ostream&out, vvp_sub_pointer_t val) +{ out << val.ptr() << "[" << val.port() << "]"; return out; } /* * This is the basic unit of netlist connectivity. It is a fan-in of