vvp_fun_signal eliminates duplicate propagations.

This commit is contained in:
steve 2005-04-25 04:42:17 +00:00
parent aed8474944
commit e9bf021f6c
2 changed files with 58 additions and 11 deletions

View File

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ident "$Id: vvp_net.cc,v 1.24 2005/04/13 06:34:20 steve Exp $" #ident "$Id: vvp_net.cc,v 1.25 2005/04/25 04:42:17 steve Exp $"
# include "config.h" # include "config.h"
# include "vvp_net.h" # include "vvp_net.h"
@ -302,6 +302,27 @@ void vvp_vector4_t::set_bit(unsigned idx, vvp_bit4_t val)
} }
} }
bool vvp_vector4_t::eeq(const vvp_vector4_t&that) const
{
if (size_ != that.size_)
return false;
unsigned words = (size_+bits_per_word-1) / bits_per_word;
if (words == 1) {
if (bits_val_ == that.bits_val_)
return true;
else
return false;
}
for (unsigned idx = 0 ; idx < words ; idx += 1) {
if (bits_ptr_[idx] != that.bits_ptr_[idx])
return false;
}
return true;
}
char* vvp_vector4_t::as_string(char*buf, size_t buf_len) char* vvp_vector4_t::as_string(char*buf, size_t buf_len)
{ {
char*res = buf; char*res = buf;
@ -666,7 +687,7 @@ void vvp_fun_drive::recv_vec4(vvp_net_ptr_t port, vvp_vector4_t bit)
/* **** vvp_fun_signal methods **** */ /* **** vvp_fun_signal methods **** */
vvp_fun_signal::vvp_fun_signal(unsigned wid) vvp_fun_signal::vvp_fun_signal(unsigned wid)
: bits4_(wid) : bits4_(wid), needs_init_(true)
{ {
vpi_callbacks = 0; vpi_callbacks = 0;
continuous_assign_active_ = false; continuous_assign_active_ = false;
@ -680,15 +701,27 @@ bool vvp_fun_signal::type_is_vector8_() const
/* /*
* Nets simply reflect their input to their output. * Nets simply reflect their input to their output.
*/ *
* NOTE: It is a quirk of vvp_fun_signal that it has an initial value
* that needs to be propagated, but after that it only needs to
* propagate if the value changes. Elimitating duplicate propagations
* should improve performance, but has the quirk that an input that
* matches the initial value might not be propagated. The hack used
* herein is to keep a "needs_init_" flag that is turned false after
* the first propagation, and forces the first propagation to happen
* even if it matches the initial value.
*/ */
void vvp_fun_signal::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit) void vvp_fun_signal::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit)
{ {
switch (ptr.port()) { switch (ptr.port()) {
case 0: // Normal input (feed from net, or set from process) case 0: // Normal input (feed from net, or set from process)
if (! continuous_assign_active_) { if (!continuous_assign_active_) {
bits4_ = bit; if (needs_init_ || !bits4_.eeq(bit)) {
vvp_send_vec4(ptr.ptr()->out, bit); bits4_ = bit;
run_vpi_callbacks(); needs_init_ = false;
vvp_send_vec4(ptr.ptr()->out, bit);
run_vpi_callbacks();
}
} }
break; break;
@ -731,6 +764,7 @@ void vvp_fun_signal::recv_vec4_pv(vvp_net_ptr_t ptr, vvp_vector4_t bit,
break; break;
bits4_.set_bit(base+idx, bit.value(idx)); bits4_.set_bit(base+idx, bit.value(idx));
} }
needs_init_ = false;
vvp_send_vec4(ptr.ptr()->out, bits4_); vvp_send_vec4(ptr.ptr()->out, bits4_);
run_vpi_callbacks(); run_vpi_callbacks();
} }
@ -749,6 +783,7 @@ void vvp_fun_signal::recv_vec8(vvp_net_ptr_t ptr, vvp_vector8_t bit)
if (! continuous_assign_active_) { if (! continuous_assign_active_) {
bits8_ = bit; bits8_ = bit;
needs_init_ = false;
vvp_send_vec8(ptr.ptr()->out, bit); vvp_send_vec8(ptr.ptr()->out, bit);
run_vpi_callbacks(); run_vpi_callbacks();
} }
@ -1303,6 +1338,9 @@ vvp_bit4_t compare_gtge_signed(const vvp_vector4_t&a,
/* /*
* $Log: vvp_net.cc,v $ * $Log: vvp_net.cc,v $
* Revision 1.25 2005/04/25 04:42:17 steve
* vvp_fun_signal eliminates duplicate propagations.
*
* Revision 1.24 2005/04/13 06:34:20 steve * Revision 1.24 2005/04/13 06:34:20 steve
* Add vvp driver functor for logic outputs, * Add vvp driver functor for logic outputs,
* Add ostream output operators for debugging. * Add ostream output operators for debugging.

View File

@ -18,7 +18,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ident "$Id: vvp_net.h,v 1.23 2005/04/13 06:34:20 steve Exp $" #ident "$Id: vvp_net.h,v 1.24 2005/04/25 04:42:17 steve Exp $"
# include "config.h" # include "config.h"
# include <assert.h> # include <assert.h>
@ -85,18 +85,21 @@ class vvp_vector4_t {
public: public:
explicit vvp_vector4_t(unsigned size =0); explicit vvp_vector4_t(unsigned size =0);
vvp_vector4_t(const vvp_vector4_t&that);
vvp_vector4_t& operator= (const vvp_vector4_t&that);
~vvp_vector4_t(); ~vvp_vector4_t();
unsigned size() const { return size_; } unsigned size() const { return size_; }
vvp_bit4_t value(unsigned idx) const; vvp_bit4_t value(unsigned idx) const;
void set_bit(unsigned idx, vvp_bit4_t val); void set_bit(unsigned idx, vvp_bit4_t val);
// Test that the vectors are exactly equal
bool eeq(const vvp_vector4_t&that) const;
// Display the value into the buf as a string. // Display the value into the buf as a string.
char*as_string(char*buf, size_t buf_len); char*as_string(char*buf, size_t buf_len);
vvp_vector4_t(const vvp_vector4_t&that);
vvp_vector4_t& operator= (const vvp_vector4_t&that);
private: private:
unsigned size_; unsigned size_;
union { union {
@ -610,6 +613,9 @@ class vvp_fun_signal : public vvp_net_fun_t {
vvp_vector8_t bits8_; vvp_vector8_t bits8_;
bool type_is_vector8_() const; bool type_is_vector8_() const;
// This is true until at least one propagation happens.
bool needs_init_;
bool continuous_assign_active_; bool continuous_assign_active_;
vvp_vector4_t force_; vvp_vector4_t force_;
@ -692,6 +698,9 @@ class vvp_wide_fun_t : public vvp_net_fun_t {
/* /*
* $Log: vvp_net.h,v $ * $Log: vvp_net.h,v $
* Revision 1.24 2005/04/25 04:42:17 steve
* vvp_fun_signal eliminates duplicate propagations.
*
* Revision 1.23 2005/04/13 06:34:20 steve * Revision 1.23 2005/04/13 06:34:20 steve
* Add vvp driver functor for logic outputs, * Add vvp driver functor for logic outputs,
* Add ostream output operators for debugging. * Add ostream output operators for debugging.