Reimplement combinational UDPs.

This commit is contained in:
steve
2005-04-01 06:02:45 +00:00
parent becda0e26c
commit b7ef2fcb0a
8 changed files with 484 additions and 592 deletions
+196 -408
View File
@@ -1,6 +1,8 @@
/*
* Copyright (c) 2000 Stephen Williams ([email protected])
* Copyright (c) 2001 Stephan Boettcher <[email protected]>
* Copyright (c) 2005 Stephen Williams ([email protected])
*
* (This is a rewrite of code that was ...
* Copyright (c) 2001 Stephan Boettcher <[email protected]>)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -18,445 +20,231 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: udp.cc,v 1.26 2004/10/04 01:10:59 steve Exp $"
#ident "$Id: udp.cc,v 1.27 2005/04/01 06:02:45 steve Exp $"
#endif
#include "udp.h"
#include "schedule.h"
#include "symbols.h"
#include "compile.h"
#include <assert.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*
* This method is called when the input of a slice of the UDP
* changes. All the slices of the UDP point to this common functor,
* that manages the output of the UDP device. The input functors are
* all edge_inputs_functors_s objects.
*/
void udp_functor_s::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
{
// Save the input in the ival member of this functor. It will
// be read by the propagate method. The old_ival method of the
// edge_input_functor (I am that) will be set by propagate.
put(i, val);
unsigned char out = udp->propagate(this, i);
// Send the result to the output. If this is a combinational
// UDP, then push according to the push flag. However, do
// *not* push sequential outputs.
// Sequential primitive outputs are scheduled as active
// events, no matter what common sense and reason say.
put_oval(out, push & !udp->sequ, false);
}
static symbol_table_t udp_table;
struct vvp_udp_s *udp_create(char *label)
struct vvp_udp_s *udp_find(const char *label)
{
if (!udp_table)
udp_table = new_symbol_table();
assert(!udp_find(label));
struct vvp_udp_s *u = new vvp_udp_s;
symbol_value_t v;
v.ptr = u;
sym_set_value(udp_table, label, v);
u->name = 0x0;
u->sequ = 0;
u->nin = 0;
u->init = 3;
u->table = 0x0;
return u;
symbol_value_t v = sym_get_value(udp_table, label);
return (struct vvp_udp_s *)v.ptr;
}
struct vvp_udp_s *udp_find(char *label)
vvp_udp_s::vvp_udp_s(char*label, char*name, unsigned ports, bool sequ)
{
symbol_value_t v = sym_get_value(udp_table, label);
return (struct vvp_udp_s *)v.ptr;
assert(!sequ); // XXXX sequential UDPs not supported yet.
if (!udp_table)
udp_table = new_symbol_table();
assert(!udp_find(label));
symbol_value_t v;
v.ptr = this;
sym_set_value(udp_table, label, v);
name_ = name;
ports_ = ports;
levels0_ = 0;
levels1_ = 0;
nlevels0_ = 0;
nlevels1_ = 0;
}
typedef unsigned int udp_vec_t;
struct udp_table_entry_s
vvp_udp_s::~vvp_udp_s()
{
udp_vec_t not_0; // all inputs that must not be 0
udp_vec_t not_1x; // all inputs that must not be 1, x
unsigned char edge_idx; // input index of the edge
unsigned char edge_type; // permissible transitions. 0: no edge.
unsigned char out; // new output, 0..2
};
if (levels0_) delete[] levels0_;
if (levels1_) delete[] levels1_;
}
enum edge_type_e
unsigned vvp_udp_s::port_count() const
{
EDGE_0 = 0x01,
EDGE_1 = 0x02,
EDGE_x = 0x0c,
EDGE_any = 0x0f,
};
return ports_;
}
vvp_bit4_t vvp_udp_s::test_levels(const udp_levels_table&cur)
{
for (unsigned idx = 0 ; idx < nlevels0_ ; idx += 1) {
if (cur.mask0 != levels0_[idx].mask0)
continue;
if (cur.mask1 != levels0_[idx].mask1)
continue;
if (cur.maskx != levels0_[idx].maskx)
continue;
return BIT4_0;
}
for (unsigned idx = 0 ; idx < nlevels1_ ; idx += 1) {
if (cur.mask0 != levels1_[idx].mask0)
continue;
if (cur.mask1 != levels1_[idx].mask1)
continue;
if (cur.maskx != levels1_[idx].maskx)
continue;
return BIT4_1;
}
return BIT4_X;
}
void vvp_udp_s::compile_table(char**tab)
{
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);
}
}
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;
default:
assert(0);
}
}
switch (tab[idx][ports_]) {
case '0':
levels0_[nrows0++] = cur;
break;
case '1':
levels1_[nrows1++] = cur;
break;
default:
break;
}
}
assert(nrows0 == nlevels0_);
assert(nrows1 == nlevels1_);
}
vvp_udp_fun_core::vvp_udp_fun_core(vvp_net_t*net, vvp_udp_s*def)
: vvp_wide_fun_core(net, def->port_count())
{
def_ = def;
// 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;
}
vvp_vector4_t out (1);
out.set_bit(0, def_->test_levels(current_));
propagate_vec4(out);
}
/*
* This method of the common table object for the UDP calculates the
* output based on the new input of the functor calling me.
* 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.
*/
unsigned char vvp_udp_s::propagate(functor_t fu, vvp_ipoint_t uix)
void compile_udp_functor(char*label, char*type,
vvp_delay_t delay,
unsigned argc, struct symb_s*argv)
{
vvp_ipoint_t base = ipoint_make(uix, 0);
struct vvp_udp_s *def = udp_find(type);
assert(def);
free(type);
unsigned char ret = 2;
unsigned edge_idx = 0; // input index that changed
unsigned edge_type = 0; // input transition
udp_vec_t invec = 0x0; // vector of 2-bit inputs
for (unsigned i=0; i < nin; i+=4)
{
int idx = ipoint_input_index(base, i);
edge_inputs_functor_s *pfun =
dynamic_cast<edge_inputs_functor_s *>(functor_index(idx));
assert(pfun);
invec |= pfun->ival << (2*i);
unsigned char diff = pfun->ival ^ pfun->old_ival;
if (diff)
{
unsigned ii = 0;
if (diff & 0x03) ii = 0;
if (diff & 0x0c) ii = 1;
if (diff & 0x30) ii = 2;
if (diff & 0xc0) ii = 3;
edge_idx = i+ii;
unsigned old_in = (pfun->old_ival >> (2*ii)) & 3;
edge_type = (1<<old_in);
}
pfun->old_ival = pfun->ival;
}
if (sequ)
{
if (edge_type == 0)
return fu->get_oval();
invec <<= 2;
invec |= (fu->get_oval() & 3);
}
udp_vec_t inx = invec & 0xaaaaaaaaU; // all 'x'/'z'
udp_vec_t in01 = ~(inx>>1); // masks all 'x'/'z'
udp_vec_t in1x = invec & in01; // all 'x' and '1'
udp_vec_t in0 = ~invec & in01; // all '0'
for (unsigned ri=0; ri < ntable; ri++)
{
udp_table_entry_t row = table+ri;
if ((in1x & row->not_1x) || (in0 & row->not_0))
continue;
if (!row->edge_type)
{
ret = row->out;
break;
}
if (row->edge_idx != edge_idx)
continue;
if (row->edge_type & edge_type)
{
ret = row->out;
break;
}
}
if (ret>2)
ret = fu->get_oval();
return ret;
}
void vvp_udp_s::compile_table(char **tab)
{
ntable = 0;
for (char **ss = tab; *ss; ss++)
ntable++;
table = new struct udp_table_entry_s[ntable];
for (unsigned i = 0; i < ntable; i++)
{
compile_row_(&table[i], tab[i]);
free(tab[i]);
}
free(tab);
}
void vvp_udp_s::compile_row_(udp_table_entry_t row, char *rchr)
{
row->not_0 = 0; // all inputs that must not be 0
row->not_1x = 0; // all inputs that must not be 1 or x
row->edge_idx = 0; // input index of the edge
row->edge_type = 0; // permissible transitions. 0: no edge.
char *s = rchr;
for (unsigned i = (sequ ? 0 : 1); i <= nin; i++)
{
char c = *s;
s++;
unsigned char n0 = 0;
unsigned char n1x = 0;
unsigned char edge = 0;
switch (c)
{
default:
fprintf(stderr, "vvp: Illegal character (%d) in UDP table\n", c);
assert(0);
break;
case '?':
break;
case '0':
n1x = 3; // 1, x not allowed
break;
case '1':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
break;
case 'x':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
break;
case 'b':
n1x = 2; // x not allowed
break;
case 'l':
n1x = 1; // 1 not allowed
break;
case 'h':
n0 = 1; // 0 not allowed
break;
case '*':
edge = EDGE_any;
break;
case '+':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
edge = EDGE_any;
break;
case '_':
n1x = 3; // 1, x not allowed
edge = EDGE_any;
break;
case '%':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_any;
break;
case 'N':
edge = EDGE_1;
break;
case 'P':
edge = EDGE_0;
break;
case 'B':
edge = EDGE_x;
break;
case 'r':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
edge = EDGE_0;
break;
case 'R':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
edge = EDGE_x;
break;
case 'f':
n1x = 3; // 1, x not allowed
edge = EDGE_1;
break;
case 'F':
n1x = 3; // 1, x not allowed
edge = EDGE_x;
break;
case 'Q':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_0;
break;
case 'q':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_0 | EDGE_1;
break;
case 'M':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_1;
break;
case 'n':
n1x = 1; // 1 not allowed
edge = EDGE_1 | EDGE_x;
break;
case 'p':
n0 = 1; // 0 not allowed
edge = EDGE_0 | EDGE_x;
break;
case 'v':
n1x = 2; // x not allowed
edge = EDGE_0 | EDGE_1;
break;
}
if (edge)
{
if (!sequ)
{
fprintf(stderr, "vvp: edge in combinatorial UDP\n");
assert(0);
}
if (!i)
{
fprintf(stderr, "vvp: edge in UDP output state\n");
assert(0);
}
row->edge_idx = i-1;
if (row->edge_type)
{
fprintf(stderr, "vvp: multiple edges in UDP table row\n");
assert(0);
}
row->edge_type = edge;
}
int j = sequ ? i : i-1;
row->not_0 |= n0 << (2*j);
row->not_1x |= n1x << (2*j);
}
switch (*s)
{
case '0':
row->out = 0;
break;
case '1':
row->out = 1;
break;
case 'x':
row->out = 2;
break;
case '-':
row->out = 4;
break;
default:
fprintf(stderr, "vvp: illegal character (%d) in udp output spec\n", *s);
assert(0);
}
vvp_net_t*ptr = new vvp_net_t;
vvp_udp_fun_core*core = new vvp_udp_fun_core(ptr, def);
ptr->fun = core;
define_functor_symbol(label, ptr);
free(label);
wide_inputs_connect(core, argc, argv);
free(argv);
}
/*
* $Log: udp.cc,v $
* Revision 1.26 2004/10/04 01:10:59 steve
* Clean up spurious trailing white space.
*
* Revision 1.25 2003/09/24 20:46:48 steve
* Standard udp scheduling behavior.
*
* Revision 1.24 2003/09/17 03:39:55 steve
* Internal documentation of UDP devices.
*
* Revision 1.23 2003/09/13 00:59:02 steve
* Comments.
*
* Revision 1.22 2003/09/09 00:56:45 steve
* Reimpelement scheduler to divide nonblocking assign queue out.
*
* Revision 1.21 2003/06/17 21:28:59 steve
* Remove short int restrictions from vvp opcodes. (part 2)
*
* Revision 1.20 2003/04/01 05:32:56 steve
* Propagate output of sequential udp like non-blocksing assign.
*
* Revision 1.19 2003/03/18 01:32:33 steve
* Add the q edge flag.
*
* Revision 1.18 2003/02/09 23:33:26 steve
* Spelling fixes.
*
* Revision 1.17 2002/08/12 01:35:08 steve
* conditional ident string using autoconfig.
*
* Revision 1.16 2002/01/20 23:27:51 steve
* return calculated oval from UDP (Stephan Boettcher)
*
* Revision 1.15 2002/01/06 17:35:01 steve
* Feedback output, not propagated output. (Stephan Boettcher)
*
* Revision 1.14 2001/12/06 03:31:25 steve
* Support functor delays for gates and UDP devices.
* (Stephan Boettcher)
*
* Revision 1.13 2001/11/07 03:34:42 steve
* Use functor pointers where vvp_ipoint_t is unneeded.
*
* Revision 1.12 2001/10/31 04:27:47 steve
* Rewrite the functor type to have fewer functor modes,
* and use objects to manage the different types.
* (Stephan Boettcher)
*
* Revision 1.11 2001/09/19 04:10:40 steve
* Change UDP output only if table matches.
*
* Revision 1.10 2001/09/15 18:27:05 steve
* Make configure detect malloc.h
*
* Revision 1.9 2001/08/09 19:38:23 steve
* Nets (wires) do not use their own functors.
* Modifications to propagation of values.
* (Stephan Boettcher)
*
* Revision 1.8 2001/07/24 01:44:50 steve
* Fast UDP tables (Stephan Boettcher)
*
* Revision 1.7 2001/07/16 19:08:32 steve
* Schedule instead of propagating UDP output. (Stephan Boettcher)
*
* Revision 1.6 2001/06/18 00:51:23 steve
* Add more UDP edge types, and finish up compile
* and run-time support. (Stephan Boettcher)
*
* Revision 1.5 2001/05/31 04:12:43 steve
* Make the bufif0 and bufif1 gates strength aware,
* and accurately propagate strengths of outputs.
*
* Revision 1.4 2001/05/06 03:51:37 steve
* Regularize the mode-42 functor handling.
*
* Revision 1.3 2001/04/26 15:52:22 steve
* Add the mode-42 functor concept to UDPs.
*
* Revision 1.2 2001/04/26 03:10:55 steve
* Redo and simplify UDP behavior.
*
* Revision 1.1 2001/04/24 02:23:59 steve
* Support for UDP devices in VVP (Stephen Boettcher)
* Revision 1.27 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
*/