2001-05-09 04:53:25 +02:00
|
|
|
/*
|
2021-11-04 18:02:07 +01:00
|
|
|
* Copyright (c) 2001-2021 Stephen Williams (steve@icarus.com)
|
2001-05-09 04:53:25 +02: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-05-09 04:53:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "resolv.h"
|
|
|
|
|
# include "schedule.h"
|
2007-07-12 06:38:56 +02:00
|
|
|
# include "compile.h"
|
2002-07-05 22:08:44 +02:00
|
|
|
# include "statistics.h"
|
2005-04-13 08:34:20 +02:00
|
|
|
# include <iostream>
|
2012-07-10 22:15:34 +02:00
|
|
|
# include <algorithm>
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cassert>
|
2001-05-09 04:53:25 +02:00
|
|
|
|
2021-11-04 18:02:07 +01:00
|
|
|
using namespace std;
|
2001-05-30 05:02:35 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
/*
|
|
|
|
|
* The core functor for a resolver node stores all the input values
|
|
|
|
|
* received by that node. This provides the necessary information
|
2015-06-02 19:40:24 +02:00
|
|
|
* for implementing the $countdrivers system call. For efficiency,
|
2012-07-10 22:15:34 +02:00
|
|
|
* the resolver is implemented using a balanced quaternary tree, so
|
|
|
|
|
* the core functor also stores the current value for each branch
|
|
|
|
|
* of the tree, to eliminate the need to re-evaluate branches whose
|
|
|
|
|
* inputs haven't changed. The tree values are flattened into a linear
|
|
|
|
|
* array, with the input values stored at the start of the array, then
|
|
|
|
|
* the next level of branch values, and so on, down to the final array
|
|
|
|
|
* array element which stores the current output value.
|
|
|
|
|
*/
|
2001-05-12 22:38:06 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
|
|
|
|
|
resolv_core::resolv_core(unsigned nports, vvp_net_t*net)
|
|
|
|
|
: nports_(nports), net_(net)
|
2001-12-15 02:54:38 +01:00
|
|
|
{
|
2012-07-10 22:15:34 +02:00
|
|
|
count_functors_resolv += 1;
|
2001-12-15 02:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
resolv_core::~resolv_core()
|
2001-12-15 02:54:38 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
void resolv_core::recv_vec4_pv_(unsigned port, const vvp_vector4_t&bit,
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned base, unsigned vwid)
|
2005-01-09 21:11:15 +01:00
|
|
|
{
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned wid = bit.size();
|
2005-01-09 21:11:15 +01:00
|
|
|
vvp_vector4_t res (vwid);
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < base ; idx += 1)
|
|
|
|
|
res.set_bit(idx, BIT4_Z);
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
for (unsigned idx = 0 ; idx < wid && idx+base < vwid; idx += 1)
|
2005-01-09 21:11:15 +01:00
|
|
|
res.set_bit(idx+base, bit.value(idx));
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = base+wid ; idx < vwid ; idx += 1)
|
|
|
|
|
res.set_bit(idx, BIT4_Z);
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
recv_vec4_(port, res);
|
2005-01-09 21:11:15 +01:00
|
|
|
}
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
void resolv_core::recv_vec8_pv_(unsigned port, const vvp_vector8_t&bit,
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned base, unsigned vwid)
|
2001-05-09 04:53:25 +02:00
|
|
|
{
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned wid = bit.size();
|
2012-07-10 22:15:34 +02:00
|
|
|
vvp_vector8_t res (vwid);
|
2001-12-06 04:31:24 +01:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
for (unsigned idx = 0 ; idx < base ; idx += 1)
|
|
|
|
|
res.set_bit(idx, vvp_scalar_t());
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid && idx+base < vwid; idx += 1)
|
|
|
|
|
res.set_bit(idx+base, bit.value(idx));
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = base+wid ; idx < vwid ; idx += 1)
|
|
|
|
|
res.set_bit(idx, vvp_scalar_t());
|
2005-06-15 02:47:15 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
recv_vec8_(port, res);
|
|
|
|
|
}
|
2001-12-06 04:31:24 +01:00
|
|
|
|
2001-05-09 04:53:25 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
resolv_extend::resolv_extend(resolv_core*core, unsigned port_base)
|
|
|
|
|
: core_(core), port_base_(port_base)
|
|
|
|
|
{
|
|
|
|
|
}
|
2004-12-11 03:31:25 +01:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
resolv_extend::~resolv_extend()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resolv_tri::resolv_tri(unsigned nports, vvp_net_t*net, vvp_scalar_t hiz_value)
|
|
|
|
|
: resolv_core(nports, net), hiz_value_(hiz_value)
|
|
|
|
|
{
|
|
|
|
|
// count the input (leaf) nodes
|
|
|
|
|
unsigned nnodes = nports;
|
|
|
|
|
|
|
|
|
|
// add in the intermediate branch nodes
|
|
|
|
|
while (nports > 4) {
|
|
|
|
|
nports = (nports + 3) / 4;
|
|
|
|
|
nnodes += nports;
|
2005-02-13 06:26:30 +01:00
|
|
|
}
|
2012-07-10 22:15:34 +02:00
|
|
|
// add one more node for storing the output value
|
|
|
|
|
// (not needed if there is only one input)
|
|
|
|
|
if (nnodes > 1)
|
|
|
|
|
nnodes += 1;
|
2005-02-13 06:26:30 +01:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
val_ = new vvp_vector8_t [nnodes];
|
|
|
|
|
}
|
2007-07-12 06:38:56 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
resolv_tri::~resolv_tri()
|
|
|
|
|
{
|
|
|
|
|
delete[] val_;
|
2004-12-11 03:31:25 +01:00
|
|
|
}
|
2008-04-21 04:21:41 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
void resolv_tri::recv_vec4_(unsigned port, const vvp_vector4_t&bit)
|
2008-07-17 02:58:34 +02:00
|
|
|
{
|
2012-07-10 22:15:34 +02:00
|
|
|
recv_vec8_(port, vvp_vector8_t(bit, 6,6 /* STRONG */));
|
|
|
|
|
}
|
2008-07-17 02:58:34 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
void resolv_tri::recv_vec8_(unsigned port, const vvp_vector8_t&bit)
|
|
|
|
|
{
|
|
|
|
|
assert(port < nports_);
|
2008-07-17 02:58:34 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
if (val_[port].eeq(bit))
|
|
|
|
|
return;
|
2008-07-17 02:58:34 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
val_[port] = bit;
|
|
|
|
|
|
|
|
|
|
// Starting at the leaf level, work down the tree, resolving
|
|
|
|
|
// the changed values. base is the first node in the current
|
|
|
|
|
// level and span is the number of nodes at that level. ip
|
|
|
|
|
// is the first node in the group of four nodes at that level
|
|
|
|
|
// that include the node that has changed, and op is the node
|
|
|
|
|
// at the next level that stores the resolved value from that
|
|
|
|
|
// group.
|
|
|
|
|
unsigned base = 0;
|
|
|
|
|
unsigned span = nports_;
|
|
|
|
|
while (span > 1) {
|
|
|
|
|
unsigned next_base = base + span;
|
|
|
|
|
unsigned ip = base + (port & ~0x3);
|
|
|
|
|
unsigned op = next_base + (port / 4);
|
|
|
|
|
unsigned ll = min(ip + 4, next_base);
|
|
|
|
|
|
|
|
|
|
vvp_vector8_t out = val_[ip];
|
|
|
|
|
for (ip = ip + 1; ip < ll; ip += 1) {
|
|
|
|
|
if (val_[ip].size() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (out.size() == 0)
|
|
|
|
|
out = val_[ip];
|
|
|
|
|
else
|
|
|
|
|
out = resolve(out, val_[ip]);
|
|
|
|
|
}
|
|
|
|
|
if (val_[op].eeq(out))
|
|
|
|
|
return;
|
|
|
|
|
val_[op] = out;
|
|
|
|
|
|
|
|
|
|
base = next_base;
|
|
|
|
|
span = (span + 3) / 4;
|
|
|
|
|
port = port / 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! hiz_value_.is_hiz()) {
|
|
|
|
|
for (unsigned idx = 0 ; idx < val_[base].size() ; idx += 1) {
|
2013-10-25 20:55:04 +02:00
|
|
|
val_[base].set_bit(idx, resolve(val_[base].value(idx),
|
|
|
|
|
hiz_value_));
|
2012-07-10 22:15:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
2008-07-17 02:58:34 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
net_->send_vec8(val_[base]);
|
2008-07-17 02:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-10 23:33:17 +02:00
|
|
|
void resolv_tri::count_drivers(unsigned bit_idx, unsigned counts[3])
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < nports_ ; idx += 1) {
|
|
|
|
|
if (val_[idx].size() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
update_driver_counts(val_[idx].value(bit_idx).value(), counts);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
|
|
|
|
|
resolv_wired_logic::resolv_wired_logic(unsigned nports, vvp_net_t*net)
|
|
|
|
|
: resolv_core(nports, net)
|
2008-04-21 04:21:41 +02:00
|
|
|
{
|
2012-07-10 22:15:34 +02:00
|
|
|
// count the input (leaf) nodes
|
|
|
|
|
unsigned nnodes = nports;
|
|
|
|
|
|
|
|
|
|
// add in the intermediate branch nodes
|
|
|
|
|
while (nports > 4) {
|
|
|
|
|
nports = (nports + 3) / 4;
|
|
|
|
|
nnodes += nports;
|
|
|
|
|
}
|
|
|
|
|
// add one more node for storing the output value
|
|
|
|
|
// (not needed if there is only one input)
|
|
|
|
|
if (nnodes > 1)
|
|
|
|
|
nnodes += 1;
|
|
|
|
|
|
|
|
|
|
val_ = new vvp_vector4_t [nnodes];
|
2008-04-21 04:21:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolv_wired_logic::~resolv_wired_logic()
|
|
|
|
|
{
|
2012-07-10 22:15:34 +02:00
|
|
|
delete[] val_;
|
2008-04-21 04:21:41 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
void resolv_wired_logic::recv_vec4_(unsigned port, const vvp_vector4_t&bit)
|
2008-04-21 04:21:41 +02:00
|
|
|
{
|
2012-07-10 22:15:34 +02:00
|
|
|
assert(port < nports_);
|
2008-04-21 04:21:41 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
if (val_[port].eeq(bit))
|
2008-04-21 04:21:41 +02:00
|
|
|
return;
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
val_[port] = bit;
|
|
|
|
|
|
|
|
|
|
// Starting at the leaf level, work down the tree, resolving
|
|
|
|
|
// the changed values. base is the first node in the current
|
|
|
|
|
// level and span is the number of nodes at that level. ip
|
|
|
|
|
// is the first node in the group of four nodes at that level
|
|
|
|
|
// that include the node that has changed, and op is the node
|
|
|
|
|
// at the next level that stores the resolved value from that
|
|
|
|
|
// group.
|
|
|
|
|
unsigned base = 0;
|
|
|
|
|
unsigned span = nports_;
|
|
|
|
|
while (span > 1) {
|
|
|
|
|
unsigned next_base = base + span;
|
|
|
|
|
unsigned ip = base + (port & ~0x3);
|
|
|
|
|
unsigned op = next_base + (port / 4);
|
|
|
|
|
unsigned ll = min(ip + 4, next_base);
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t out = val_[ip];
|
|
|
|
|
for (ip = ip + 1; ip < ll; ip += 1) {
|
|
|
|
|
if (val_[ip].size() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (out.size() == 0)
|
|
|
|
|
out = val_[ip];
|
|
|
|
|
else
|
|
|
|
|
out = wired_logic_math_(out, val_[ip]);
|
|
|
|
|
}
|
|
|
|
|
if (val_[op].eeq(out))
|
|
|
|
|
return;
|
|
|
|
|
val_[op] = out;
|
|
|
|
|
|
|
|
|
|
base = next_base;
|
|
|
|
|
span = (span + 3) / 4;
|
|
|
|
|
port = port / 4;
|
|
|
|
|
}
|
2008-04-21 04:21:41 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
net_->send_vec4(val_[base], 0);
|
|
|
|
|
}
|
2008-04-21 04:21:41 +02:00
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
void resolv_wired_logic::recv_vec8_(unsigned port, const vvp_vector8_t&bit)
|
|
|
|
|
{
|
|
|
|
|
recv_vec4_(port, reduce4(bit));
|
|
|
|
|
}
|
2008-04-21 04:21:41 +02:00
|
|
|
|
2012-07-10 23:33:17 +02:00
|
|
|
void resolv_wired_logic::count_drivers(unsigned bit_idx, unsigned counts[3])
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < nports_ ; idx += 1) {
|
|
|
|
|
if (val_[idx].size() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
update_driver_counts(val_[idx].value(bit_idx), counts);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
|
|
|
|
|
resolv_triand::resolv_triand(unsigned nports, vvp_net_t*net)
|
|
|
|
|
: resolv_wired_logic(nports, net)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolv_triand::~resolv_triand()
|
|
|
|
|
{
|
2008-04-21 04:21:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t resolv_triand::wired_logic_math_(vvp_vector4_t&a, vvp_vector4_t&b)
|
|
|
|
|
{
|
|
|
|
|
assert(a.size() == b.size());
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t out (a.size());
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < out.size() ; idx += 1) {
|
|
|
|
|
vvp_bit4_t abit = a.value(idx);
|
|
|
|
|
vvp_bit4_t bbit = b.value(idx);
|
|
|
|
|
if (abit == BIT4_Z) {
|
|
|
|
|
out.set_bit(idx, bbit);
|
|
|
|
|
} else if (bbit == BIT4_Z) {
|
|
|
|
|
out.set_bit(idx, abit);
|
|
|
|
|
} else if (abit == BIT4_0 || bbit == BIT4_0) {
|
|
|
|
|
out.set_bit(idx, BIT4_0);
|
|
|
|
|
} else if (abit == BIT4_X || bbit == BIT4_X) {
|
|
|
|
|
out.set_bit(idx, BIT4_X);
|
|
|
|
|
} else {
|
|
|
|
|
out.set_bit(idx, BIT4_1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-10 22:15:34 +02:00
|
|
|
|
|
|
|
|
resolv_trior::resolv_trior(unsigned nports, vvp_net_t*net)
|
|
|
|
|
: resolv_wired_logic(nports, net)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolv_trior::~resolv_trior()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-21 04:21:41 +02:00
|
|
|
vvp_vector4_t resolv_trior::wired_logic_math_(vvp_vector4_t&a, vvp_vector4_t&b)
|
|
|
|
|
{
|
|
|
|
|
assert(a.size() == b.size());
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t out (a.size());
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < out.size() ; idx += 1) {
|
|
|
|
|
vvp_bit4_t abit = a.value(idx);
|
|
|
|
|
vvp_bit4_t bbit = b.value(idx);
|
|
|
|
|
if (abit == BIT4_Z) {
|
|
|
|
|
out.set_bit(idx, bbit);
|
|
|
|
|
} else if (bbit == BIT4_Z) {
|
|
|
|
|
out.set_bit(idx, abit);
|
|
|
|
|
} else if (abit == BIT4_1 || bbit == BIT4_1) {
|
|
|
|
|
out.set_bit(idx, BIT4_1);
|
|
|
|
|
} else if (abit == BIT4_X || bbit == BIT4_X) {
|
|
|
|
|
out.set_bit(idx, BIT4_X);
|
|
|
|
|
} else {
|
|
|
|
|
out.set_bit(idx, BIT4_0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|