2001-04-24 04:23:58 +02:00
|
|
|
/*
|
2005-04-01 08:02:45 +02:00
|
|
|
* Copyright (c) 2005 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* (This is a rewrite of code that was ...
|
|
|
|
|
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>)
|
2001-04-24 04:23:58 +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
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2005-04-04 07:13:59 +02:00
|
|
|
#ident "$Id: udp.cc,v 1.29 2005/04/04 05:13:59 steve Exp $"
|
2001-04-24 04:23:58 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "udp.h"
|
2001-07-16 21:08:32 +02:00
|
|
|
#include "schedule.h"
|
2001-04-24 04:23:58 +02:00
|
|
|
#include "symbols.h"
|
2005-04-01 08:02:45 +02:00
|
|
|
#include "compile.h"
|
2001-04-24 04:23:58 +02:00
|
|
|
#include <assert.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#ifdef HAVE_MALLOC_H
|
2001-04-24 04:23:58 +02:00
|
|
|
#include <malloc.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#endif
|
|
|
|
|
#include <stdlib.h>
|
2005-04-01 08:02:45 +02:00
|
|
|
#include <string.h>
|
2001-07-24 03:44:50 +02:00
|
|
|
#include <stdio.h>
|
2001-04-26 17:52:22 +02:00
|
|
|
|
2001-07-24 03:44:50 +02:00
|
|
|
|
|
|
|
|
static symbol_table_t udp_table;
|
|
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
struct vvp_udp_s *udp_find(const char *label)
|
2001-04-24 04:23:58 +02:00
|
|
|
{
|
2005-04-01 08:02:45 +02:00
|
|
|
symbol_value_t v = sym_get_value(udp_table, label);
|
|
|
|
|
return (struct vvp_udp_s *)v.ptr;
|
|
|
|
|
}
|
2001-04-24 04:23:58 +02:00
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
vvp_udp_s::vvp_udp_s(char*label, char*name, unsigned ports, bool sequ)
|
|
|
|
|
{
|
|
|
|
|
assert(!sequ); // XXXX sequential UDPs not supported yet.
|
2001-04-24 04:23:58 +02:00
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
if (!udp_table)
|
|
|
|
|
udp_table = new_symbol_table();
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
assert(!udp_find(label));
|
2001-04-24 04:23:58 +02:00
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
symbol_value_t v;
|
|
|
|
|
v.ptr = this;
|
|
|
|
|
sym_set_value(udp_table, label, v);
|
2001-04-24 04:23:58 +02:00
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
name_ = name;
|
|
|
|
|
ports_ = ports;
|
|
|
|
|
levels0_ = 0;
|
|
|
|
|
levels1_ = 0;
|
|
|
|
|
nlevels0_ = 0;
|
|
|
|
|
nlevels1_ = 0;
|
2001-04-24 04:23:58 +02:00
|
|
|
}
|
|
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
vvp_udp_s::~vvp_udp_s()
|
2001-04-24 04:23:58 +02:00
|
|
|
{
|
2005-04-01 08:02:45 +02:00
|
|
|
if (levels0_) delete[] levels0_;
|
|
|
|
|
if (levels1_) delete[] levels1_;
|
2001-04-24 04:23:58 +02:00
|
|
|
}
|
|
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
unsigned vvp_udp_s::port_count() const
|
2001-07-24 03:44:50 +02:00
|
|
|
{
|
2005-04-01 08:02:45 +02:00
|
|
|
return ports_;
|
2001-07-24 03:44:50 +02:00
|
|
|
}
|
|
|
|
|
|
2005-04-04 07:13:59 +02:00
|
|
|
/*
|
|
|
|
|
* The cur table that is passed in must have for every valid bit
|
|
|
|
|
* position exactly one of the three mask bits set. This represents an
|
|
|
|
|
* actual vector of inputs to be tested.
|
|
|
|
|
*
|
|
|
|
|
* The levels0_ and levels1_ tables have levels_table objects that
|
|
|
|
|
* eack represent a single row. For the row to match the input vector,
|
|
|
|
|
* all the bits that are set in the cur table must also be set in the
|
|
|
|
|
* row being tested.
|
|
|
|
|
*
|
|
|
|
|
* It is possible for a row to match multiple different vectors. This
|
|
|
|
|
* is seen from the compile_table function, where bit positions for
|
|
|
|
|
* multiple masks can be test for certain row positions. For example,
|
|
|
|
|
* if the row bit position is '?', then mask 0/1/x are all set in the
|
|
|
|
|
* row for that bit position. This means it doesn't matter which of
|
|
|
|
|
* the three bit positions is set in the cur input table, the bit
|
|
|
|
|
* position will generate a match.
|
|
|
|
|
*/
|
2005-04-01 08:02:45 +02:00
|
|
|
vvp_bit4_t vvp_udp_s::test_levels(const udp_levels_table&cur)
|
2001-07-24 03:44:50 +02:00
|
|
|
{
|
2005-04-01 08:02:45 +02:00
|
|
|
for (unsigned idx = 0 ; idx < nlevels0_ ; idx += 1) {
|
2005-04-04 07:13:59 +02:00
|
|
|
if (cur.mask0 != (cur.mask0 & levels0_[idx].mask0))
|
2005-04-01 08:02:45 +02:00
|
|
|
continue;
|
2005-04-04 07:13:59 +02:00
|
|
|
if (cur.mask1 != (cur.mask1 & levels0_[idx].mask1))
|
2005-04-01 08:02:45 +02:00
|
|
|
continue;
|
2005-04-04 07:13:59 +02:00
|
|
|
if (cur.maskx != (cur.maskx & levels0_[idx].maskx))
|
2005-04-01 08:02:45 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return BIT4_0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < nlevels1_ ; idx += 1) {
|
2005-04-04 07:13:59 +02:00
|
|
|
if (cur.mask0 != (cur.mask0 & levels1_[idx].mask0))
|
2005-04-01 08:02:45 +02:00
|
|
|
continue;
|
2005-04-04 07:13:59 +02:00
|
|
|
if (cur.mask1 != (cur.mask1 & levels1_[idx].mask1))
|
2005-04-01 08:02:45 +02:00
|
|
|
continue;
|
2005-04-04 07:13:59 +02:00
|
|
|
if (cur.maskx != (cur.maskx & levels1_[idx].maskx))
|
2005-04-01 08:02:45 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return BIT4_1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BIT4_X;
|
2001-07-24 03:44:50 +02:00
|
|
|
}
|
|
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
void vvp_udp_s::compile_table(char**tab)
|
2001-07-24 03:44:50 +02:00
|
|
|
{
|
2005-04-01 08:02:45 +02:00
|
|
|
unsigned nrows0 = 0, nrows1 = 0;
|
|
|
|
|
|
|
|
|
|
/* First run through the table to figure out the number of
|
|
|
|
|
rows I need for each kind of table. */
|
|
|
|
|
for (unsigned idx = 0 ; tab[idx] ; idx += 1) {
|
|
|
|
|
assert(strlen(tab[idx]) == ports_ + 1);
|
|
|
|
|
switch (tab[idx][ports_]) {
|
|
|
|
|
case '0':
|
|
|
|
|
nrows0 += 1;
|
|
|
|
|
break;
|
|
|
|
|
case '1':
|
|
|
|
|
nrows1 += 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
2001-07-24 03:44:50 +02:00
|
|
|
}
|
2005-04-01 08:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nlevels0_ = nrows0;
|
|
|
|
|
levels0_ = new udp_levels_table[nlevels0_];
|
|
|
|
|
|
|
|
|
|
nlevels1_ = nrows1;
|
|
|
|
|
levels1_ = new udp_levels_table[nlevels1_];
|
|
|
|
|
|
|
|
|
|
nrows0 = 0;
|
|
|
|
|
nrows1 = 0;
|
|
|
|
|
for (unsigned idx = 0 ; tab[idx] ; idx += 1) {
|
|
|
|
|
struct udp_levels_table cur;
|
|
|
|
|
cur.mask0 = 0;
|
|
|
|
|
cur.mask1 = 0;
|
|
|
|
|
cur.maskx = 0;
|
|
|
|
|
assert(ports_ <= sizeof(cur.mask0));
|
|
|
|
|
for (unsigned pp = 0 ; pp < ports_ ; pp += 1) {
|
|
|
|
|
unsigned long mask_bit = 1UL << pp;
|
|
|
|
|
switch (tab[idx][pp]) {
|
|
|
|
|
case '0':
|
|
|
|
|
cur.mask0 |= mask_bit;
|
|
|
|
|
break;
|
|
|
|
|
case '1':
|
|
|
|
|
cur.mask1 |= mask_bit;
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
cur.maskx |= mask_bit;
|
|
|
|
|
break;
|
2005-04-04 07:13:59 +02:00
|
|
|
case 'b':
|
|
|
|
|
cur.mask0 |= mask_bit;
|
|
|
|
|
cur.mask1 |= mask_bit;
|
|
|
|
|
break;
|
|
|
|
|
case 'l':
|
|
|
|
|
cur.mask0 |= mask_bit;
|
|
|
|
|
cur.maskx |= mask_bit;
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
|
|
|
|
cur.maskx |= mask_bit;
|
|
|
|
|
cur.mask1 |= mask_bit;
|
|
|
|
|
break;
|
|
|
|
|
case '?':
|
|
|
|
|
cur.mask0 |= mask_bit;
|
|
|
|
|
cur.maskx |= mask_bit;
|
|
|
|
|
cur.mask1 |= mask_bit;
|
|
|
|
|
break;
|
2005-04-01 08:02:45 +02:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
2001-07-24 03:44:50 +02:00
|
|
|
}
|
2005-04-01 08:02:45 +02:00
|
|
|
|
|
|
|
|
switch (tab[idx][ports_]) {
|
|
|
|
|
case '0':
|
|
|
|
|
levels0_[nrows0++] = cur;
|
|
|
|
|
break;
|
|
|
|
|
case '1':
|
|
|
|
|
levels1_[nrows1++] = cur;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2001-07-24 03:44:50 +02:00
|
|
|
}
|
2005-04-01 08:02:45 +02:00
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
assert(nrows0 == nlevels0_);
|
|
|
|
|
assert(nrows1 == nlevels1_);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_udp_fun_core::vvp_udp_fun_core(vvp_net_t*net,
|
|
|
|
|
vvp_udp_s*def,
|
|
|
|
|
vvp_delay_t*del)
|
2005-04-01 08:02:45 +02:00
|
|
|
: vvp_wide_fun_core(net, def->port_count())
|
|
|
|
|
{
|
|
|
|
|
def_ = def;
|
2005-04-03 07:45:51 +02:00
|
|
|
delay_ = del;
|
|
|
|
|
cur_out_ = BIT4_X;
|
2005-04-01 08:02:45 +02:00
|
|
|
// Assume initially that all the inputs are 1'bx
|
|
|
|
|
current_.mask0 = 0;
|
|
|
|
|
current_.mask1 = 0;
|
|
|
|
|
current_.maskx = ~ ((-1UL) << port_count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_udp_fun_core::~vvp_udp_fun_core()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_udp_fun_core::recv_vec4_from_inputs(unsigned port)
|
|
|
|
|
{
|
|
|
|
|
/* For now, assume udps are 1-bit wide. */
|
|
|
|
|
assert(value(port).size() == 1);
|
|
|
|
|
|
|
|
|
|
unsigned long mask = 1UL << port;
|
|
|
|
|
|
|
|
|
|
switch (value(port).value(0)) {
|
|
|
|
|
|
|
|
|
|
case BIT4_0:
|
|
|
|
|
current_.mask0 |= mask;
|
|
|
|
|
current_.mask1 &= ~mask;
|
|
|
|
|
current_.maskx &= ~mask;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_1:
|
|
|
|
|
current_.mask0 &= ~mask;
|
|
|
|
|
current_.mask1 |= mask;
|
|
|
|
|
current_.maskx &= ~mask;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
current_.mask0 &= ~mask;
|
|
|
|
|
current_.mask1 &= ~mask;
|
|
|
|
|
current_.maskx |= mask;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_bit4_t out_bit = def_->test_levels(current_);
|
2005-04-01 08:02:45 +02:00
|
|
|
vvp_vector4_t out (1);
|
2005-04-03 07:45:51 +02:00
|
|
|
out.set_bit(0, out_bit);
|
2005-04-01 08:02:45 +02:00
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
if (delay_)
|
|
|
|
|
propagate_vec4(out, delay_->get_delay(cur_out_, out_bit));
|
|
|
|
|
else
|
|
|
|
|
propagate_vec4(out);
|
|
|
|
|
|
|
|
|
|
cur_out_ = out_bit;
|
2005-04-01 08:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function is called by the parser in response to a .udp
|
|
|
|
|
* node. We create the nodes needed to integrate the UDP into the
|
|
|
|
|
* netlist. The definition should be parsed already.
|
|
|
|
|
*/
|
|
|
|
|
void compile_udp_functor(char*label, char*type,
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_delay_t*delay,
|
2005-04-01 08:02:45 +02:00
|
|
|
unsigned argc, struct symb_s*argv)
|
|
|
|
|
{
|
|
|
|
|
struct vvp_udp_s *def = udp_find(type);
|
|
|
|
|
assert(def);
|
|
|
|
|
free(type);
|
|
|
|
|
|
|
|
|
|
vvp_net_t*ptr = new vvp_net_t;
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_udp_fun_core*core = new vvp_udp_fun_core(ptr, def, delay);
|
2005-04-01 08:02:45 +02:00
|
|
|
ptr->fun = core;
|
|
|
|
|
define_functor_symbol(label, ptr);
|
|
|
|
|
free(label);
|
|
|
|
|
|
|
|
|
|
wide_inputs_connect(core, argc, argv);
|
|
|
|
|
free(argv);
|
2001-04-24 04:23:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: udp.cc,v $
|
2005-04-04 07:13:59 +02:00
|
|
|
* Revision 1.29 2005/04/04 05:13:59 steve
|
|
|
|
|
* Support row level wildcards.
|
|
|
|
|
*
|
2005-04-03 07:45:51 +02:00
|
|
|
* Revision 1.28 2005/04/03 05:45:51 steve
|
|
|
|
|
* Rework the vvp_delay_t class.
|
|
|
|
|
*
|
2005-04-01 08:02:45 +02:00
|
|
|
* Revision 1.27 2005/04/01 06:02:45 steve
|
|
|
|
|
* Reimplement combinational UDPs.
|
2001-04-24 04:23:58 +02:00
|
|
|
*
|
|
|
|
|
*/
|