2001-11-10 19:07:11 +01:00
|
|
|
/*
|
2025-07-22 08:30:57 +02:00
|
|
|
* Copyright (c) 2005-2025 Stephen Williams <steve@icarus.com>
|
2001-11-10 19:07:11 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-11-10 19:07:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "delay.h"
|
2005-05-14 21:43:23 +02:00
|
|
|
#include "schedule.h"
|
2007-10-31 04:14:40 +01:00
|
|
|
#include "vpi_priv.h"
|
2009-01-30 02:23:09 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
#include "vvp_cleanup.h"
|
|
|
|
|
#endif
|
2005-11-10 14:27:16 +01:00
|
|
|
#include <iostream>
|
2008-01-05 00:23:47 +01:00
|
|
|
#include <cstdlib>
|
2008-04-26 02:17:51 +02:00
|
|
|
#include <list>
|
2010-05-31 22:12:06 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
#include <cmath>
|
2010-10-24 00:52:56 +02:00
|
|
|
#include "ivl_alloc.h"
|
2001-11-10 19:07:11 +01:00
|
|
|
|
2021-11-04 18:02:07 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
2006-01-02 06:32:06 +01:00
|
|
|
void vvp_delay_t::calculate_min_delay_()
|
|
|
|
|
{
|
|
|
|
|
min_delay_ = rise_;
|
|
|
|
|
if (fall_ < min_delay_)
|
|
|
|
|
min_delay_ = fall_;
|
2010-07-13 19:01:32 +02:00
|
|
|
if (ignore_decay_) decay_ = min_delay_;
|
|
|
|
|
else if (decay_ < min_delay_)
|
2006-01-02 06:32:06 +01:00
|
|
|
min_delay_ = decay_;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_delay_t::vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall)
|
2001-11-10 19:07:11 +01:00
|
|
|
{
|
2005-04-03 07:45:51 +02:00
|
|
|
rise_ = rise;
|
|
|
|
|
fall_ = fall;
|
|
|
|
|
decay_= fall < rise? fall : rise;
|
|
|
|
|
min_delay_ = decay_;
|
2010-07-13 19:01:32 +02:00
|
|
|
ignore_decay_ = false;
|
2001-11-10 19:07:11 +01:00
|
|
|
}
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_delay_t::vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall, vvp_time64_t decay)
|
2001-11-10 19:07:11 +01:00
|
|
|
{
|
2005-04-03 07:45:51 +02:00
|
|
|
rise_ = rise;
|
|
|
|
|
fall_ = fall;
|
|
|
|
|
decay_= decay;
|
2010-07-13 19:01:32 +02:00
|
|
|
ignore_decay_ = false;
|
|
|
|
|
|
|
|
|
|
calculate_min_delay_();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_delay_t::set_ignore_decay()
|
|
|
|
|
{
|
|
|
|
|
ignore_decay_ = true;
|
2005-04-03 07:45:51 +02:00
|
|
|
|
2006-01-02 06:32:06 +01:00
|
|
|
calculate_min_delay_();
|
2001-11-10 19:07:11 +01:00
|
|
|
}
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_delay_t::~vvp_delay_t()
|
2001-11-10 19:07:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_time64_t vvp_delay_t::get_delay(vvp_bit4_t from, vvp_bit4_t to)
|
2001-11-10 19:07:11 +01:00
|
|
|
{
|
2005-04-03 07:45:51 +02:00
|
|
|
switch (from) {
|
|
|
|
|
case BIT4_0:
|
|
|
|
|
switch (to) {
|
|
|
|
|
case BIT4_0: return 0;
|
|
|
|
|
case BIT4_1: return rise_;
|
|
|
|
|
case BIT4_X: return min_delay_;
|
|
|
|
|
case BIT4_Z: return decay_;
|
|
|
|
|
}
|
2001-11-10 19:07:11 +01:00
|
|
|
break;
|
2005-04-03 07:45:51 +02:00
|
|
|
case BIT4_1:
|
|
|
|
|
switch (to) {
|
|
|
|
|
case BIT4_0: return fall_;
|
|
|
|
|
case BIT4_1: return 0;
|
|
|
|
|
case BIT4_X: return min_delay_;
|
|
|
|
|
case BIT4_Z: return decay_;
|
2001-11-10 19:07:11 +01:00
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
break;
|
2005-04-03 07:45:51 +02:00
|
|
|
case BIT4_X:
|
|
|
|
|
switch (to) {
|
|
|
|
|
case BIT4_0: return fall_;
|
|
|
|
|
case BIT4_1: return rise_;
|
|
|
|
|
case BIT4_X: return 0;
|
|
|
|
|
case BIT4_Z: return decay_;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_Z:
|
|
|
|
|
switch (to) {
|
|
|
|
|
case BIT4_0: return fall_;
|
|
|
|
|
case BIT4_1: return rise_;
|
|
|
|
|
case BIT4_X: return min_delay_;
|
|
|
|
|
case BIT4_Z: return 0;
|
2001-11-10 19:07:11 +01:00
|
|
|
}
|
2005-04-03 07:45:51 +02:00
|
|
|
break;
|
2001-11-10 19:07:11 +01:00
|
|
|
}
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
2001-11-10 19:07:11 +01:00
|
|
|
}
|
|
|
|
|
|
2005-07-06 06:29:25 +02:00
|
|
|
vvp_time64_t vvp_delay_t::get_min_delay() const
|
|
|
|
|
{
|
|
|
|
|
return min_delay_;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-02 06:32:06 +01:00
|
|
|
void vvp_delay_t::set_rise(vvp_time64_t val)
|
|
|
|
|
{
|
|
|
|
|
rise_ = val;
|
2010-07-14 00:03:22 +02:00
|
|
|
if (val < min_delay_) {
|
2006-01-02 06:32:06 +01:00
|
|
|
min_delay_ = val;
|
2010-07-14 00:03:22 +02:00
|
|
|
if (ignore_decay_) decay_ = val;
|
|
|
|
|
} else
|
2006-01-02 06:32:06 +01:00
|
|
|
calculate_min_delay_();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_delay_t::set_fall(vvp_time64_t val)
|
|
|
|
|
{
|
|
|
|
|
fall_ = val;
|
2010-07-14 00:03:22 +02:00
|
|
|
if (val < min_delay_) {
|
2006-01-02 06:32:06 +01:00
|
|
|
min_delay_ = val;
|
2010-07-14 00:03:22 +02:00
|
|
|
if (ignore_decay_) decay_ = val;
|
|
|
|
|
} else
|
2006-01-02 06:32:06 +01:00
|
|
|
calculate_min_delay_();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_delay_t::set_decay(vvp_time64_t val)
|
|
|
|
|
{
|
2010-07-13 19:01:32 +02:00
|
|
|
assert(!ignore_decay_);
|
|
|
|
|
|
2006-01-02 06:32:06 +01:00
|
|
|
decay_ = val;
|
|
|
|
|
if (val < min_delay_)
|
|
|
|
|
min_delay_ = val;
|
|
|
|
|
else
|
|
|
|
|
calculate_min_delay_();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 12:48:17 +02:00
|
|
|
vvp_fun_delay::vvp_fun_delay(vvp_net_t*n, unsigned width, const vvp_delay_t&d)
|
|
|
|
|
: net_(n), delay_(d)
|
2005-05-14 21:43:23 +02:00
|
|
|
{
|
2008-02-15 23:10:53 +01:00
|
|
|
cur_real_ = 0.0;
|
2010-04-08 12:48:17 +02:00
|
|
|
if (width > 0) {
|
|
|
|
|
cur_vec4_ = vvp_vector4_t(width, BIT4_X);
|
|
|
|
|
cur_vec8_ = vvp_vector8_t(cur_vec4_, 6, 6);
|
|
|
|
|
schedule_init_propagate(net_, cur_vec4_);
|
|
|
|
|
} else {
|
|
|
|
|
schedule_init_propagate(net_, cur_real_);
|
|
|
|
|
}
|
2007-01-26 06:15:41 +01:00
|
|
|
list_ = 0;
|
2009-08-07 05:32:10 +02:00
|
|
|
type_ = UNKNOWN_DELAY;
|
2008-01-30 23:14:52 +01:00
|
|
|
initial_ = true;
|
2008-09-12 01:50:45 +02:00
|
|
|
// Calculate the values used when converting variable delays
|
|
|
|
|
// to simulation time units.
|
2025-10-13 22:14:57 +02:00
|
|
|
const __vpiScope*scope = vpip_peek_current_scope();
|
2008-09-12 01:50:45 +02:00
|
|
|
|
2021-01-01 09:19:27 +01:00
|
|
|
int powr = scope->time_units - scope->time_precision;
|
2008-09-12 01:50:45 +02:00
|
|
|
round_ = 1;
|
2021-01-01 09:19:27 +01:00
|
|
|
for (int lp = 0; lp < powr; lp += 1) round_ *= 10;
|
2008-09-12 01:50:45 +02:00
|
|
|
|
2021-01-01 09:19:27 +01:00
|
|
|
powr = scope->time_precision - vpip_get_time_precision();
|
2008-09-12 01:50:45 +02:00
|
|
|
scale_ = 1;
|
2021-01-01 09:19:27 +01:00
|
|
|
for (int lp = 0; lp < powr; lp += 1) scale_ *= 10;
|
2005-05-14 21:43:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_delay::~vvp_fun_delay()
|
|
|
|
|
{
|
2007-01-26 06:15:41 +01:00
|
|
|
while (struct event_*cur = dequeue_())
|
|
|
|
|
delete cur;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-07 05:32:10 +02:00
|
|
|
bool vvp_fun_delay::clean_pulse_events_(vvp_time64_t use_delay,
|
|
|
|
|
const vvp_vector4_t&bit)
|
|
|
|
|
{
|
|
|
|
|
if (list_ == 0) return false;
|
|
|
|
|
|
|
|
|
|
/* If the most recent event and the new event have the same
|
|
|
|
|
* value then we need to skip the new event. */
|
|
|
|
|
if (list_->next->ptr_vec4.eeq(bit)) return true;
|
|
|
|
|
|
|
|
|
|
clean_pulse_events_(use_delay);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool vvp_fun_delay::clean_pulse_events_(vvp_time64_t use_delay,
|
|
|
|
|
const vvp_vector8_t&bit)
|
|
|
|
|
{
|
|
|
|
|
if (list_ == 0) return false;
|
|
|
|
|
|
|
|
|
|
/* If the most recent event and the new event have the same
|
|
|
|
|
* value then we need to skip the new event. */
|
|
|
|
|
if (list_->next->ptr_vec8.eeq(bit)) return true;
|
|
|
|
|
|
|
|
|
|
clean_pulse_events_(use_delay);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool vvp_fun_delay::clean_pulse_events_(vvp_time64_t use_delay,
|
|
|
|
|
double bit)
|
|
|
|
|
{
|
|
|
|
|
if (list_ == 0) return false;
|
|
|
|
|
|
|
|
|
|
/* If the most recent event and the new event have the same
|
|
|
|
|
* value then we need to skip the new event. */
|
|
|
|
|
if (list_->next->ptr_real == bit) return true;
|
|
|
|
|
|
|
|
|
|
clean_pulse_events_(use_delay);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
void vvp_fun_delay::clean_pulse_events_(vvp_time64_t use_delay)
|
|
|
|
|
{
|
2009-08-07 05:32:10 +02:00
|
|
|
assert(list_ != 0);
|
2007-01-26 06:15:41 +01:00
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
struct event_*cur = list_->next;
|
|
|
|
|
/* If this event is far enough from the event I'm about
|
|
|
|
|
to create, then that scheduled event is not a pulse
|
|
|
|
|
to be eliminated, so we're done. */
|
|
|
|
|
if (cur->sim_time+use_delay <= use_delay+schedule_simtime())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (list_ == cur)
|
|
|
|
|
list_ = 0;
|
|
|
|
|
else
|
|
|
|
|
list_->next = cur->next;
|
|
|
|
|
delete cur;
|
|
|
|
|
} while (list_);
|
2005-05-14 21:43:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2005-11-10 14:27:16 +01:00
|
|
|
* FIXME: this implementation currently only uses the maximum delay
|
|
|
|
|
* from all the bit changes in the vectors. If there are multiple
|
|
|
|
|
* changes with different delays, then the results would be
|
|
|
|
|
* wrong. What should happen is that if there are multiple changes,
|
|
|
|
|
* multiple vectors approaching the result should be scheduled.
|
2005-05-14 21:43:23 +02:00
|
|
|
*/
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_delay::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2005-05-14 21:43:23 +02:00
|
|
|
{
|
2006-01-02 06:32:06 +01:00
|
|
|
if (port.port() > 0) {
|
|
|
|
|
// Get the integer value of the bit vector, or 0 if
|
|
|
|
|
// there are X or Z bits.
|
2008-09-12 01:50:45 +02:00
|
|
|
vvp_time64_t bval = 0;
|
|
|
|
|
// The following does not work correctly for negative values.
|
|
|
|
|
// They should be sign extended to 64 bits (1364-2001 9.7.1).
|
|
|
|
|
vector4_to_value(bit, bval);
|
|
|
|
|
// Integer values do not need to be rounded so just scale them.
|
|
|
|
|
vvp_time64_t val = bval * round_ * scale_;
|
2006-01-02 06:32:06 +01:00
|
|
|
|
|
|
|
|
switch (port.port()) {
|
|
|
|
|
case 1:
|
|
|
|
|
delay_.set_rise(val);
|
|
|
|
|
return;
|
|
|
|
|
case 2:
|
|
|
|
|
delay_.set_fall(val);
|
|
|
|
|
return;
|
|
|
|
|
case 3:
|
|
|
|
|
delay_.set_decay(val);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-06 06:29:25 +02:00
|
|
|
vvp_time64_t use_delay;
|
2008-01-30 23:14:52 +01:00
|
|
|
/* 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_) {
|
2009-08-07 05:32:10 +02:00
|
|
|
type_ = VEC4_DELAY;
|
2011-11-06 18:39:20 +01:00
|
|
|
cur_vec8_ = vvp_vector8_t(vvp_vector4_t(0, BIT4_X), 6, 6);
|
2008-01-30 23:14:52 +01:00
|
|
|
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 {
|
2009-08-07 05:32:10 +02:00
|
|
|
assert(type_ == VEC4_DELAY);
|
2005-07-06 06:29:25 +02:00
|
|
|
|
2009-11-24 03:27:14 +01:00
|
|
|
// Use as a reference for calculating the delay the
|
|
|
|
|
// current value of the output. Detect and handle the
|
|
|
|
|
// special case that the event list contains the current
|
|
|
|
|
// value as a zero-delay-remaining event.
|
|
|
|
|
const vvp_vector4_t&use_vec4 = (list_ && list_->next->sim_time == schedule_simtime())? list_->next->ptr_vec4 : cur_vec4_;
|
|
|
|
|
|
2008-01-30 23:14:52 +01:00
|
|
|
/* How many bits to compare? */
|
2009-11-24 03:27:14 +01:00
|
|
|
unsigned use_wid = use_vec4.size();
|
2008-01-30 23:14:52 +01:00
|
|
|
if (bit.size() < use_wid) use_wid = bit.size();
|
|
|
|
|
|
|
|
|
|
/* Scan the vectors looking for delays. Select the maximum
|
|
|
|
|
delay encountered. */
|
2009-11-24 03:27:14 +01:00
|
|
|
use_delay = delay_.get_delay(use_vec4.value(0), bit.value(0));
|
2008-01-30 23:14:52 +01:00
|
|
|
|
|
|
|
|
for (unsigned idx = 1 ; idx < use_wid ; idx += 1) {
|
|
|
|
|
vvp_time64_t tmp;
|
2009-11-24 03:27:14 +01:00
|
|
|
tmp = delay_.get_delay(use_vec4.value(idx), bit.value(idx));
|
2008-01-30 23:14:52 +01:00
|
|
|
if (tmp > use_delay) use_delay = tmp;
|
|
|
|
|
}
|
2005-11-10 14:27:16 +01:00
|
|
|
}
|
|
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
/* what *should* happen here is we check to see if there is a
|
|
|
|
|
transaction in the queue. This would be a pulse that needs to be
|
|
|
|
|
eliminated. */
|
2009-08-07 05:32:10 +02:00
|
|
|
if (clean_pulse_events_(use_delay, bit)) return;
|
2007-01-26 06:15:41 +01:00
|
|
|
|
|
|
|
|
vvp_time64_t use_simtime = schedule_simtime() + use_delay;
|
|
|
|
|
|
2005-11-10 14:27:16 +01:00
|
|
|
/* And propagate it. */
|
2009-11-24 03:27:14 +01:00
|
|
|
if (use_delay == 0 && list_ == 0) {
|
2007-01-26 06:15:41 +01:00
|
|
|
cur_vec4_ = bit;
|
2008-01-30 23:14:52 +01:00
|
|
|
initial_ = false;
|
2009-04-04 05:40:26 +02:00
|
|
|
net_->send_vec4(cur_vec4_, 0);
|
2005-07-06 06:29:25 +02:00
|
|
|
} else {
|
2007-01-26 06:15:41 +01:00
|
|
|
struct event_*cur = new struct event_(use_simtime);
|
|
|
|
|
cur->run_run_ptr = &vvp_fun_delay::run_run_vec4_;
|
|
|
|
|
cur->ptr_vec4 = bit;
|
|
|
|
|
enqueue_(cur);
|
2006-01-02 06:32:06 +01:00
|
|
|
schedule_generic(this, use_delay, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 00:47:43 +02:00
|
|
|
void vvp_fun_delay::recv_vec4_pv(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned base, unsigned vwid, vvp_context_t ctx)
|
2016-04-19 00:47:43 +02:00
|
|
|
{
|
2022-05-28 13:04:53 +02:00
|
|
|
recv_vec4_pv_(ptr, bit, base, vwid, ctx);
|
2016-04-19 00:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
2009-04-28 05:37:28 +02:00
|
|
|
/* See the recv_vec4 comment above. */
|
2008-06-12 21:08:02 +02:00
|
|
|
void vvp_fun_delay::recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit)
|
2006-01-02 06:32:06 +01:00
|
|
|
{
|
|
|
|
|
assert(port.port() == 0);
|
|
|
|
|
|
|
|
|
|
vvp_time64_t use_delay;
|
2009-04-28 05:37:28 +02:00
|
|
|
/* 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_) {
|
2009-08-07 05:32:10 +02:00
|
|
|
type_ = VEC8_DELAY;
|
2011-11-06 18:39:20 +01:00
|
|
|
cur_vec4_ = vvp_vector4_t(0, BIT4_X);
|
2009-04-28 05:37:28 +02:00
|
|
|
vvp_bit4_t cur_val = cur_vec8_.value(0).value();
|
|
|
|
|
use_delay = delay_.get_delay(cur_val, bit.value(0).value());
|
|
|
|
|
for (unsigned idx = 1 ; idx < bit.size() ; idx += 1) {
|
|
|
|
|
vvp_time64_t tmp;
|
|
|
|
|
tmp = delay_.get_delay(cur_val, bit.value(idx).value());
|
|
|
|
|
if (tmp > use_delay) use_delay = tmp;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-08-07 05:32:10 +02:00
|
|
|
assert(type_ == VEC8_DELAY);
|
2009-04-28 05:37:28 +02:00
|
|
|
|
2009-11-24 03:27:14 +01:00
|
|
|
// Use as a reference for calculating the delay the
|
|
|
|
|
// current value of the output. Detect and handle the
|
|
|
|
|
// special case that the event list contains the current
|
|
|
|
|
// value as a zero-delay-remaining event.
|
|
|
|
|
const vvp_vector8_t&use_vec8 = (list_ && list_->next->sim_time == schedule_simtime())? list_->next->ptr_vec8 : cur_vec8_;
|
|
|
|
|
|
2009-04-28 05:37:28 +02:00
|
|
|
/* How many bits to compare? */
|
2009-11-24 03:27:14 +01:00
|
|
|
unsigned use_wid = use_vec8.size();
|
2009-04-28 05:37:28 +02:00
|
|
|
if (bit.size() < use_wid) use_wid = bit.size();
|
|
|
|
|
|
|
|
|
|
/* Scan the vectors looking for delays. Select the maximum
|
|
|
|
|
delay encountered. */
|
2009-11-24 03:27:14 +01:00
|
|
|
use_delay = delay_.get_delay(use_vec8.value(0).value(),
|
2009-04-28 05:37:28 +02:00
|
|
|
bit.value(0).value());
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 1 ; idx < use_wid ; idx += 1) {
|
|
|
|
|
vvp_time64_t tmp;
|
2009-11-24 03:27:14 +01:00
|
|
|
tmp = delay_.get_delay(use_vec8.value(idx).value(),
|
2009-04-28 05:37:28 +02:00
|
|
|
bit.value(idx).value());
|
|
|
|
|
if (tmp > use_delay) use_delay = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* what *should* happen here is we check to see if there is a
|
|
|
|
|
transaction in the queue. This would be a pulse that needs to be
|
|
|
|
|
eliminated. */
|
2009-08-07 05:32:10 +02:00
|
|
|
if (clean_pulse_events_(use_delay, bit)) return;
|
2006-01-02 06:32:06 +01:00
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
vvp_time64_t use_simtime = schedule_simtime() + use_delay;
|
2009-04-28 05:37:28 +02:00
|
|
|
|
|
|
|
|
/* And propagate it. */
|
2009-11-24 03:27:14 +01:00
|
|
|
if (use_delay == 0 && list_ == 0) {
|
2007-01-26 06:15:41 +01:00
|
|
|
cur_vec8_ = bit;
|
2008-01-30 23:14:52 +01:00
|
|
|
initial_ = false;
|
2009-04-04 05:40:26 +02:00
|
|
|
net_->send_vec8(cur_vec8_);
|
2006-01-02 06:32:06 +01:00
|
|
|
} else {
|
2007-01-26 06:15:41 +01:00
|
|
|
struct event_*cur = new struct event_(use_simtime);
|
|
|
|
|
cur->ptr_vec8 = bit;
|
|
|
|
|
cur->run_run_ptr = &vvp_fun_delay::run_run_vec8_;
|
|
|
|
|
enqueue_(cur);
|
2005-07-06 06:29:25 +02:00
|
|
|
schedule_generic(this, use_delay, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 00:47:43 +02:00
|
|
|
void vvp_fun_delay::recv_vec8_pv(vvp_net_ptr_t ptr, const vvp_vector8_t&bit,
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned base, unsigned vwid)
|
2016-04-19 00:47:43 +02:00
|
|
|
{
|
2022-05-28 13:04:53 +02:00
|
|
|
recv_vec8_pv_(ptr, bit, base, vwid);
|
2016-04-19 00:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_delay::recv_real(vvp_net_ptr_t port, double bit,
|
|
|
|
|
vvp_context_t)
|
2005-07-06 06:29:25 +02:00
|
|
|
{
|
2006-07-08 23:48:00 +02:00
|
|
|
if (port.port() > 0) {
|
|
|
|
|
/* If the port is not 0, then this is a delay value that
|
|
|
|
|
should be rounded and converted to an integer delay. */
|
2008-09-12 01:50:45 +02:00
|
|
|
vvp_time64_t val = 0;
|
|
|
|
|
if (bit > -0.5) {
|
2008-09-12 03:07:01 +02:00
|
|
|
val = (vvp_time64_t) (bit * round_ + 0.5) * scale_;
|
2008-09-12 01:50:45 +02:00
|
|
|
} else if (bit != bit) {
|
|
|
|
|
// For a NaN we use the default (0).
|
|
|
|
|
} else {
|
2008-09-12 03:07:01 +02:00
|
|
|
vvp_vector4_t vec4(8*sizeof(vvp_time64_t),
|
|
|
|
|
floor(-bit * round_ + 0.5) * -1 * scale_);
|
|
|
|
|
vector4_to_value(vec4, val);
|
2008-09-12 01:50:45 +02:00
|
|
|
}
|
2006-07-08 23:48:00 +02:00
|
|
|
|
|
|
|
|
switch (port.port()) {
|
|
|
|
|
case 1:
|
|
|
|
|
delay_.set_rise(val);
|
|
|
|
|
return;
|
|
|
|
|
case 2:
|
|
|
|
|
delay_.set_fall(val);
|
|
|
|
|
return;
|
|
|
|
|
case 3:
|
|
|
|
|
delay_.set_decay(val);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-06 18:39:20 +01:00
|
|
|
if (initial_) {
|
|
|
|
|
type_ = REAL_DELAY;
|
|
|
|
|
cur_vec4_ = vvp_vector4_t(0, BIT4_X);
|
|
|
|
|
cur_vec8_ = vvp_vector8_t(cur_vec4_, 6, 6);
|
|
|
|
|
} else assert(type_ == REAL_DELAY);
|
2009-08-07 05:32:10 +02:00
|
|
|
|
2005-05-14 21:43:23 +02:00
|
|
|
vvp_time64_t use_delay;
|
2005-07-06 06:29:25 +02:00
|
|
|
use_delay = delay_.get_min_delay();
|
2005-05-14 21:43:23 +02:00
|
|
|
|
2008-02-13 20:21:19 +01:00
|
|
|
/* Eliminate glitches. */
|
2009-08-07 05:32:10 +02:00
|
|
|
if (clean_pulse_events_(use_delay, bit)) return;
|
2008-02-13 20:21:19 +01:00
|
|
|
|
|
|
|
|
/* This must be done after cleaning pulses to avoid propagating
|
|
|
|
|
* an incorrect value. */
|
|
|
|
|
if (cur_real_ == bit) return;
|
|
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
vvp_time64_t use_simtime = schedule_simtime() + use_delay;
|
|
|
|
|
|
2009-11-24 03:27:14 +01:00
|
|
|
if (use_delay == 0 && list_ == 0) {
|
2007-01-26 06:15:41 +01:00
|
|
|
cur_real_ = bit;
|
2008-01-30 23:14:52 +01:00
|
|
|
initial_ = false;
|
2009-04-04 05:40:26 +02:00
|
|
|
net_->send_real(cur_real_, 0);
|
2005-07-06 06:29:25 +02:00
|
|
|
} else {
|
2007-01-26 06:15:41 +01:00
|
|
|
struct event_*cur = new struct event_(use_simtime);
|
|
|
|
|
cur->run_run_ptr = &vvp_fun_delay::run_run_real_;
|
|
|
|
|
cur->ptr_real = bit;
|
|
|
|
|
enqueue_(cur);
|
|
|
|
|
|
2005-06-09 07:04:45 +02:00
|
|
|
schedule_generic(this, use_delay, false);
|
2005-07-06 06:29:25 +02:00
|
|
|
}
|
2005-06-02 18:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_delay::run_run()
|
|
|
|
|
{
|
2007-01-26 06:15:41 +01:00
|
|
|
vvp_time64_t sim_time = schedule_simtime();
|
|
|
|
|
if (list_ == 0 || list_->next->sim_time > sim_time)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
struct event_*cur = dequeue_();
|
|
|
|
|
if (cur == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
(this->*(cur->run_run_ptr))(cur);
|
2008-01-30 23:14:52 +01:00
|
|
|
initial_ = false;
|
2007-01-26 06:15:41 +01:00
|
|
|
delete cur;
|
2005-05-14 21:43:23 +02:00
|
|
|
}
|
|
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
void vvp_fun_delay::run_run_vec4_(struct event_*cur)
|
2006-01-02 06:32:06 +01:00
|
|
|
{
|
2007-01-26 06:15:41 +01:00
|
|
|
cur_vec4_ = cur->ptr_vec4;
|
2009-04-04 05:40:26 +02:00
|
|
|
net_->send_vec4(cur_vec4_, 0);
|
2006-01-02 06:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
void vvp_fun_delay::run_run_vec8_(struct vvp_fun_delay::event_*cur)
|
2006-01-02 06:32:06 +01:00
|
|
|
{
|
2007-01-26 06:15:41 +01:00
|
|
|
cur_vec8_ = cur->ptr_vec8;
|
2009-04-04 05:40:26 +02:00
|
|
|
net_->send_vec8(cur_vec8_);
|
2006-01-02 06:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
void vvp_fun_delay::run_run_real_(struct vvp_fun_delay::event_*cur)
|
2006-01-02 06:32:06 +01:00
|
|
|
{
|
2007-01-26 06:15:41 +01:00
|
|
|
cur_real_ = cur->ptr_real;
|
2009-04-04 05:40:26 +02:00
|
|
|
net_->send_real(cur_real_, 0);
|
2006-01-02 06:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-08 12:48:17 +02:00
|
|
|
vvp_fun_modpath::vvp_fun_modpath(vvp_net_t*net, unsigned width)
|
2008-04-29 04:00:29 +02:00
|
|
|
: net_(net), src_list_(0), ifnone_list_(0)
|
2006-09-23 06:57:19 +02:00
|
|
|
{
|
2010-04-08 12:48:17 +02:00
|
|
|
cur_vec4_ = vvp_vector4_t(width, BIT4_X);
|
|
|
|
|
schedule_init_propagate(net_, cur_vec4_);
|
2006-09-23 06:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_modpath::~vvp_fun_modpath()
|
|
|
|
|
{
|
|
|
|
|
// Delete the source probes.
|
|
|
|
|
while (src_list_) {
|
|
|
|
|
vvp_fun_modpath_src*tmp = src_list_;
|
|
|
|
|
src_list_ = tmp->next_;
|
|
|
|
|
delete tmp;
|
|
|
|
|
}
|
2008-04-29 04:00:29 +02:00
|
|
|
while (ifnone_list_) {
|
|
|
|
|
vvp_fun_modpath_src*tmp = ifnone_list_;
|
|
|
|
|
ifnone_list_ = tmp->next_;
|
|
|
|
|
delete tmp;
|
|
|
|
|
}
|
2006-09-23 06:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2008-04-29 04:00:29 +02:00
|
|
|
void vvp_fun_modpath::add_modpath_src(vvp_fun_modpath_src*that, bool ifnone)
|
2006-09-23 06:57:19 +02:00
|
|
|
{
|
|
|
|
|
assert(that->next_ == 0);
|
2008-04-29 04:00:29 +02:00
|
|
|
if (ifnone) {
|
|
|
|
|
that->next_ = ifnone_list_;
|
|
|
|
|
ifnone_list_ = that;
|
|
|
|
|
} else {
|
|
|
|
|
that->next_ = src_list_;
|
|
|
|
|
src_list_ = that;
|
|
|
|
|
}
|
2006-09-23 06:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2008-04-29 04:00:29 +02:00
|
|
|
static vvp_time64_t delay_from_edge(vvp_bit4_t a, vvp_bit4_t b,
|
2025-07-22 08:30:57 +02:00
|
|
|
vvp_time64_t const array[12])
|
2006-09-29 05:57:01 +02:00
|
|
|
{
|
|
|
|
|
typedef delay_edge_t bit4_table4[4];
|
2010-10-24 00:52:56 +02:00
|
|
|
static const bit4_table4 edge_table[4] = {
|
2014-10-18 04:38:30 +02:00
|
|
|
{ DELAY_EDGE_01, DELAY_EDGE_01, DELAY_EDGE_0z, DELAY_EDGE_0x },
|
|
|
|
|
{ DELAY_EDGE_10, DELAY_EDGE_10, DELAY_EDGE_1z, DELAY_EDGE_1x },
|
|
|
|
|
{ DELAY_EDGE_z0, DELAY_EDGE_z1, DELAY_EDGE_z0, DELAY_EDGE_zx },
|
|
|
|
|
{ DELAY_EDGE_x0, DELAY_EDGE_x1, DELAY_EDGE_xz, DELAY_EDGE_x0 }
|
2006-09-29 05:57:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return array[ edge_table[a][b] ];
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_modpath::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2006-09-23 06:57:19 +02:00
|
|
|
{
|
|
|
|
|
/* Only the first port is used. */
|
|
|
|
|
if (port.port() > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (cur_vec4_.eeq(bit))
|
|
|
|
|
return;
|
|
|
|
|
|
2008-04-26 02:17:51 +02:00
|
|
|
/* Select a time delay source that applies. Notice that there
|
|
|
|
|
may be multiple delay sources that apply, so collect all
|
|
|
|
|
the candidates into a list first. */
|
|
|
|
|
list<vvp_fun_modpath_src*>candidate_list;
|
|
|
|
|
vvp_time64_t candidate_wake_time = 0;
|
2006-09-23 06:57:19 +02:00
|
|
|
for (vvp_fun_modpath_src*cur = src_list_ ; cur ; cur=cur->next_) {
|
2007-03-01 07:19:38 +01:00
|
|
|
/* Skip paths that are disabled by conditions. */
|
|
|
|
|
if (cur->condition_flag_ == false)
|
|
|
|
|
continue;
|
|
|
|
|
|
2008-04-26 02:17:51 +02:00
|
|
|
if (candidate_list.empty()) {
|
|
|
|
|
candidate_list.push_back(cur);
|
|
|
|
|
candidate_wake_time = cur->wake_time_;
|
|
|
|
|
} else if (cur->wake_time_ == candidate_wake_time) {
|
|
|
|
|
candidate_list.push_back(cur);
|
|
|
|
|
} else if (cur->wake_time_ > candidate_wake_time) {
|
|
|
|
|
candidate_list.assign(1, cur);
|
|
|
|
|
candidate_wake_time = cur->wake_time_;
|
2006-09-23 06:57:19 +02:00
|
|
|
} else {
|
|
|
|
|
continue; /* Skip this entry. */
|
|
|
|
|
}
|
2006-09-29 05:57:01 +02:00
|
|
|
}
|
2006-09-23 06:57:19 +02:00
|
|
|
|
2008-04-29 04:00:29 +02:00
|
|
|
/* Only add the ifnone delay if it has a later wake_time_ or
|
|
|
|
|
* if there are no normal delays. */
|
|
|
|
|
vvp_time64_t ifnone_wake_time = candidate_wake_time;
|
|
|
|
|
for (vvp_fun_modpath_src*cur = ifnone_list_ ; cur ; cur=cur->next_) {
|
|
|
|
|
if (candidate_list.empty()) {
|
|
|
|
|
candidate_list.push_back(cur);
|
|
|
|
|
ifnone_wake_time = cur->wake_time_;
|
|
|
|
|
} else if (cur->wake_time_ == ifnone_wake_time &&
|
|
|
|
|
ifnone_wake_time > candidate_wake_time) {
|
|
|
|
|
candidate_list.push_back(cur);
|
|
|
|
|
} else if (cur->wake_time_ > ifnone_wake_time) {
|
|
|
|
|
candidate_list.assign(1, cur);
|
|
|
|
|
ifnone_wake_time = cur->wake_time_;
|
|
|
|
|
} else {
|
|
|
|
|
continue; /* Skip this entry. */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-22 04:57:17 +01:00
|
|
|
/* Handle the special case that there are no delays that
|
|
|
|
|
match. This may happen, for example, if the set of
|
|
|
|
|
conditional delays is incomplete, leaving some cases
|
|
|
|
|
uncovered. In that case, just pass the data without delay */
|
2008-04-26 02:17:51 +02:00
|
|
|
if (candidate_list.empty()) {
|
2008-01-22 04:57:17 +01:00
|
|
|
cur_vec4_ = bit;
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-26 02:17:51 +02:00
|
|
|
/* Now given that we have a list of candidate delays, find for
|
|
|
|
|
each if the 12 numbers the minimum from all the
|
|
|
|
|
candidates. This minimum set becomes the chosen delay to
|
|
|
|
|
use. */
|
2006-09-29 05:57:01 +02:00
|
|
|
vvp_time64_t out_at[12];
|
|
|
|
|
vvp_time64_t now = schedule_simtime();
|
2008-04-26 02:17:51 +02:00
|
|
|
|
|
|
|
|
typedef list<vvp_fun_modpath_src*>::const_iterator iter_t;
|
|
|
|
|
|
|
|
|
|
iter_t cur = candidate_list.begin();
|
|
|
|
|
vvp_fun_modpath_src*src = *cur;
|
|
|
|
|
|
2006-09-29 05:57:01 +02:00
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1) {
|
|
|
|
|
out_at[idx] = src->wake_time_ + src->delay_[idx];
|
|
|
|
|
if (out_at[idx] <= now)
|
|
|
|
|
out_at[idx] = 0;
|
|
|
|
|
else
|
|
|
|
|
out_at[idx] -= now;
|
2006-09-23 06:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-30 05:38:23 +02:00
|
|
|
for (++ cur ; cur != candidate_list.end() ; ++ cur ) {
|
2008-04-26 02:17:51 +02:00
|
|
|
src = *cur;
|
|
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1) {
|
|
|
|
|
vvp_time64_t tmp = src->wake_time_ + src->delay_[idx];
|
|
|
|
|
if (tmp <= now)
|
|
|
|
|
tmp = 0;
|
|
|
|
|
else
|
|
|
|
|
tmp -= now;
|
|
|
|
|
if (tmp < out_at[idx])
|
|
|
|
|
out_at[idx] = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-23 06:57:19 +02:00
|
|
|
/* Given the scheduled output time, create an output event. */
|
2006-09-29 05:57:01 +02:00
|
|
|
vvp_time64_t use_delay = delay_from_edge(cur_vec4_.value(0),
|
|
|
|
|
bit.value(0),
|
|
|
|
|
out_at);
|
|
|
|
|
|
|
|
|
|
/* FIXME: This bases the edge delay on only the least
|
|
|
|
|
bit. This is WRONG! I need to find all the possible delays,
|
|
|
|
|
and schedule an event for each partial change. Hard! */
|
|
|
|
|
for (unsigned idx = 1 ; idx < bit.size() ; idx += 1) {
|
|
|
|
|
vvp_time64_t tmp = delay_from_edge(cur_vec4_.value(idx),
|
2015-10-22 07:00:50 +02:00
|
|
|
bit.value(idx),
|
2006-09-29 05:57:01 +02:00
|
|
|
out_at);
|
2015-10-22 07:00:50 +02:00
|
|
|
/* If the current and new bit values match then no delay
|
|
|
|
|
* is needed for this bit. */
|
|
|
|
|
if (cur_vec4_.value(idx) == bit.value(idx)) continue;
|
2024-12-31 17:59:23 +01:00
|
|
|
if (tmp != use_delay) {
|
|
|
|
|
fprintf(stderr, "sorry: multi-bit module path delays are "
|
|
|
|
|
"currently not fully supported.\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2006-09-29 05:57:01 +02:00
|
|
|
}
|
2006-09-23 06:57:19 +02:00
|
|
|
|
|
|
|
|
cur_vec4_ = bit;
|
|
|
|
|
schedule_generic(this, use_delay, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_modpath::run_run()
|
|
|
|
|
{
|
2009-04-04 05:40:26 +02:00
|
|
|
net_->send_vec4(cur_vec4_, 0);
|
2006-09-23 06:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-22 08:30:57 +02:00
|
|
|
vvp_fun_modpath_src::vvp_fun_modpath_src(vvp_time64_t const del[12])
|
2006-09-23 06:57:19 +02:00
|
|
|
{
|
2006-09-29 05:57:01 +02:00
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1)
|
2007-11-07 05:26:03 +01:00
|
|
|
delay_[idx] = del[idx];
|
2006-09-29 05:57:01 +02:00
|
|
|
|
2006-09-23 06:57:19 +02:00
|
|
|
next_ = 0;
|
|
|
|
|
wake_time_ = 0;
|
2007-03-01 07:19:38 +01:00
|
|
|
condition_flag_ = true;
|
2006-09-23 06:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_modpath_src::~vvp_fun_modpath_src()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-07 05:26:03 +01:00
|
|
|
void vvp_fun_modpath_src::get_delay12(vvp_time64_t val[12]) const
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1)
|
|
|
|
|
val[idx] = delay_[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_modpath_src::put_delay12(const vvp_time64_t val[12])
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1)
|
|
|
|
|
delay_[idx] = val[idx];
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_modpath_src::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2006-09-23 06:57:19 +02:00
|
|
|
{
|
2007-03-01 07:19:38 +01:00
|
|
|
if (port.port() == 0) {
|
|
|
|
|
// The modpath input...
|
2007-03-02 07:13:22 +01:00
|
|
|
if (test_vec4(bit))
|
|
|
|
|
wake_time_ = schedule_simtime();
|
2007-03-01 07:19:38 +01:00
|
|
|
|
|
|
|
|
} else if (port.port() == 1) {
|
|
|
|
|
// The modpath condition input...
|
|
|
|
|
if (bit.value(0) == BIT4_1)
|
|
|
|
|
condition_flag_ = true;
|
|
|
|
|
else
|
|
|
|
|
condition_flag_ = false;
|
|
|
|
|
}
|
2006-09-23 06:57:19 +02:00
|
|
|
}
|
2006-01-02 06:32:06 +01:00
|
|
|
|
2007-03-02 07:13:22 +01:00
|
|
|
bool vvp_fun_modpath_src::test_vec4(const vvp_vector4_t&)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_modpath_edge::vvp_fun_modpath_edge(vvp_time64_t del[12],
|
|
|
|
|
bool pos, bool neg)
|
|
|
|
|
: vvp_fun_modpath_src(del)
|
|
|
|
|
{
|
|
|
|
|
old_value_ = BIT4_X;
|
|
|
|
|
posedge_ = pos;
|
|
|
|
|
negedge_ = neg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool vvp_fun_modpath_edge::test_vec4(const vvp_vector4_t&bit)
|
|
|
|
|
{
|
|
|
|
|
vvp_bit4_t tmp = old_value_;
|
|
|
|
|
old_value_ = bit.value(0);
|
|
|
|
|
|
|
|
|
|
int edge_flag = edge(tmp, old_value_);
|
|
|
|
|
if (edge_flag > 0) return posedge_;
|
|
|
|
|
if (edge_flag < 0) return negedge_;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 04:14:40 +01:00
|
|
|
|
2001-11-10 19:07:11 +01:00
|
|
|
/*
|
2007-10-31 04:14:40 +01:00
|
|
|
* All the below routines that begin with
|
|
|
|
|
* modpath_src_* belong the internal function
|
|
|
|
|
* of an vpiModPathIn object. This is used to
|
|
|
|
|
* make some specific delays path operations
|
2005-11-10 14:27:16 +01:00
|
|
|
*
|
2007-10-31 04:14:40 +01:00
|
|
|
*/
|
2010-10-11 06:52:26 +02:00
|
|
|
static int modpath_src_get(int, vpiHandle ref)
|
2007-10-31 04:14:40 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc*obj =dynamic_cast<__vpiModPathSrc*>(ref);
|
2007-11-06 04:58:20 +01:00
|
|
|
assert(obj);
|
2010-10-11 06:52:26 +02:00
|
|
|
return 0;
|
2007-10-31 04:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 06:52:26 +02:00
|
|
|
static void modpath_src_get_value(vpiHandle ref, p_vpi_value)
|
2007-10-31 04:14:40 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc* modpathsrc = dynamic_cast<__vpiModPathSrc*>(ref);
|
2010-10-11 06:52:26 +02:00
|
|
|
assert(modpathsrc);
|
|
|
|
|
return;
|
2007-10-31 04:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 06:52:26 +02:00
|
|
|
static vpiHandle modpath_src_put_value(vpiHandle ref, s_vpi_value *, int )
|
2007-10-31 04:14:40 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc* modpathsrc = dynamic_cast<__vpiModPathSrc*>(ref);
|
2010-10-11 06:52:26 +02:00
|
|
|
assert(modpathsrc);
|
|
|
|
|
return 0;
|
2007-10-31 04:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle modpath_src_get_handle(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc*rfp = dynamic_cast<__vpiModPathSrc*>(ref);
|
2007-11-06 04:58:20 +01:00
|
|
|
assert(rfp);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
2007-10-31 04:14:40 +01:00
|
|
|
case vpiScope:
|
2012-01-19 19:16:39 +01:00
|
|
|
return rfp->dest->scope;
|
2007-11-06 04:58:20 +01:00
|
|
|
|
|
|
|
|
case vpiModule:
|
2015-12-27 20:37:10 +01:00
|
|
|
{ __vpiScope*scope = rfp->dest->scope;
|
2012-01-19 19:16:39 +01:00
|
|
|
while (scope && scope->get_type_code() != vpiModule)
|
2007-11-06 04:58:20 +01:00
|
|
|
scope = scope->scope;
|
|
|
|
|
assert(scope);
|
2012-01-19 19:16:39 +01:00
|
|
|
return scope;
|
2007-11-06 04:58:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-10-15 19:21:37 +02:00
|
|
|
// Handles to path term objects should really be obtained via
|
|
|
|
|
// the vpi_iterate and vpi_scan functions. Continue to allow
|
|
|
|
|
// them to be obtained here for backwards compatibility with
|
|
|
|
|
// older versions of Icarus Verilog.
|
2011-11-03 02:10:41 +01:00
|
|
|
|
2007-11-06 04:58:20 +01:00
|
|
|
case vpiModPathIn:
|
2012-01-19 19:16:39 +01:00
|
|
|
return &rfp->path_term_in;
|
2007-11-06 04:58:20 +01:00
|
|
|
|
|
|
|
|
case vpiModPathOut:
|
2012-01-19 19:16:39 +01:00
|
|
|
return &rfp->dest->path_term_out;
|
2008-02-16 00:05:39 +01:00
|
|
|
}
|
2007-10-31 04:14:40 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-15 19:21:37 +02:00
|
|
|
static vpiHandle modpath_src_iterate(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc*rfp = dynamic_cast<__vpiModPathSrc*>(ref);
|
2011-10-15 19:21:37 +02:00
|
|
|
assert(rfp);
|
|
|
|
|
|
|
|
|
|
// Module paths with multiple sources or destinations are
|
|
|
|
|
// currently represented by a separate modpath object for
|
|
|
|
|
// each source/destination combination, so there is only
|
|
|
|
|
// ever one input path term and one output path term.
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiModPathIn: {
|
2025-10-13 22:14:57 +02:00
|
|
|
vpiHandle*args = static_cast<vpiHandle*>(calloc(1, sizeof(vpiHandle*)));
|
2012-01-19 19:16:39 +01:00
|
|
|
args[0] = &rfp->path_term_in;
|
2011-10-15 19:21:37 +02:00
|
|
|
return vpip_make_iterator(1, args, true);
|
|
|
|
|
}
|
|
|
|
|
case vpiModPathOut: {
|
2025-10-13 22:14:57 +02:00
|
|
|
vpiHandle*args = static_cast<vpiHandle*>(calloc(1, sizeof(vpiHandle*)));
|
2012-01-19 19:16:39 +01:00
|
|
|
args[0] = &rfp->dest->path_term_out;
|
2011-10-15 19:21:37 +02:00
|
|
|
return vpip_make_iterator(1, args, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-11 06:52:26 +02:00
|
|
|
static vpiHandle modpath_src_index ( vpiHandle ref, int)
|
2007-10-31 04:14:40 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
assert(ref->get_type_code() == vpiModPathIn);
|
2010-10-11 06:52:26 +02:00
|
|
|
return 0;
|
2007-10-31 04:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-01-04 21:35:27 +01:00
|
|
|
* This routine will put specific dimension of delay[] values
|
2010-06-19 01:03:17 +02:00
|
|
|
* into a vpiHandle. In this case, we will put
|
2007-10-31 04:14:40 +01:00
|
|
|
* specific delays values in a vpiModPathIn object
|
2005-06-02 18:02:11 +02:00
|
|
|
*
|
2007-10-31 04:14:40 +01:00
|
|
|
*/
|
2008-03-11 05:54:58 +01:00
|
|
|
static void modpath_src_put_delays (vpiHandle ref, p_vpi_delay delays)
|
2007-10-31 04:14:40 +01:00
|
|
|
{
|
2007-11-07 05:26:03 +01:00
|
|
|
vvp_time64_t tmp[12];
|
|
|
|
|
int idx;
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc * src = dynamic_cast<__vpiModPathSrc*>(ref) ;
|
2007-11-06 04:58:20 +01:00
|
|
|
assert(src) ;
|
|
|
|
|
|
|
|
|
|
vvp_fun_modpath_src *fun = dynamic_cast<vvp_fun_modpath_src*>(src->net->fun);
|
2007-10-31 04:14:40 +01:00
|
|
|
assert( fun );
|
2007-11-23 02:34:51 +01:00
|
|
|
|
|
|
|
|
typedef unsigned char map_array_t[12];
|
2014-10-18 04:38:30 +02:00
|
|
|
// Only the first six entries are used for the less than twelve maps.
|
2014-10-19 00:25:17 +02:00
|
|
|
static const map_array_t map_1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
2014-10-18 04:38:30 +02:00
|
|
|
static const map_array_t map_2 = {0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0};
|
2014-10-18 05:04:39 +02:00
|
|
|
static const map_array_t map_3 = {0, 1, 2, 0, 2, 1, 0, 0, 0, 0, 0, 0};
|
2014-10-24 01:54:04 +02:00
|
|
|
static const map_array_t map_6 = {0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0};
|
2007-11-23 02:34:51 +01:00
|
|
|
static const map_array_t map12 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
|
|
|
|
|
|
|
|
|
const map_array_t*use_map = 0;
|
|
|
|
|
switch (delays->no_of_delays) {
|
2014-10-19 00:25:17 +02:00
|
|
|
case 1:
|
|
|
|
|
use_map = &map_1;
|
|
|
|
|
break;
|
2007-11-23 02:34:51 +01:00
|
|
|
case 2:
|
|
|
|
|
use_map = &map_2;
|
|
|
|
|
break;
|
2014-10-18 05:04:39 +02:00
|
|
|
case 3:
|
|
|
|
|
use_map = &map_3;
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
use_map = &map_6;
|
|
|
|
|
break;
|
2007-11-23 02:34:51 +01:00
|
|
|
case 12:
|
|
|
|
|
use_map = &map12;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-11-07 05:26:03 +01:00
|
|
|
|
2007-11-11 04:54:21 +01:00
|
|
|
if (delays->time_type == vpiSimTime) {
|
2007-11-23 02:34:51 +01:00
|
|
|
for (idx = 0 ; idx < 12 ; idx += 1) {
|
|
|
|
|
tmp[idx] = vpip_timestruct_to_time(delays->da+use_map[0][idx]);
|
2007-11-11 04:54:21 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2010-06-19 01:03:17 +02:00
|
|
|
// You cannot create a modpath with a negative delay so set it
|
|
|
|
|
// to zero per 1364-2005 section 14.3.1.
|
|
|
|
|
for (idx = 0 ; idx < delays->no_of_delays ; idx += 1) {
|
|
|
|
|
if (delays->da[idx].real < 0.0) delays->da[idx].real = 0.0;
|
|
|
|
|
}
|
2007-11-23 02:34:51 +01:00
|
|
|
for (idx = 0 ; idx < 12 ; idx += 1) {
|
|
|
|
|
tmp[idx] = vpip_scaled_real_to_time64(delays->da[use_map[0][idx]].real,
|
2007-11-11 04:54:21 +01:00
|
|
|
src->dest->scope);
|
|
|
|
|
}
|
2007-11-06 04:58:20 +01:00
|
|
|
}
|
2007-11-07 05:26:03 +01:00
|
|
|
|
2014-10-18 04:38:30 +02:00
|
|
|
/* Now define the to-from-x delays if needed. */
|
2007-11-23 02:34:51 +01:00
|
|
|
if (delays->no_of_delays <= 6) {
|
2014-10-18 04:38:30 +02:00
|
|
|
/* 0->x is the minimum of 0->z and 0->1. */
|
|
|
|
|
tmp[DELAY_EDGE_0x] = tmp[DELAY_EDGE_0z] < tmp[DELAY_EDGE_01] ?
|
|
|
|
|
tmp[DELAY_EDGE_0z] : tmp[DELAY_EDGE_01];
|
|
|
|
|
/* x->1 is the maximum of z->1 and 0->1. */
|
|
|
|
|
tmp[DELAY_EDGE_x1] = tmp[DELAY_EDGE_z1] > tmp[DELAY_EDGE_01] ?
|
|
|
|
|
tmp[DELAY_EDGE_z1] : tmp[DELAY_EDGE_01];
|
|
|
|
|
/* 1->x is the minimum of 1->z and 1->0. */
|
|
|
|
|
tmp[DELAY_EDGE_1x] = tmp[DELAY_EDGE_1z] < tmp[DELAY_EDGE_10] ?
|
|
|
|
|
tmp[DELAY_EDGE_1z] : tmp[DELAY_EDGE_10];
|
|
|
|
|
/* x->0 is the maximum of z->0 and 1->0. */
|
|
|
|
|
tmp[DELAY_EDGE_x0] = tmp[DELAY_EDGE_z0] > tmp[DELAY_EDGE_10] ?
|
|
|
|
|
tmp[DELAY_EDGE_z0] : tmp[DELAY_EDGE_10];
|
|
|
|
|
/* x->z is the maximum of 1->z and 0->z. */
|
|
|
|
|
tmp[DELAY_EDGE_xz] = tmp[DELAY_EDGE_1z] > tmp[DELAY_EDGE_0z] ?
|
|
|
|
|
tmp[DELAY_EDGE_1z] : tmp[DELAY_EDGE_0z];
|
|
|
|
|
/* z->x is the minimum of z->1 and z->0. */
|
|
|
|
|
tmp[DELAY_EDGE_zx] = tmp[DELAY_EDGE_z1] < tmp[DELAY_EDGE_z0] ?
|
|
|
|
|
tmp[DELAY_EDGE_z1] : tmp[DELAY_EDGE_z0];
|
2007-11-23 02:34:51 +01:00
|
|
|
}
|
|
|
|
|
|
2007-11-07 05:26:03 +01:00
|
|
|
fun->put_delay12(tmp);
|
2007-10-31 04:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2008-01-04 21:35:27 +01:00
|
|
|
* This routine will retrieve the delay[12] values
|
|
|
|
|
* of a vpiHandle. In this case, he will get an
|
2008-09-04 18:41:51 +02:00
|
|
|
* specific delays values from a vpiModPathIn
|
2007-10-31 04:14:40 +01:00
|
|
|
* object
|
2005-05-14 21:43:23 +02:00
|
|
|
*
|
2007-10-31 04:14:40 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void modpath_src_get_delays ( vpiHandle ref, p_vpi_delay delays )
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc*src = dynamic_cast<__vpiModPathSrc*>(ref) ;
|
2007-11-06 04:58:20 +01:00
|
|
|
assert(src);
|
|
|
|
|
|
|
|
|
|
vvp_fun_modpath_src *fun = dynamic_cast<vvp_fun_modpath_src*>(src->net->fun);
|
2007-11-07 05:26:03 +01:00
|
|
|
assert(fun);
|
2007-11-11 04:54:21 +01:00
|
|
|
|
|
|
|
|
int idx;
|
|
|
|
|
vvp_time64_t tmp[12];
|
|
|
|
|
fun->get_delay12(tmp);
|
|
|
|
|
|
2007-11-07 05:26:03 +01:00
|
|
|
switch (delays->no_of_delays) {
|
2009-02-10 04:21:50 +01:00
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
case 3:
|
|
|
|
|
case 6:
|
2007-11-07 05:26:03 +01:00
|
|
|
case 12:
|
2007-11-11 04:54:21 +01:00
|
|
|
break;
|
|
|
|
|
|
2007-11-07 05:26:03 +01:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
2007-11-11 04:54:21 +01:00
|
|
|
break;
|
2007-11-07 05:26:03 +01:00
|
|
|
}
|
2009-02-10 04:21:50 +01:00
|
|
|
|
|
|
|
|
if (delays->time_type == vpiSimTime) {
|
|
|
|
|
for (idx = 0; idx < delays->no_of_delays; idx += 1) {
|
|
|
|
|
vpip_time_to_timestruct(delays->da+idx, tmp[idx]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (idx = 0; idx < delays->no_of_delays; idx += 1) {
|
|
|
|
|
delays->da[idx].real = vpip_time_to_scaled_real(tmp[idx], src->dest->scope);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-31 04:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
2007-12-14 05:42:06 +01:00
|
|
|
static int pathterm_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathTerm*obj = dynamic_cast<__vpiModPathTerm*>(ref);
|
2007-12-14 05:42:06 +01:00
|
|
|
assert(obj);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiEdge:
|
|
|
|
|
return obj->edge;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-31 04:14:40 +01:00
|
|
|
|
2007-11-03 03:59:08 +01:00
|
|
|
static vpiHandle pathterm_get_handle(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathTerm*obj = dynamic_cast<__vpiModPathTerm*>(ref);
|
2007-11-03 03:59:08 +01:00
|
|
|
assert(obj);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiExpr:
|
|
|
|
|
return obj->expr;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-31 04:14:40 +01:00
|
|
|
|
|
|
|
|
/*
|
2007-11-06 04:58:20 +01:00
|
|
|
* The __vpiModPathSrc class is what the VPI client sees as a
|
|
|
|
|
* vpiModPath object. The __vpiModPath structure contains items that
|
|
|
|
|
* are common to a bunch of modpaths, including the destination term.
|
2007-10-31 04:14:40 +01:00
|
|
|
*/
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiModPathSrc::__vpiModPathSrc()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiModPathSrc::get_type_code(void) const
|
|
|
|
|
{ return vpiModPath; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiModPathSrc::vpi_get(int code)
|
|
|
|
|
{ return modpath_src_get(code, this); }
|
|
|
|
|
|
|
|
|
|
void __vpiModPathSrc::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{ modpath_src_get_value(this, val); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiModPathSrc::vpi_put_value(p_vpi_value val, int flags)
|
|
|
|
|
{ return modpath_src_put_value(this, val, flags); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiModPathSrc::vpi_handle(int code)
|
|
|
|
|
{ return modpath_src_get_handle(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiModPathSrc::vpi_iterate(int code)
|
|
|
|
|
{ return modpath_src_iterate(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiModPathSrc:: vpi_index(int idx)
|
|
|
|
|
{ return modpath_src_index(this, idx); }
|
|
|
|
|
|
|
|
|
|
void __vpiModPathSrc::vpi_get_delays(p_vpi_delay del)
|
|
|
|
|
{ modpath_src_get_delays(this, del); }
|
|
|
|
|
|
|
|
|
|
void __vpiModPathSrc::vpi_put_delays(p_vpi_delay del)
|
|
|
|
|
{ modpath_src_put_delays(this, del); }
|
|
|
|
|
|
2012-01-21 20:59:49 +01:00
|
|
|
static int modpath_src_free_object( vpiHandle ref )
|
|
|
|
|
{
|
|
|
|
|
delete ref;
|
|
|
|
|
return 1 ;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 23:15:26 +01:00
|
|
|
__vpiHandle::free_object_fun_t __vpiModPathSrc::free_object_fun(void)
|
|
|
|
|
{ return &modpath_src_free_object; }
|
2012-01-20 20:39:48 +01:00
|
|
|
|
2007-11-03 03:59:08 +01:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiModPathTerm::__vpiModPathTerm()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiModPathTerm::get_type_code(void) const
|
|
|
|
|
{ return vpiPathTerm; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiModPathTerm::vpi_get(int code)
|
|
|
|
|
{ return pathterm_get(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiModPathTerm::vpi_handle(int code)
|
|
|
|
|
{ return pathterm_get_handle(code, this); }
|
|
|
|
|
|
2007-11-03 03:59:08 +01:00
|
|
|
static void initialize_path_term(struct __vpiModPathTerm&obj)
|
|
|
|
|
{
|
|
|
|
|
obj.expr = 0;
|
2007-12-14 05:42:06 +01:00
|
|
|
obj.edge = vpiNoEdge;
|
2007-11-03 03:59:08 +01:00
|
|
|
}
|
|
|
|
|
|
2007-10-31 04:14:40 +01:00
|
|
|
/*
|
2008-01-04 21:35:27 +01:00
|
|
|
* This function will construct a vpiModPath Object.
|
2007-10-31 04:14:40 +01:00
|
|
|
* give a respective "net", and will point to his
|
|
|
|
|
* respective functor
|
|
|
|
|
*/
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
static struct __vpiModPath**mp_list = 0;
|
|
|
|
|
static unsigned mp_count = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-11-06 04:58:20 +01:00
|
|
|
struct __vpiModPath* vpip_make_modpath(vvp_net_t *net)
|
2007-10-31 04:14:40 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPath*obj = new __vpiModPath;
|
2007-11-06 04:58:20 +01:00
|
|
|
obj->scope = vpip_peek_current_scope ( );
|
2007-11-03 03:59:08 +01:00
|
|
|
|
|
|
|
|
initialize_path_term(obj->path_term_out);
|
2007-11-06 04:58:20 +01:00
|
|
|
obj->input_net = net ;
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
mp_count += 1;
|
2025-10-13 22:14:57 +02:00
|
|
|
mp_list = static_cast<struct __vpiModPath **>
|
|
|
|
|
(realloc(static_cast<void*>(mp_list),
|
|
|
|
|
mp_count*sizeof(struct __vpiModPath **)));
|
2009-01-30 02:23:09 +01:00
|
|
|
mp_list[mp_count-1] = obj;
|
|
|
|
|
#endif
|
2007-11-06 04:58:20 +01:00
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void modpath_delete()
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0; idx < mp_count; idx += 1) {
|
2012-10-09 03:52:24 +02:00
|
|
|
delete mp_list[idx];
|
2009-01-30 02:23:09 +01:00
|
|
|
}
|
|
|
|
|
free(mp_list);
|
|
|
|
|
mp_list = 0;
|
|
|
|
|
mp_count = 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2007-11-06 04:58:20 +01:00
|
|
|
|
|
|
|
|
/*
|
2008-09-04 18:41:51 +02:00
|
|
|
* This function will construct a vpiModPathIn
|
2007-11-06 04:58:20 +01:00
|
|
|
* ( struct __vpiModPathSrc ) Object. will give
|
|
|
|
|
* a delays[12] values, and point to the specified functor
|
|
|
|
|
*
|
|
|
|
|
*/
|
2007-10-31 04:14:40 +01:00
|
|
|
|
2010-10-11 06:52:26 +02:00
|
|
|
struct __vpiModPathSrc* vpip_make_modpath_src(struct __vpiModPath*path,
|
|
|
|
|
vvp_net_t *net)
|
2007-11-06 04:58:20 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiModPathSrc *obj = new __vpiModPathSrc;
|
2007-10-31 04:14:40 +01:00
|
|
|
|
2007-11-06 04:58:20 +01:00
|
|
|
obj->dest = path;
|
2012-01-19 19:16:39 +01:00
|
|
|
obj->type = 0;
|
2007-11-06 04:58:20 +01:00
|
|
|
obj->net = net;
|
|
|
|
|
initialize_path_term(obj->path_term_in);
|
2007-10-31 04:14:40 +01:00
|
|
|
|
2007-11-06 04:58:20 +01:00
|
|
|
return obj;
|
2007-10-31 04:14:40 +01:00
|
|
|
}
|
2023-07-19 15:02:20 +02:00
|
|
|
|
|
|
|
|
vvp_fun_intermodpath::vvp_fun_intermodpath(vvp_net_t*net, unsigned width)
|
|
|
|
|
: net_(net)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1)
|
2023-08-17 16:09:20 +02:00
|
|
|
delay_[idx] = 0;
|
2023-07-19 15:02:20 +02:00
|
|
|
|
|
|
|
|
cur_vec4_ = vvp_vector4_t(width, BIT4_X);
|
2023-08-17 16:09:20 +02:00
|
|
|
schedule_init_propagate(net_, cur_vec4_);
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_intermodpath::~vvp_fun_intermodpath()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_intermodpath::get_delay12(vvp_time64_t val[12]) const
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1)
|
|
|
|
|
val[idx] = delay_[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_intermodpath::put_delay12(const vvp_time64_t val[12])
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < 12 ; idx += 1)
|
|
|
|
|
delay_[idx] = val[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* FIXME: this implementation currently only uses the maximum delay
|
|
|
|
|
* from all the bit changes in the vectors. If there are multiple
|
|
|
|
|
* changes with different delays, then the results would be
|
|
|
|
|
* wrong. What should happen is that if there are multiple changes,
|
|
|
|
|
* multiple vectors approaching the result should be scheduled.
|
|
|
|
|
*/
|
|
|
|
|
void vvp_fun_intermodpath::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
|
|
|
|
{
|
|
|
|
|
/* Only the first port is used. */
|
|
|
|
|
if (port.port() > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (cur_vec4_.eeq(bit))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Given the scheduled output time, create an output event. */
|
|
|
|
|
vvp_time64_t use_delay = delay_from_edge(cur_vec4_.value(0),
|
|
|
|
|
bit.value(0),
|
|
|
|
|
delay_);
|
|
|
|
|
|
|
|
|
|
/* FIXME: This bases the edge delay on only the least
|
|
|
|
|
bit. This is WRONG! I need to find all the possible delays,
|
|
|
|
|
and schedule an event for each partial change. Hard! */
|
|
|
|
|
for (unsigned idx = 1 ; idx < bit.size() ; idx += 1) {
|
|
|
|
|
vvp_time64_t tmp = delay_from_edge(cur_vec4_.value(idx),
|
|
|
|
|
bit.value(idx),
|
|
|
|
|
delay_);
|
|
|
|
|
/* If the current and new bit values match then no delay
|
|
|
|
|
* is needed for this bit. */
|
|
|
|
|
if (cur_vec4_.value(idx) == bit.value(idx)) continue;
|
|
|
|
|
assert(tmp == use_delay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur_vec4_ = bit;
|
|
|
|
|
schedule_generic(this, use_delay, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_intermodpath::run_run()
|
|
|
|
|
{
|
|
|
|
|
net_->send_vec4(cur_vec4_, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* All the below routines that begin with
|
|
|
|
|
* intermodpath_* belong the internal function
|
|
|
|
|
* of an vpiInterModPath object. This is used to
|
|
|
|
|
* make some specific delays path operations
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static int intermodpath_get(int, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiInterModPath*obj =dynamic_cast<__vpiInterModPath*>(ref);
|
|
|
|
|
assert(obj);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void intermodpath_get_value(vpiHandle ref, p_vpi_value)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiInterModPath* intermodpath = dynamic_cast<__vpiInterModPath*>(ref);
|
|
|
|
|
assert(intermodpath);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle intermodpath_put_value(vpiHandle ref, s_vpi_value *, int )
|
|
|
|
|
{
|
|
|
|
|
struct __vpiInterModPath* intermodpath = dynamic_cast<__vpiInterModPath*>(ref);
|
|
|
|
|
assert(intermodpath);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle intermodpath_get_handle(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiInterModPath*rfp = dynamic_cast<__vpiInterModPath*>(ref);
|
|
|
|
|
assert(rfp);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiScope:
|
|
|
|
|
return rfp->scope;
|
|
|
|
|
|
|
|
|
|
case vpiModule:
|
|
|
|
|
{ __vpiScope*scope = rfp->scope;
|
|
|
|
|
while (scope && scope->get_type_code() != vpiModule)
|
|
|
|
|
scope = scope->scope;
|
|
|
|
|
assert(scope);
|
|
|
|
|
return scope;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle intermodpath_iterate(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiInterModPath*rfp = dynamic_cast<__vpiInterModPath*>(ref);
|
|
|
|
|
assert(rfp);
|
|
|
|
|
|
|
|
|
|
// For now intermodpaths only support exactly two ports
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiPort: {
|
2025-10-13 22:14:57 +02:00
|
|
|
vpiHandle*args = static_cast<vpiHandle*>(calloc(2, sizeof(vpiHandle*)));
|
2023-07-19 15:02:20 +02:00
|
|
|
args[0] = rfp->port1;
|
|
|
|
|
args[1] = rfp->port2;
|
|
|
|
|
return vpip_make_iterator(2, args, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This routine will put specific dimension of delay[] values
|
|
|
|
|
* into a vpiHandle. In this case, we will put
|
|
|
|
|
* specific delays values in a vpiInterModPath object
|
2023-08-17 16:09:20 +02:00
|
|
|
*
|
2023-07-19 15:02:20 +02:00
|
|
|
*/
|
|
|
|
|
static void intermodpath_put_delays (vpiHandle ref, p_vpi_delay delays)
|
|
|
|
|
{
|
|
|
|
|
vvp_time64_t tmp[12];
|
|
|
|
|
int idx;
|
|
|
|
|
struct __vpiInterModPath * src = dynamic_cast<__vpiInterModPath*>(ref) ;
|
|
|
|
|
assert(src) ;
|
|
|
|
|
|
|
|
|
|
vvp_fun_intermodpath *fun = dynamic_cast<vvp_fun_intermodpath*>(src->net->fun);
|
|
|
|
|
assert( fun );
|
|
|
|
|
|
|
|
|
|
typedef unsigned char map_array_t[12];
|
|
|
|
|
// Only the first six entries are used for the less than twelve maps.
|
|
|
|
|
static const map_array_t map_1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
|
static const map_array_t map_2 = {0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0};
|
|
|
|
|
static const map_array_t map_3 = {0, 1, 2, 0, 2, 1, 0, 0, 0, 0, 0, 0};
|
|
|
|
|
static const map_array_t map_6 = {0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0};
|
|
|
|
|
static const map_array_t map12 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
|
|
|
|
|
|
|
|
|
const map_array_t*use_map = 0;
|
|
|
|
|
switch (delays->no_of_delays) {
|
|
|
|
|
case 1:
|
|
|
|
|
use_map = &map_1;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
use_map = &map_2;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
use_map = &map_3;
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
use_map = &map_6;
|
|
|
|
|
break;
|
|
|
|
|
case 12:
|
|
|
|
|
use_map = &map12;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (delays->time_type == vpiSimTime) {
|
|
|
|
|
for (idx = 0 ; idx < 12 ; idx += 1) {
|
|
|
|
|
tmp[idx] = vpip_timestruct_to_time(delays->da+use_map[0][idx]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// You cannot create a modpath with a negative delay so set it
|
|
|
|
|
// to zero per 1364-2005 section 14.3.1.
|
|
|
|
|
for (idx = 0 ; idx < delays->no_of_delays ; idx += 1) {
|
|
|
|
|
if (delays->da[idx].real < 0.0) delays->da[idx].real = 0.0;
|
|
|
|
|
}
|
|
|
|
|
for (idx = 0 ; idx < 12 ; idx += 1) {
|
|
|
|
|
tmp[idx] = vpip_scaled_real_to_time64(delays->da[use_map[0][idx]].real,
|
|
|
|
|
src->scope);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now define the to-from-x delays if needed. */
|
|
|
|
|
if (delays->no_of_delays <= 6) {
|
|
|
|
|
/* 0->x is the minimum of 0->z and 0->1. */
|
|
|
|
|
tmp[DELAY_EDGE_0x] = tmp[DELAY_EDGE_0z] < tmp[DELAY_EDGE_01] ?
|
|
|
|
|
tmp[DELAY_EDGE_0z] : tmp[DELAY_EDGE_01];
|
|
|
|
|
/* x->1 is the maximum of z->1 and 0->1. */
|
|
|
|
|
tmp[DELAY_EDGE_x1] = tmp[DELAY_EDGE_z1] > tmp[DELAY_EDGE_01] ?
|
|
|
|
|
tmp[DELAY_EDGE_z1] : tmp[DELAY_EDGE_01];
|
|
|
|
|
/* 1->x is the minimum of 1->z and 1->0. */
|
|
|
|
|
tmp[DELAY_EDGE_1x] = tmp[DELAY_EDGE_1z] < tmp[DELAY_EDGE_10] ?
|
|
|
|
|
tmp[DELAY_EDGE_1z] : tmp[DELAY_EDGE_10];
|
|
|
|
|
/* x->0 is the maximum of z->0 and 1->0. */
|
|
|
|
|
tmp[DELAY_EDGE_x0] = tmp[DELAY_EDGE_z0] > tmp[DELAY_EDGE_10] ?
|
|
|
|
|
tmp[DELAY_EDGE_z0] : tmp[DELAY_EDGE_10];
|
|
|
|
|
/* x->z is the maximum of 1->z and 0->z. */
|
|
|
|
|
tmp[DELAY_EDGE_xz] = tmp[DELAY_EDGE_1z] > tmp[DELAY_EDGE_0z] ?
|
|
|
|
|
tmp[DELAY_EDGE_1z] : tmp[DELAY_EDGE_0z];
|
|
|
|
|
/* z->x is the minimum of z->1 and z->0. */
|
|
|
|
|
tmp[DELAY_EDGE_zx] = tmp[DELAY_EDGE_z1] < tmp[DELAY_EDGE_z0] ?
|
|
|
|
|
tmp[DELAY_EDGE_z1] : tmp[DELAY_EDGE_z0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun->put_delay12(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This routine will retrieve the delay[12] values
|
|
|
|
|
* of a vpiHandle. In this case, he will get an
|
|
|
|
|
* specific delays values from a vpiInterModPath
|
|
|
|
|
* object
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void intermodpath_get_delays ( vpiHandle ref, p_vpi_delay delays )
|
|
|
|
|
{
|
|
|
|
|
struct __vpiInterModPath*src = dynamic_cast<__vpiInterModPath*>(ref) ;
|
|
|
|
|
assert(src);
|
|
|
|
|
|
|
|
|
|
vvp_fun_intermodpath *fun = dynamic_cast<vvp_fun_intermodpath*>(src->net->fun);
|
|
|
|
|
assert(fun);
|
|
|
|
|
|
|
|
|
|
int idx;
|
|
|
|
|
vvp_time64_t tmp[12];
|
|
|
|
|
fun->get_delay12(tmp);
|
|
|
|
|
|
|
|
|
|
switch (delays->no_of_delays) {
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
case 3:
|
|
|
|
|
case 6:
|
|
|
|
|
case 12:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (delays->time_type == vpiSimTime) {
|
|
|
|
|
for (idx = 0; idx < delays->no_of_delays; idx += 1) {
|
|
|
|
|
vpip_time_to_timestruct(delays->da+idx, tmp[idx]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (idx = 0; idx < delays->no_of_delays; idx += 1) {
|
|
|
|
|
delays->da[idx].real = vpip_time_to_scaled_real(tmp[idx], src->scope);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The __vpiInterModPath class is what the VPI client sees as a
|
|
|
|
|
* vpiInterModPath object.
|
|
|
|
|
*/
|
|
|
|
|
inline __vpiInterModPath::__vpiInterModPath()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
int __vpiInterModPath::get_type_code(void) const
|
|
|
|
|
{ return vpiInterModPath; }
|
|
|
|
|
|
|
|
|
|
int __vpiInterModPath::vpi_get(int code)
|
|
|
|
|
{ return intermodpath_get(code, this); }
|
|
|
|
|
|
|
|
|
|
void __vpiInterModPath::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{ intermodpath_get_value(this, val); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiInterModPath::vpi_put_value(p_vpi_value val, int flags)
|
|
|
|
|
{ return intermodpath_put_value(this, val, flags); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiInterModPath::vpi_handle(int code)
|
|
|
|
|
{ return intermodpath_get_handle(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiInterModPath::vpi_iterate(int code)
|
|
|
|
|
{ return intermodpath_iterate(code, this); }
|
|
|
|
|
|
|
|
|
|
void __vpiInterModPath::vpi_get_delays(p_vpi_delay del)
|
|
|
|
|
{ intermodpath_get_delays(this, del); }
|
|
|
|
|
|
|
|
|
|
void __vpiInterModPath::vpi_put_delays(p_vpi_delay del)
|
|
|
|
|
{ intermodpath_put_delays(this, del); }
|
|
|
|
|
|
|
|
|
|
static int intermodpath_free_object( vpiHandle ref )
|
|
|
|
|
{
|
|
|
|
|
delete ref;
|
|
|
|
|
return 1 ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__vpiHandle::free_object_fun_t __vpiInterModPath::free_object_fun(void)
|
|
|
|
|
{ return &intermodpath_free_object; }
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function will construct a vpiInterModPath Object.
|
|
|
|
|
* give a respective "net", and will point to his
|
|
|
|
|
* respective functor
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
static struct __vpiInterModPath**imp_list = 0;
|
|
|
|
|
static unsigned imp_count = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct __vpiInterModPath* vpip_make_intermodpath(vvp_net_t *net, vpiPortInfo* port1, vpiPortInfo* port2)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiInterModPath*obj = new __vpiInterModPath;
|
|
|
|
|
obj->scope = vpip_peek_current_scope ( );
|
|
|
|
|
|
|
|
|
|
obj->net = net;
|
|
|
|
|
obj->port1 = port1;
|
|
|
|
|
obj->port2 = port2;
|
|
|
|
|
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
imp_count += 1;
|
2025-10-13 22:14:57 +02:00
|
|
|
imp_list = static_cast<struct __vpiInterModPath **>
|
|
|
|
|
(realloc(static_cast<void>(imp_list),
|
|
|
|
|
imp_count*sizeof(struct __vpiInterModPath **)));
|
2023-07-19 15:02:20 +02:00
|
|
|
imp_list[imp_count-1] = obj;
|
|
|
|
|
#endif
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void intermodpath_delete()
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0; idx < mp_count; idx += 1) {
|
|
|
|
|
delete imp_list[idx];
|
|
|
|
|
}
|
|
|
|
|
free(imp_list);
|
|
|
|
|
imp_list = 0;
|
|
|
|
|
imp_count = 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|