1999-09-29 02:42:50 +02:00
|
|
|
/*
|
2011-02-10 06:03:08 +01:00
|
|
|
* Copyright (c) 1999-2011 Stephen Williams (steve@icarus.com)
|
1999-09-29 02:42:50 +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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
2001-07-25 05:10:48 +02:00
|
|
|
# include "config.h"
|
|
|
|
|
|
1999-09-29 02:42:50 +02:00
|
|
|
# include "netlist.h"
|
|
|
|
|
# include "netmisc.h"
|
|
|
|
|
|
2007-10-16 05:17:06 +02:00
|
|
|
|
1999-09-29 02:42:50 +02:00
|
|
|
/*
|
2003-01-27 06:09:17 +01:00
|
|
|
* This function transforms an expression by padding the high bits
|
1999-09-29 02:42:50 +02:00
|
|
|
* with V0 until the expression has the desired width. This may mean
|
|
|
|
|
* not transforming the expression at all, if it is already wide
|
|
|
|
|
* enough.
|
|
|
|
|
*/
|
2008-11-19 02:17:19 +01:00
|
|
|
NetExpr*pad_to_width(NetExpr*expr, unsigned wid, const LineInfo&info)
|
1999-09-29 02:42:50 +02:00
|
|
|
{
|
2002-05-25 18:43:22 +02:00
|
|
|
if (wid <= expr->expr_width())
|
|
|
|
|
return expr;
|
|
|
|
|
|
|
|
|
|
/* If the expression is a const, then replace it with a wider
|
|
|
|
|
const. This is a more efficient result. */
|
|
|
|
|
if (NetEConst*tmp = dynamic_cast<NetEConst*>(expr)) {
|
2007-10-16 05:17:06 +02:00
|
|
|
verinum oval = pad_to_width(tmp->value(), wid);
|
2002-05-25 18:43:22 +02:00
|
|
|
tmp = new NetEConst(oval);
|
2008-11-19 02:17:19 +01:00
|
|
|
tmp->set_line(info);
|
2002-05-25 18:43:22 +02:00
|
|
|
delete expr;
|
|
|
|
|
return tmp;
|
1999-09-29 02:42:50 +02:00
|
|
|
}
|
2002-05-25 18:43:22 +02:00
|
|
|
|
2005-12-22 16:43:47 +01:00
|
|
|
NetESelect*tmp = new NetESelect(expr, 0, wid);
|
2008-11-19 02:17:19 +01:00
|
|
|
tmp->set_line(info);
|
2005-12-22 16:43:47 +01:00
|
|
|
tmp->cast_signed(expr->has_sign());
|
|
|
|
|
return tmp;
|
1999-09-29 02:42:50 +02:00
|
|
|
}
|
|
|
|
|
|
2005-01-12 04:17:36 +01:00
|
|
|
/*
|
|
|
|
|
* Pad a NetNet to the desired vector width by concatenating a
|
|
|
|
|
* NetConst of constant zeros. Use a NetConcat node to do the
|
|
|
|
|
* concatenation.
|
|
|
|
|
*/
|
2008-11-19 02:17:19 +01:00
|
|
|
NetNet*pad_to_width(Design*des, NetNet*net, unsigned wid, const LineInfo&info)
|
2000-02-16 04:58:27 +01:00
|
|
|
{
|
2001-02-15 07:59:35 +01:00
|
|
|
NetScope*scope = net->scope();
|
2000-05-02 02:58:11 +02:00
|
|
|
|
2005-01-12 04:17:36 +01:00
|
|
|
if (net->vector_width() >= wid)
|
2000-02-16 04:58:27 +01:00
|
|
|
return net;
|
|
|
|
|
|
2005-01-12 04:17:36 +01:00
|
|
|
// Make the NetConcat and connect the input net to the lsb input.
|
|
|
|
|
NetConcat*cc = new NetConcat(scope, scope->local_symbol(), wid, 2);
|
2011-02-10 06:03:08 +01:00
|
|
|
cc->set_line(info);
|
2005-01-12 04:17:36 +01:00
|
|
|
des->add_node(cc);
|
|
|
|
|
connect(cc->pin(1), net->pin(0));
|
|
|
|
|
|
|
|
|
|
// Make a NetConst of the desired width and connect in to the
|
|
|
|
|
// lsb input of the NetConcat.
|
|
|
|
|
verinum pad(verinum::V0, wid - net->vector_width());
|
2004-02-18 18:11:54 +01:00
|
|
|
NetConst*con = new NetConst(scope, scope->local_symbol(), pad);
|
2011-02-10 06:03:08 +01:00
|
|
|
con->set_line(info);
|
2000-02-16 04:58:27 +01:00
|
|
|
des->add_node(con);
|
2005-01-12 04:17:36 +01:00
|
|
|
connect(cc->pin(2), con->pin(0));
|
2000-02-16 04:58:27 +01:00
|
|
|
|
2005-01-12 04:17:36 +01:00
|
|
|
// Make a NetNet for the NetConst to NetConcat link.
|
2003-03-06 01:28:41 +01:00
|
|
|
NetNet*tmp = new NetNet(scope, scope->local_symbol(),
|
2005-01-12 04:17:36 +01:00
|
|
|
NetNet::WIRE, wid - net->vector_width());
|
2008-11-19 02:17:19 +01:00
|
|
|
tmp->set_line(info);
|
2011-02-10 06:03:08 +01:00
|
|
|
tmp->data_type( net->data_type() );
|
2000-02-16 04:58:27 +01:00
|
|
|
tmp->local_flag(true);
|
2005-01-12 04:17:36 +01:00
|
|
|
connect(cc->pin(2), tmp->pin(0));
|
2000-02-16 04:58:27 +01:00
|
|
|
|
2005-01-12 04:17:36 +01:00
|
|
|
// Create a NetNet of the output width and connect it to the
|
|
|
|
|
// NetConcat node output pin.
|
|
|
|
|
tmp = new NetNet(scope, scope->local_symbol(),
|
|
|
|
|
NetNet::WIRE, wid);
|
2008-11-19 02:17:19 +01:00
|
|
|
tmp->set_line(info);
|
2011-02-10 06:03:08 +01:00
|
|
|
tmp->data_type( net->data_type() );
|
2005-01-12 04:17:36 +01:00
|
|
|
tmp->local_flag(true);
|
|
|
|
|
connect(cc->pin(0), tmp->pin(0));
|
2000-02-16 04:58:27 +01:00
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
1999-09-29 02:42:50 +02:00
|
|
|
|
2008-11-19 02:17:19 +01:00
|
|
|
NetNet*pad_to_width_signed(Design*des, NetNet*net, unsigned wid,
|
|
|
|
|
const LineInfo&info)
|
2005-05-24 03:44:27 +02:00
|
|
|
{
|
|
|
|
|
NetScope*scope = net->scope();
|
|
|
|
|
|
|
|
|
|
if (net->vector_width() >= wid)
|
|
|
|
|
return net;
|
|
|
|
|
|
|
|
|
|
NetSignExtend*se
|
|
|
|
|
= new NetSignExtend(scope, scope->local_symbol(), wid);
|
2008-11-19 02:17:19 +01:00
|
|
|
se->set_line(info);
|
2005-05-24 03:44:27 +02:00
|
|
|
des->add_node(se);
|
|
|
|
|
|
|
|
|
|
NetNet*tmp = new NetNet(scope, scope->local_symbol(), NetNet::WIRE, wid);
|
2008-11-19 02:17:19 +01:00
|
|
|
tmp->set_line(info);
|
2005-05-24 03:44:27 +02:00
|
|
|
tmp->local_flag(true);
|
2005-07-07 18:22:49 +02:00
|
|
|
tmp->data_type(net->data_type());
|
2005-05-24 03:44:27 +02:00
|
|
|
tmp->set_signed(true);
|
|
|
|
|
|
|
|
|
|
connect(tmp->pin(0), se->pin(0));
|
|
|
|
|
connect(se->pin(1), net->pin(0));
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-25 01:44:01 +02:00
|
|
|
NetNet*crop_to_width(Design*des, NetNet*net, unsigned wid)
|
|
|
|
|
{
|
|
|
|
|
NetScope*scope = net->scope();
|
|
|
|
|
|
|
|
|
|
if (net->vector_width() <= wid)
|
|
|
|
|
return net;
|
|
|
|
|
|
|
|
|
|
NetPartSelect*ps = new NetPartSelect(net, 0, wid, NetPartSelect::VP);
|
|
|
|
|
ps->set_line(*net);
|
2011-02-10 06:03:08 +01:00
|
|
|
des->add_node(ps);
|
2005-04-25 01:44:01 +02:00
|
|
|
|
|
|
|
|
NetNet*tmp = new NetNet(scope, scope->local_symbol(),
|
|
|
|
|
NetNet::WIRE, wid);
|
2011-02-10 06:03:08 +01:00
|
|
|
tmp->set_line(*net);
|
2005-07-07 18:22:49 +02:00
|
|
|
tmp->data_type(net->data_type());
|
2005-04-25 01:44:01 +02:00
|
|
|
tmp->local_flag(true);
|
|
|
|
|
connect(ps->pin(0), tmp->pin(0));
|
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|