2004-12-11 03:31:25 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2004 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2006-05-01 20:44:08 +02:00
|
|
|
#ident "$Id: part.cc,v 1.11 2006/05/01 18:44:08 steve Exp $"
|
2004-12-11 03:31:25 +01:00
|
|
|
|
|
|
|
|
# include "compile.h"
|
2005-09-20 02:51:53 +02:00
|
|
|
# include "part.h"
|
2004-12-11 03:31:25 +01:00
|
|
|
# include <stdlib.h>
|
2005-05-09 02:36:58 +02:00
|
|
|
# include <limits.h>
|
2004-12-11 03:31:25 +01:00
|
|
|
#ifdef HAVE_MALLOC_H
|
|
|
|
|
# include <malloc.h>
|
|
|
|
|
#endif
|
2005-06-26 23:08:11 +02:00
|
|
|
# include <iostream>
|
2004-12-11 03:31:25 +01:00
|
|
|
# include <assert.h>
|
|
|
|
|
|
|
|
|
|
vvp_fun_part::vvp_fun_part(unsigned base, unsigned wid)
|
|
|
|
|
: base_(base), wid_(wid)
|
|
|
|
|
{
|
2005-09-20 02:51:53 +02:00
|
|
|
net_ = 0;
|
2004-12-11 03:31:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_part::~vvp_fun_part()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-22 02:04:48 +02:00
|
|
|
void vvp_fun_part::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit)
|
2004-12-11 03:31:25 +01:00
|
|
|
{
|
|
|
|
|
assert(port.port() == 0);
|
|
|
|
|
|
2005-09-20 02:51:53 +02:00
|
|
|
if (val_ .eeq( bit ))
|
|
|
|
|
return;
|
2004-12-11 03:31:25 +01:00
|
|
|
|
2005-09-20 02:51:53 +02:00
|
|
|
val_ = bit;
|
|
|
|
|
|
|
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = port.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_part::run_run()
|
|
|
|
|
{
|
|
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
2006-05-01 20:44:08 +02:00
|
|
|
vvp_vector4_t res (wid_, BIT4_X);
|
2004-12-11 03:31:25 +01:00
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2005-09-20 02:51:53 +02:00
|
|
|
if (idx + base_ < val_.size())
|
|
|
|
|
res.set_bit(idx, val_.value(base_+idx));
|
2004-12-11 03:31:25 +01:00
|
|
|
}
|
2005-09-20 02:51:53 +02:00
|
|
|
vvp_send_vec4(ptr->out, res);
|
2004-12-11 03:31:25 +01:00
|
|
|
}
|
|
|
|
|
|
2005-01-09 21:11:15 +01:00
|
|
|
vvp_fun_part_pv::vvp_fun_part_pv(unsigned b, unsigned w, unsigned v)
|
|
|
|
|
: base_(b), wid_(w), vwid_(v)
|
2004-12-11 03:31:25 +01:00
|
|
|
{
|
2005-01-09 21:11:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_part_pv::~vvp_fun_part_pv()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-22 02:04:48 +02:00
|
|
|
void vvp_fun_part_pv::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit)
|
2005-01-09 21:11:15 +01:00
|
|
|
{
|
|
|
|
|
assert(port.port() == 0);
|
2005-06-26 23:08:11 +02:00
|
|
|
|
|
|
|
|
if (bit.size() != wid_) {
|
|
|
|
|
cerr << "internal error: part_pv data mismatch. "
|
|
|
|
|
<< "base_=" << base_ << ", wid_=" << wid_
|
2006-04-26 06:39:23 +02:00
|
|
|
<< ", vwid_=" << vwid_ << ", bit=" << bit
|
2005-07-15 01:34:18 +02:00
|
|
|
<< endl;
|
2005-06-26 23:08:11 +02:00
|
|
|
}
|
2005-01-09 21:11:15 +01:00
|
|
|
assert(bit.size() == wid_);
|
2005-06-26 23:08:11 +02:00
|
|
|
|
2005-01-09 21:11:15 +01:00
|
|
|
vvp_send_vec4_pv(port.ptr()->out, bit, base_, wid_, vwid_);
|
|
|
|
|
}
|
2004-12-11 03:31:25 +01:00
|
|
|
|
2005-05-09 01:40:14 +02:00
|
|
|
vvp_fun_part_var::vvp_fun_part_var(unsigned w)
|
|
|
|
|
: base_(0), wid_(w)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_part_var::~vvp_fun_part_var()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-22 02:04:48 +02:00
|
|
|
void vvp_fun_part_var::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit)
|
2005-05-09 01:40:14 +02:00
|
|
|
{
|
|
|
|
|
unsigned long tmp;
|
|
|
|
|
switch (port.port()) {
|
|
|
|
|
case 0:
|
|
|
|
|
source_ = bit;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2005-05-09 02:36:58 +02:00
|
|
|
tmp = ULONG_MAX;
|
2005-05-09 01:40:14 +02:00
|
|
|
vector4_to_value(bit, tmp);
|
|
|
|
|
if (tmp == base_) return;
|
|
|
|
|
base_ = tmp;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t res (wid_);
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
|
|
|
|
unsigned adr = base_+idx;
|
|
|
|
|
if (adr >= source_.size())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
res.set_bit(idx, source_.value(adr));
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-09 02:36:58 +02:00
|
|
|
if (! ref_.eeq(res)) {
|
|
|
|
|
ref_ = res;
|
|
|
|
|
vvp_send_vec4(port.ptr()->out, res);
|
|
|
|
|
}
|
2005-05-09 01:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-01-09 21:11:15 +01:00
|
|
|
/*
|
|
|
|
|
* Given a node functor, create a network node and link it into the
|
|
|
|
|
* netlist. This form assumes nodes with a single input.
|
|
|
|
|
*/
|
|
|
|
|
void link_node_1(char*label, char*source, vvp_net_fun_t*fun)
|
|
|
|
|
{
|
2004-12-11 03:31:25 +01:00
|
|
|
vvp_net_t*net = new vvp_net_t;
|
|
|
|
|
net->fun = fun;
|
|
|
|
|
|
|
|
|
|
define_functor_symbol(label, net);
|
|
|
|
|
free(label);
|
|
|
|
|
|
|
|
|
|
input_connect(net, 0, source);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-09 21:11:15 +01:00
|
|
|
void compile_part_select(char*label, char*source,
|
|
|
|
|
unsigned base, unsigned wid)
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_part*fun = new vvp_fun_part(base, wid);
|
|
|
|
|
link_node_1(label, source, fun);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_part_select_pv(char*label, char*source,
|
|
|
|
|
unsigned base, unsigned wid,
|
|
|
|
|
unsigned vector_wid)
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_part_pv*fun = new vvp_fun_part_pv(base, wid, vector_wid);
|
|
|
|
|
link_node_1(label, source, fun);
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-09 01:40:14 +02:00
|
|
|
void compile_part_select_var(char*label, char*source, char*var,
|
|
|
|
|
unsigned wid)
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_part_var*fun = new vvp_fun_part_var(wid);
|
|
|
|
|
vvp_net_t*net = new vvp_net_t;
|
|
|
|
|
net->fun = fun;
|
|
|
|
|
|
|
|
|
|
define_functor_symbol(label, net);
|
|
|
|
|
free(label);
|
|
|
|
|
|
|
|
|
|
input_connect(net, 0, source);
|
|
|
|
|
input_connect(net, 1, var);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
/*
|
|
|
|
|
* $Log: part.cc,v $
|
2006-05-01 20:44:08 +02:00
|
|
|
* Revision 1.11 2006/05/01 18:44:08 steve
|
|
|
|
|
* Reduce steps to make logic output.
|
|
|
|
|
*
|
2006-04-26 06:39:23 +02:00
|
|
|
* Revision 1.10 2006/04/26 04:39:23 steve
|
|
|
|
|
* Include bit value in assertion message.
|
|
|
|
|
*
|
2005-09-20 02:51:53 +02:00
|
|
|
* Revision 1.9 2005/09/20 00:51:53 steve
|
|
|
|
|
* Lazy processing of vvp_fun_part functor.
|
|
|
|
|
*
|
2005-07-15 01:34:18 +02:00
|
|
|
* Revision 1.8 2005/07/14 23:34:19 steve
|
|
|
|
|
* gcc4 compile errors.
|
|
|
|
|
*
|
2005-06-26 23:08:11 +02:00
|
|
|
* Revision 1.7 2005/06/26 21:08:11 steve
|
|
|
|
|
* More verbose debugging of part select width errors.
|
|
|
|
|
*
|
2005-06-22 02:04:48 +02:00
|
|
|
* Revision 1.6 2005/06/22 00:04:49 steve
|
|
|
|
|
* Reduce vvp_vector4 copies by using const references.
|
|
|
|
|
*
|
2005-05-09 02:36:58 +02:00
|
|
|
* Revision 1.5 2005/05/09 00:36:58 steve
|
|
|
|
|
* Force part base out of bounds if index is invalid.
|
|
|
|
|
*
|
2005-05-09 01:40:14 +02:00
|
|
|
* Revision 1.4 2005/05/08 23:40:14 steve
|
|
|
|
|
* Add support for variable part select.
|
|
|
|
|
*
|
2005-01-09 21:11:15 +01:00
|
|
|
* Revision 1.3 2005/01/09 20:11:16 steve
|
|
|
|
|
* Add the .part/pv node and related functionality.
|
|
|
|
|
*
|
2004-12-30 00:44:39 +01:00
|
|
|
* Revision 1.2 2004/12/29 23:44:39 steve
|
|
|
|
|
* Fix missing output propagation of part node.
|
|
|
|
|
*
|
2004-12-11 03:31:25 +01:00
|
|
|
* Revision 1.1 2004/12/11 02:31:30 steve
|
|
|
|
|
* Rework of internals to carry vectors through nexus instead
|
|
|
|
|
* of single bits. Make the ivl, tgt-vvp and vvp initial changes
|
|
|
|
|
* down this path.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|