Skip to content

Commit

Permalink
NetConst can now hold wide constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve committed Dec 17, 1999
1 parent d355270 commit 65ae928
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 113 deletions.
52 changes: 29 additions & 23 deletions cprop.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: cprop.cc,v 1.2 1998/12/02 04:37:13 steve Exp $"
#ident "$Id: cprop.cc,v 1.3 1999/12/17 03:38:46 steve Exp $"
#endif

# include "netlist.h"
Expand All @@ -35,7 +35,7 @@ static bool is_a_const_node(const NetNode*obj)
return dynamic_cast<const NetConst*>(obj);
}

static bool const_into_xnor(Design*des, NetConst*obj,
static bool const_into_xnor(Design*des, verinum::V cval,
NetLogic*log, unsigned pin)
{
assert(pin > 0);
Expand All @@ -44,7 +44,7 @@ static bool const_into_xnor(Design*des, NetConst*obj,
the device is simply buffering the constant value. */
if (log->pin_count() == 2) {
cerr << "cprop: delete gate " << log->name() <<
" and propogate " << obj->value() << "." << endl;
" and propogate " << cval << "." << endl;

assert(pin == 1);
connect(log->pin(0), log->pin(1));
Expand All @@ -55,7 +55,7 @@ static bool const_into_xnor(Design*des, NetConst*obj,

/* If this is a constant 0, then replace the gate with one
1-pin smaller. Skip this pin. */
if (obj->value() == verinum::V0) {
if (cval == verinum::V0) {
cerr << "cprop: disconnect pin " << pin << " from gate "
<< log->name() << "." << endl;

Expand All @@ -78,7 +78,7 @@ static bool const_into_xnor(Design*des, NetConst*obj,
/* If this is a constant 1, then replace the gate with an XOR
that is 1-pin smaller. Removing the constant 1 causes the
sense of the output to change. */
if (obj->value() == verinum::V1) {
if (cval == verinum::V1) {
cerr << "cprop: disconnect pin " << pin << " from gate "
<< log->name() << "." << endl;

Expand All @@ -101,7 +101,7 @@ static bool const_into_xnor(Design*des, NetConst*obj,
/* If this is a constant X or Z, then the gate is certain to
generate an X. Replace the gate with a constant X. This may
cause other signals all over to become dangling. */
if ((obj->value() == verinum::Vx) || (obj->value() == verinum::Vz)) {
if ((cval == verinum::Vx) || (cval == verinum::Vz)) {
cerr << "cprop: replace gate " << log->name() << " with "
"a constant X." << endl;

Expand All @@ -115,11 +115,11 @@ static bool const_into_xnor(Design*des, NetConst*obj,
return false;
}

static void look_for_core_logic(Design*des, NetConst*obj)
static void look_for_core_logic(Design*des, NetConst*obj, unsigned cpin)
{
NetObj*cur = obj;
unsigned pin = 0;
for (obj->pin(0).next_link(cur, pin)
for (obj->pin(cpin).next_link(cur, pin)
; cur != obj
; cur->pin(pin).next_link(cur, pin)) {

Expand All @@ -130,7 +130,7 @@ static void look_for_core_logic(Design*des, NetConst*obj)
bool flag = false;
switch (log->type()) {
case NetLogic::XNOR:
flag = const_into_xnor(des, obj, log, pin);
flag = const_into_xnor(des, obj->value(cpin), log, pin);
break;
default:
break;
Expand All @@ -151,23 +151,25 @@ static void dangling_const(Design*des, NetConst*obj)
{
// If there are any links that take input, abort this
// operation.
if (count_inputs(obj->pin(0)) > 0)
return;
for (unsigned idx = 0 ; idx < obj->pin_count() ; idx += 1)
if (count_inputs(obj->pin(idx)) > 0)
return;

// If there are no other drivers, delete all the signals that
// are also dangling.
if (count_outputs(obj->pin(0)) == 1) {

NetObj*cur;
unsigned pin;
obj->pin(0).next_link(cur, pin);
while (cur != obj) {
cerr << "cprop: delete dangling signal " << cur->name() <<
"." << endl;
delete cur;
obj->pin(0).next_link(cur, pin);
for (unsigned idx = 0 ; idx < obj->pin_count() ; idx += 1)
if (count_outputs(obj->pin(idx)) == 1) {

NetObj*cur;
unsigned pin;
obj->pin(idx).next_link(cur, pin);
while (cur != obj) {
cerr << "cprop: delete dangling signal " <<
cur->name() << "." << endl;
delete cur;
obj->pin(idx).next_link(cur, pin);
}
}
}

// Done. Delete me.
delete obj;
Expand All @@ -178,7 +180,8 @@ void cprop(Design*des)
des->clear_node_marks();
while (NetNode*obj = des->find_node(&is_a_const_node)) {
NetConst*cur = dynamic_cast<NetConst*>(obj);
look_for_core_logic(des, cur);
for (unsigned idx = 0 ; idx < cur->pin_count() ; idx += 1)
look_for_core_logic(des, cur, idx);
cur->set_mark();
dangling_const(des, cur);
}
Expand All @@ -187,6 +190,9 @@ void cprop(Design*des)

/*
* $Log: cprop.cc,v $
* Revision 1.3 1999/12/17 03:38:46 steve
* NetConst can now hold wide constants.
*
* Revision 1.2 1998/12/02 04:37:13 steve
* Add the nobufz function to eliminate bufz objects,
* Object links are marked with direction,
Expand Down
10 changes: 8 additions & 2 deletions design_dump.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: design_dump.cc,v 1.63 1999/12/12 06:03:14 steve Exp $"
#ident "$Id: design_dump.cc,v 1.64 1999/12/17 03:38:46 steve Exp $"
#endif

/*
Expand Down Expand Up @@ -189,7 +189,10 @@ void NetCaseCmp::dump_node(ostream&o, unsigned ind) const

void NetConst::dump_node(ostream&o, unsigned ind) const
{
o << setw(ind) << "" << "constant " << value_ << ": " << name() << endl;
o << setw(ind) << "" << "constant ";
for (unsigned idx = pin_count() ; idx > 0 ; idx -= 1)
o << value_[idx-1];
o << ": " << name() << endl;
dump_node_pins(o, ind+4);
}

Expand Down Expand Up @@ -862,6 +865,9 @@ void Design::dump(ostream&o) const

/*
* $Log: design_dump.cc,v $
* Revision 1.64 1999/12/17 03:38:46 steve
* NetConst can now hold wide constants.
*
* Revision 1.63 1999/12/12 06:03:14 steve
* Allow memories without indices in expressions.
*
Expand Down
26 changes: 13 additions & 13 deletions elab_net.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: elab_net.cc,v 1.13 1999/12/16 03:46:39 steve Exp $"
#ident "$Id: elab_net.cc,v 1.14 1999/12/17 03:38:46 steve Exp $"
#endif

# include "PExpr.h"
Expand Down Expand Up @@ -641,12 +641,11 @@ NetNet* PEIdent::elaborate_net(Design*des, const string&path,
verinum pvalue = pc->value();
sig = new NetNet(0, path+"."+text_, NetNet::IMPLICIT,
pc->expr_width());
for (unsigned idx = 0; idx < sig->pin_count(); idx += 1) {
NetConst*cp = new NetConst(des->local_symbol(path),
pvalue[idx]);
connect(sig->pin(idx), cp->pin(0));
des->add_node(cp);
}
NetConst*cp = new NetConst(des->local_symbol(path), pvalue);
des->add_node(cp);
des->add_signal(sig);
for (unsigned idx = 0; idx < sig->pin_count(); idx += 1)
connect(sig->pin(idx), cp->pin(idx));

} else {

Expand Down Expand Up @@ -886,13 +885,11 @@ NetNet* PENumber::elaborate_net(Design*des, const string&path,
NetNet*net = new NetNet(0, des->local_symbol(path),
NetNet::IMPLICIT, width);
net->local_flag(true);
for (unsigned idx = 0 ; idx < width ; idx += 1) {
NetConst*tmp = new NetConst(des->local_symbol(path),
value_->get(idx));
des->add_node(tmp);
connect(net->pin(idx), tmp->pin(0));
}
NetConst*tmp = new NetConst(des->local_symbol(path), *value_);
for (unsigned idx = 0 ; idx < width ; idx += 1)
connect(net->pin(idx), tmp->pin(idx));

des->add_node(tmp);
des->add_signal(net);
return net;
}
Expand Down Expand Up @@ -941,6 +938,9 @@ NetNet* PETernary::elaborate_net(Design*des, const string&path,

/*
* $Log: elab_net.cc,v $
* Revision 1.14 1999/12/17 03:38:46 steve
* NetConst can now hold wide constants.
*
* Revision 1.13 1999/12/16 03:46:39 steve
* Structural logical or.
*
Expand Down
16 changes: 9 additions & 7 deletions expr_synth.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: expr_synth.cc,v 1.6 1999/11/28 23:42:02 steve Exp $"
#ident "$Id: expr_synth.cc,v 1.7 1999/12/17 03:38:46 steve Exp $"
#endif

# include "netlist.h"
Expand Down Expand Up @@ -125,12 +125,11 @@ NetNet* NetEConst::synthesize(Design*des)
unsigned width=expr_width();

NetNet*osig = new NetNet(0, path, NetNet::IMPLICIT, width);
for (unsigned idx = 0 ; idx < width; idx += 1) {
string oname = des->local_symbol(path);
NetConst *c = new NetConst(oname, value().get(idx));
connect(osig->pin(idx), c->pin(0));
des->add_node(c);
}
NetConst*con = new NetConst(des->local_symbol(path), value());
for (unsigned idx = 0 ; idx < width; idx += 1)
connect(osig->pin(idx), con->pin(idx));

des->add_node(con);
des->add_signal(osig);
return osig;
}
Expand Down Expand Up @@ -200,6 +199,9 @@ NetNet* NetESignal::synthesize(Design*des)

/*
* $Log: expr_synth.cc,v $
* Revision 1.7 1999/12/17 03:38:46 steve
* NetConst can now hold wide constants.
*
* Revision 1.6 1999/11/28 23:42:02 steve
* NetESignal object no longer need to be NetNode
* objects. Let them keep a pointer to NetNet objects.
Expand Down
27 changes: 25 additions & 2 deletions netlist.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: netlist.cc,v 1.100 1999/12/16 02:42:15 steve Exp $"
#ident "$Id: netlist.cc,v 1.101 1999/12/17 03:38:46 steve Exp $"
#endif

# include <cassert>
Expand Down Expand Up @@ -1489,14 +1489,34 @@ NetProc* NetCondit::else_clause()
}

NetConst::NetConst(const string&n, verinum::V v)
: NetNode(n, 1), value_(v)
: NetNode(n, 1)
{
pin(0).set_dir(Link::OUTPUT);
pin(0).set_name("O", 0);
value_ = new verinum::V[1];
value_[0] = v;
}

NetConst::NetConst(const string&n, const verinum&val)
: NetNode(n, val.len())
{
value_ = new verinum::V[pin_count()];
for (unsigned idx = 0 ; idx < pin_count() ; idx += 1) {
pin(idx).set_dir(Link::OUTPUT);
pin(idx).set_name("O", idx);
value_[idx] = val.get(idx);
}
}

NetConst::~NetConst()
{
delete[]value_;
}

verinum::V NetConst::value(unsigned idx) const
{
assert(idx < pin_count());
return value_[idx];
}

NetFuncDef::NetFuncDef(const string&n, const svector<NetNet*>&po)
Expand Down Expand Up @@ -2744,6 +2764,9 @@ NetNet* Design::find_signal(bool (*func)(const NetNet*))

/*
* $Log: netlist.cc,v $
* Revision 1.101 1999/12/17 03:38:46 steve
* NetConst can now hold wide constants.
*
* Revision 1.100 1999/12/16 02:42:15 steve
* Simulate carry output on adders.
*
Expand Down
19 changes: 15 additions & 4 deletions netlist.h
Expand Up @@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: netlist.h,v 1.102 1999/12/16 02:42:15 steve Exp $"
#ident "$Id: netlist.h,v 1.103 1999/12/17 03:38:46 steve Exp $"
#endif

/*
Expand Down Expand Up @@ -707,20 +707,28 @@ class NetCaseCmp : public NetNode {
virtual void emit_node(ostream&, struct target_t*) const;
};


/*
* This class represents instances of the LPM_CONSTANT device. The
* node has only outputs and a constant value. The width is available
* by getting the pin_count(), and the value bits are available one at
* a time. There is no meaning to the aggregation of bits to form a
* wide NetConst object, although some targets may have an easier time
* detecting interesting constructs if they are combined.
*/
class NetConst : public NetNode {

public:
explicit NetConst(const string&n, verinum::V v);
explicit NetConst(const string&n, const verinum&val);
~NetConst();

verinum::V value() const { return value_; }
verinum::V value(unsigned idx) const;

virtual void emit_node(ostream&, struct target_t*) const;
virtual void dump_node(ostream&, unsigned ind) const;

private:
verinum::V value_;
verinum::V*value_;
};

/*
Expand Down Expand Up @@ -2070,6 +2078,9 @@ extern ostream& operator << (ostream&, NetNet::Type);

/*
* $Log: netlist.h,v $
* Revision 1.103 1999/12/17 03:38:46 steve
* NetConst can now hold wide constants.
*
* Revision 1.102 1999/12/16 02:42:15 steve
* Simulate carry output on adders.
*
Expand Down

0 comments on commit 65ae928

Please sign in to comment.