Fix problem with delay at t0 when only some of the bits change.

This patch makes sure the delay is calculated correctly when only some
of the bits change and you are comparing against the initial (t0) value.
Basically you have to check the initial value against all the bits in
the new signal not just the first bit since the order that bits change
is not deterministic.
This commit is contained in:
Cary R 2008-01-30 14:14:52 -08:00 committed by Stephen Williams
parent 4c5481f254
commit fa759c1802
2 changed files with 32 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005-2007 Stephen Williams <steve@icarus.com>
* Copyright (c) 2005-2008 Stephen Williams <steve@icarus.com>
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -132,6 +132,7 @@ vvp_fun_delay::vvp_fun_delay(vvp_net_t*n, vvp_bit4_t init, const vvp_delay_t&d)
{
cur_vec4_.set_bit(0, init);
list_ = 0;
initial_ = true;
}
vvp_fun_delay::~vvp_fun_delay()
@ -190,21 +191,32 @@ void vvp_fun_delay::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit)
return;
}
/* How many bits to compare? */
unsigned use_wid = cur_vec4_.size();
if (bit.size() < use_wid)
use_wid = bit.size();
/* Scan the vectors looking for delays. Select the maximum
delay encountered. */
vvp_time64_t use_delay;
use_delay = delay_.get_delay(cur_vec4_.value(0), bit.value(0));
/* This is an initial value so it needs to be compared to all the
bits (the order the bits are changed is not deterministic). */
if (initial_) {
vvp_bit4_t cur_val = cur_vec4_.value(0);
use_delay = delay_.get_delay(cur_val, bit.value(0));
for (unsigned idx = 1 ; idx < bit.size() ; idx += 1) {
vvp_time64_t tmp;
tmp = delay_.get_delay(cur_val, bit.value(idx));
if (tmp > use_delay) use_delay = tmp;
}
} else {
for (unsigned idx = 1 ; idx < use_wid ; idx += 1) {
vvp_time64_t tmp;
tmp = delay_.get_delay(cur_vec4_.value(idx), bit.value(idx));
if (tmp > use_delay)
use_delay = tmp;
/* How many bits to compare? */
unsigned use_wid = cur_vec4_.size();
if (bit.size() < use_wid) use_wid = bit.size();
/* Scan the vectors looking for delays. Select the maximum
delay encountered. */
use_delay = delay_.get_delay(cur_vec4_.value(0), bit.value(0));
for (unsigned idx = 1 ; idx < use_wid ; idx += 1) {
vvp_time64_t tmp;
tmp = delay_.get_delay(cur_vec4_.value(idx), bit.value(idx));
if (tmp > use_delay) use_delay = tmp;
}
}
/* what *should* happen here is we check to see if there is a
@ -217,6 +229,7 @@ void vvp_fun_delay::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit)
/* And propagate it. */
if (use_delay == 0) {
cur_vec4_ = bit;
initial_ = false;
vvp_send_vec4(net_->out, cur_vec4_);
} else {
struct event_*cur = new struct event_(use_simtime);
@ -241,6 +254,7 @@ void vvp_fun_delay::recv_vec8(vvp_net_ptr_t port, vvp_vector8_t bit)
vvp_time64_t use_simtime = schedule_simtime() + use_delay;
if (use_delay == 0) {
cur_vec8_ = bit;
initial_ = false;
vvp_send_vec8(net_->out, cur_vec8_);
} else {
struct event_*cur = new struct event_(use_simtime);
@ -284,6 +298,7 @@ void vvp_fun_delay::recv_real(vvp_net_ptr_t port, double bit)
if (use_delay == 0) {
cur_real_ = bit;
initial_ = false;
vvp_send_real(net_->out, cur_real_);
} else {
struct event_*cur = new struct event_(use_simtime);
@ -306,6 +321,7 @@ void vvp_fun_delay::run_run()
return;
(this->*(cur->run_run_ptr))(cur);
initial_ = false;
delete cur;
}

View File

@ -1,7 +1,7 @@
#ifndef __delay_H
#define __delay_H
/*
* Copyright 2005 Stephen Williams
* Copyright 2005-2008 Stephen Williams
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -19,9 +19,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/*
*/
# include "vvp_net.h"
# include "schedule.h"
@ -104,6 +101,7 @@ class vvp_fun_delay : public vvp_net_fun_t, private vvp_gen_event_s {
private:
vvp_net_t*net_;
vvp_delay_t delay_;
bool initial_; // Indicates if the value is still the initial value.
vvp_vector4_t cur_vec4_;
vvp_vector8_t cur_vec8_;