2008-11-29 19:05:31 +01:00
|
|
|
/*
|
2011-06-12 14:10:16 +02:00
|
|
|
* Copyright (c) 2008-2011 Stephen Williams (steve@icarus.com)
|
2008-11-29 19:05:31 +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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "vvp_island.h"
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "symbols.h"
|
|
|
|
|
# include "schedule.h"
|
|
|
|
|
# include <list>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
class vvp_island_tran : public vvp_island {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void run_island();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct vvp_island_branch_tran : public vvp_island_branch {
|
|
|
|
|
|
2010-10-11 00:14:29 +02:00
|
|
|
vvp_island_branch_tran(vvp_net_t*en__, bool active_high__,
|
|
|
|
|
unsigned width__, unsigned part__,
|
|
|
|
|
unsigned offset__);
|
2008-11-29 19:05:31 +01:00
|
|
|
bool run_test_enabled();
|
|
|
|
|
void run_resolution();
|
2011-06-12 14:10:16 +02:00
|
|
|
void run_output();
|
2009-02-16 21:07:29 +01:00
|
|
|
|
2010-10-11 00:14:29 +02:00
|
|
|
vvp_net_t*en;
|
|
|
|
|
unsigned width, part, offset;
|
|
|
|
|
bool active_high;
|
|
|
|
|
bool enabled_flag;
|
2008-11-29 19:05:31 +01:00
|
|
|
};
|
|
|
|
|
|
2010-10-11 00:14:29 +02:00
|
|
|
vvp_island_branch_tran::vvp_island_branch_tran(vvp_net_t*en__,
|
|
|
|
|
bool active_high__,
|
|
|
|
|
unsigned width__,
|
|
|
|
|
unsigned part__,
|
|
|
|
|
unsigned offset__)
|
|
|
|
|
: en(en__), width(width__), part(part__), offset(offset__),
|
|
|
|
|
active_high(active_high__)
|
|
|
|
|
{
|
|
|
|
|
enabled_flag = en__ ? false : true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-29 19:05:31 +01:00
|
|
|
static inline vvp_island_branch_tran* BRANCH_TRAN(vvp_island_branch*tmp)
|
|
|
|
|
{
|
|
|
|
|
vvp_island_branch_tran*res = dynamic_cast<vvp_island_branch_tran*>(tmp);
|
|
|
|
|
assert(res);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-16 21:07:29 +01:00
|
|
|
/*
|
|
|
|
|
* The run_island() method is called by the scheduler to run the
|
|
|
|
|
* entire island. We run the island by calling run_resolution() for
|
|
|
|
|
* all the branches in the island.
|
|
|
|
|
*/
|
2008-11-29 19:05:31 +01:00
|
|
|
void vvp_island_tran::run_island()
|
|
|
|
|
{
|
2009-02-16 21:07:29 +01:00
|
|
|
// Test to see if any of the branches are enabled. This loop
|
2009-10-14 04:01:02 +02:00
|
|
|
// tests the enabled inputs for all the branches and caches
|
2011-06-12 14:10:16 +02:00
|
|
|
// the results in the enabled_flag for each branch.
|
2008-11-29 19:05:31 +01:00
|
|
|
bool runnable = false;
|
|
|
|
|
for (vvp_island_branch*cur = branches_ ; cur ; cur = cur->next_branch) {
|
|
|
|
|
vvp_island_branch_tran*tmp = dynamic_cast<vvp_island_branch_tran*>(cur);
|
|
|
|
|
assert(tmp);
|
|
|
|
|
runnable |= tmp->run_test_enabled();
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-16 21:07:29 +01:00
|
|
|
// Now resolve all the branches in the island.
|
2008-11-29 19:05:31 +01:00
|
|
|
for (vvp_island_branch*cur = branches_ ; cur ; cur = cur->next_branch) {
|
|
|
|
|
vvp_island_branch_tran*tmp = dynamic_cast<vvp_island_branch_tran*>(cur);
|
|
|
|
|
assert(tmp);
|
|
|
|
|
tmp->run_resolution();
|
|
|
|
|
}
|
2011-06-12 14:10:16 +02:00
|
|
|
|
|
|
|
|
// Now output the resolved values.
|
|
|
|
|
for (vvp_island_branch*cur = branches_ ; cur ; cur = cur->next_branch) {
|
|
|
|
|
vvp_island_branch_tran*tmp = dynamic_cast<vvp_island_branch_tran*>(cur);
|
|
|
|
|
assert(tmp);
|
|
|
|
|
tmp->run_output();
|
|
|
|
|
}
|
2008-11-29 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool vvp_island_branch_tran::run_test_enabled()
|
|
|
|
|
{
|
|
|
|
|
vvp_island_port*ep = en? dynamic_cast<vvp_island_port*> (en->fun) : 0;
|
|
|
|
|
|
|
|
|
|
// If there is no ep port (no "enabled" input) then this is a
|
|
|
|
|
// tran branch. Assume it is always enabled.
|
|
|
|
|
if (ep == 0) {
|
|
|
|
|
enabled_flag = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-14 04:01:02 +02:00
|
|
|
// Get the input that is driving this enable.
|
|
|
|
|
// SPECIAL NOTE: Try to get the input value from the
|
|
|
|
|
// *outvalue* of the port. If the enable is connected to a
|
|
|
|
|
// .port (instead of a .import) then there may be feedback
|
|
|
|
|
// going on, and we need to be looking at the resolved input,
|
|
|
|
|
// not the event input. For example:
|
|
|
|
|
//
|
|
|
|
|
// tranif1 (pin, X, pin);
|
|
|
|
|
//
|
|
|
|
|
// In this case, when we test the value for "pin", we need to
|
|
|
|
|
// look at the value that is resolved from this
|
|
|
|
|
// island. Reading the outvalue will do the trick.
|
|
|
|
|
//
|
|
|
|
|
// If the outvalue is nil, then we know that this port is a
|
|
|
|
|
// .import after all, so just read the invalue.
|
2008-11-29 19:05:31 +01:00
|
|
|
enabled_flag = false;
|
2009-10-07 21:58:19 +02:00
|
|
|
vvp_bit4_t enable_val;
|
2009-10-14 04:01:02 +02:00
|
|
|
if (ep->outvalue.size() != 0)
|
|
|
|
|
enable_val = ep->outvalue.value(0).value();
|
|
|
|
|
else if (ep->invalue.size() == 0)
|
2009-10-07 21:58:19 +02:00
|
|
|
enable_val = BIT4_Z;
|
|
|
|
|
else
|
|
|
|
|
enable_val = ep->invalue.value(0).value();
|
2008-11-29 19:05:31 +01:00
|
|
|
|
|
|
|
|
if (active_high==true && enable_val != BIT4_1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (active_high==false && enable_val != BIT4_0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
enabled_flag = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
static void push_value_through_branches(const vvp_vector8_t&val,
|
|
|
|
|
list<vvp_branch_ptr_t>&connections);
|
2009-02-16 21:07:29 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
static void push_value_through_branch(const vvp_vector8_t&val,
|
|
|
|
|
vvp_branch_ptr_t cur)
|
2008-11-29 19:05:31 +01:00
|
|
|
{
|
2011-06-12 14:10:16 +02:00
|
|
|
vvp_island_branch_tran*branch = BRANCH_TRAN(cur.ptr());
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
// If the branch is not enabled, skip.
|
|
|
|
|
if (! branch->enabled_flag)
|
|
|
|
|
return;
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
unsigned src_ab = cur.port();
|
|
|
|
|
unsigned dst_ab = src_ab^1;
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
vvp_net_t*dst_net = dst_ab? branch->b : branch->a;
|
|
|
|
|
vvp_island_port*dst_port = dynamic_cast<vvp_island_port*>(dst_net->fun);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
vvp_vector8_t old_val = dst_port->value;
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
// If the port on the other side has not yet been visited,
|
|
|
|
|
// get its input value.
|
|
|
|
|
if (dst_port->value.size() == 0)
|
|
|
|
|
dst_port->value = island_get_value(dst_net);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
// If we don't yet have an initial value for the port, skip.
|
|
|
|
|
if (dst_port->value.size() == 0)
|
|
|
|
|
return;
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
// Now resolve the pushed value with whatever values we have
|
|
|
|
|
// previously collected (and resolved) for the port.
|
|
|
|
|
if (branch->width == 0) {
|
|
|
|
|
// There are no part selects.
|
|
|
|
|
dst_port->value = resolve(dst_port->value, val);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
} else if (dst_ab == 1) {
|
|
|
|
|
// The other side is a strict subset (part select)
|
|
|
|
|
// of this side.
|
|
|
|
|
vvp_vector8_t tmp = val.subvalue(branch->offset, branch->part);
|
|
|
|
|
dst_port->value = resolve(dst_port->value, tmp);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
} else {
|
|
|
|
|
// The other side is a superset of this side.
|
|
|
|
|
vvp_vector8_t tmp = part_expand(val, branch->width, branch->offset);
|
|
|
|
|
dst_port->value = resolve(dst_port->value, tmp);
|
2008-11-29 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
// If the resolved value for the port has changed, push the new
|
|
|
|
|
// value back into the network.
|
|
|
|
|
if (! dst_port->value.eeq(old_val)) {
|
|
|
|
|
list<vvp_branch_ptr_t> connections;
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
vvp_branch_ptr_t dst_side(branch, dst_ab);
|
|
|
|
|
island_collect_node(connections, dst_side);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
push_value_through_branches(dst_port->value, connections);
|
2008-11-29 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void push_value_through_branches(const vvp_vector8_t&val,
|
|
|
|
|
list<vvp_branch_ptr_t>&connections)
|
|
|
|
|
{
|
|
|
|
|
for (list<vvp_branch_ptr_t>::iterator idx = connections.begin()
|
2010-10-23 23:57:59 +02:00
|
|
|
; idx != connections.end() ; ++ idx ) {
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
push_value_through_branch(val, *idx);
|
2008-11-29 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-16 21:07:29 +01:00
|
|
|
/*
|
|
|
|
|
* This method resolves the value for a branch recursively. It uses
|
2011-06-12 14:10:16 +02:00
|
|
|
* recursive descent to span the graph of branches, pushing values
|
|
|
|
|
* through the network until a stable state is reached.
|
2009-02-16 21:07:29 +01:00
|
|
|
*/
|
2008-11-29 19:05:31 +01:00
|
|
|
void vvp_island_branch_tran::run_resolution()
|
|
|
|
|
{
|
|
|
|
|
list<vvp_branch_ptr_t> connections;
|
2011-06-12 14:10:16 +02:00
|
|
|
vvp_island_port*port;
|
|
|
|
|
|
|
|
|
|
// If the A side port hasn't already been visited, then push
|
|
|
|
|
// its input value through all the branches connected to it.
|
|
|
|
|
port = dynamic_cast<vvp_island_port*>(a->fun);
|
|
|
|
|
if (port->value.size() == 0) {
|
2008-11-29 19:05:31 +01:00
|
|
|
vvp_branch_ptr_t a_side(this, 0);
|
|
|
|
|
island_collect_node(connections, a_side);
|
|
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
port->value = island_get_value(a);
|
|
|
|
|
if (port->value.size() != 0)
|
|
|
|
|
push_value_through_branches(port->value, connections);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
connections.clear();
|
2008-11-29 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
// Do the same for the B side port. Note that if the branch
|
|
|
|
|
// is enabled, the B side port will have already been visited
|
|
|
|
|
// when we resolved the A side port.
|
|
|
|
|
port = dynamic_cast<vvp_island_port*>(b->fun);
|
|
|
|
|
if (port->value.size() == 0) {
|
|
|
|
|
vvp_branch_ptr_t b_side(this, 1);
|
|
|
|
|
island_collect_node(connections, b_side);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
port->value = island_get_value(b);
|
|
|
|
|
if (port->value.size() != 0)
|
|
|
|
|
push_value_through_branches(port->value, connections);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
connections.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
void vvp_island_branch_tran::run_output()
|
|
|
|
|
{
|
|
|
|
|
vvp_island_port*port;
|
|
|
|
|
|
|
|
|
|
// If the A side port hasn't already been updated, send the
|
|
|
|
|
// resolved value to the output.
|
|
|
|
|
port = dynamic_cast<vvp_island_port*>(a->fun);
|
|
|
|
|
if (port->value.size() != 0) {
|
|
|
|
|
island_send_value(a, port->value);
|
|
|
|
|
port->value = vvp_vector8_t::nil;
|
2008-11-29 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-12 14:10:16 +02:00
|
|
|
// Do the same for the B side port.
|
|
|
|
|
port = dynamic_cast<vvp_island_port*>(b->fun);
|
|
|
|
|
if (port->value.size() != 0) {
|
|
|
|
|
island_send_value(b, port->value);
|
|
|
|
|
port->value = vvp_vector8_t::nil;
|
|
|
|
|
}
|
2008-11-29 19:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_island_tran(char*label)
|
|
|
|
|
{
|
|
|
|
|
vvp_island*use_island = new vvp_island_tran;
|
|
|
|
|
compile_island_base(label, use_island);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_island_tranif(int sense, char*island, char*pa, char*pb, char*pe)
|
|
|
|
|
{
|
|
|
|
|
vvp_island*use_island = compile_find_island(island);
|
|
|
|
|
assert(use_island);
|
|
|
|
|
free(island);
|
|
|
|
|
|
2010-10-11 00:14:29 +02:00
|
|
|
vvp_net_t*en = NULL;
|
2008-11-29 19:05:31 +01:00
|
|
|
|
2010-10-11 00:14:29 +02:00
|
|
|
if (pe) {
|
|
|
|
|
en = use_island->find_port(pe);
|
|
|
|
|
assert(en);
|
2008-11-29 19:05:31 +01:00
|
|
|
free(pe);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-11 00:14:29 +02:00
|
|
|
vvp_island_branch_tran*br = new vvp_island_branch_tran(en,
|
|
|
|
|
sense ? true :
|
|
|
|
|
false,
|
|
|
|
|
0, 0, 0);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
|
|
|
|
use_island->add_branch(br, pa, pb);
|
|
|
|
|
|
|
|
|
|
free(pa);
|
|
|
|
|
free(pb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void compile_island_tranvp(char*island, char*pa, char*pb,
|
|
|
|
|
unsigned wid, unsigned par, unsigned off)
|
|
|
|
|
{
|
|
|
|
|
vvp_island*use_island = compile_find_island(island);
|
|
|
|
|
assert(use_island);
|
|
|
|
|
free(island);
|
|
|
|
|
|
2010-10-11 00:14:29 +02:00
|
|
|
vvp_island_branch_tran*br = new vvp_island_branch_tran(NULL, false,
|
2011-06-12 14:10:16 +02:00
|
|
|
wid, par, off);
|
2008-11-29 19:05:31 +01:00
|
|
|
|
|
|
|
|
use_island->add_branch(br, pa, pb);
|
|
|
|
|
|
|
|
|
|
free(pa);
|
|
|
|
|
free(pb);
|
|
|
|
|
}
|